-
-
Notifications
You must be signed in to change notification settings - Fork 335
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
handle cases where strlen arg is a Stringable object (#981)
* handle cases where strlen arg is a Stringable object * handle in processLeftIdentical as well * fix to use getNativeType * add test fixtures * stick on strict comparison by using string cast * fix return type * refactor processIdentical * refactor processEqual * fix * separate expr to variable
- Loading branch information
Showing
5 changed files
with
134 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
...ctor/Identical/StrlenZeroToIdenticalEmptyStringRector/Fixture/might_not_be_string.php.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\CodeQuality\Rector\Identical\StrlenZeroToIdenticalEmptyStringRector\Fixture; | ||
|
||
class MightNotBeString | ||
{ | ||
public function run($value) | ||
{ | ||
$empty = strlen($value) === 0; | ||
|
||
$empty = 0 === strlen($value); | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\CodeQuality\Rector\Identical\StrlenZeroToIdenticalEmptyStringRector\Fixture; | ||
|
||
class MightNotBeString | ||
{ | ||
public function run($value) | ||
{ | ||
$empty = (string) $value === ''; | ||
|
||
$empty = (string) $value === ''; | ||
} | ||
} | ||
|
||
?> |
35 changes: 35 additions & 0 deletions
35
.../Rector/Identical/StrlenZeroToIdenticalEmptyStringRector/Fixture/non_string_value.php.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\CodeQuality\Rector\Identical\StrlenZeroToIdenticalEmptyStringRector\Fixture; | ||
|
||
class NonStringValue | ||
{ | ||
public function run() | ||
{ | ||
$value = null; | ||
|
||
$empty = strlen($value) === 0; | ||
|
||
$empty = 0 === strlen($value); | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\CodeQuality\Rector\Identical\StrlenZeroToIdenticalEmptyStringRector\Fixture; | ||
|
||
class NonStringValue | ||
{ | ||
public function run() | ||
{ | ||
$value = null; | ||
|
||
$empty = (string) $value === ''; | ||
|
||
$empty = (string) $value === ''; | ||
} | ||
} | ||
|
||
?> |
51 changes: 51 additions & 0 deletions
51
...Rector/Identical/StrlenZeroToIdenticalEmptyStringRector/Fixture/stringable_object.php.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\CodeQuality\Rector\Identical\StrlenZeroToIdenticalEmptyStringRector\Fixture; | ||
|
||
class Stringable { | ||
private string $string = ''; | ||
|
||
public function __toString() : string { | ||
return $this->string; | ||
} | ||
} | ||
|
||
class StringableObject | ||
{ | ||
public function run() | ||
{ | ||
$value = new Stringable(); | ||
|
||
$empty = strlen($value) === 0; | ||
|
||
$empty = 0 === strlen($value); | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\CodeQuality\Rector\Identical\StrlenZeroToIdenticalEmptyStringRector\Fixture; | ||
|
||
class Stringable { | ||
private string $string = ''; | ||
|
||
public function __toString() : string { | ||
return $this->string; | ||
} | ||
} | ||
|
||
class StringableObject | ||
{ | ||
public function run() | ||
{ | ||
$value = new Stringable(); | ||
|
||
$empty = (string) $value === ''; | ||
|
||
$empty = (string) $value === ''; | ||
} | ||
} | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters