-
-
Notifications
You must be signed in to change notification settings - Fork 336
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[NodeTypeResolver] pull getType() on ArrayDimFetch when not mixed typ…
…e from its variable native definition (#5056) * [NodeTypeResolver] pull getType() on ArrayDimFetch when not mixed type from its variable native definition * also skip mixed * clean up * more fixture * on array object
- Loading branch information
1 parent
884a47e
commit ad96b1f
Showing
5 changed files
with
120 additions
and
16 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
55 changes: 55 additions & 0 deletions
55
tests/Issues/EmptyBooleanCompare/Fixture/always_exists_array_dim_fetch_item.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,55 @@ | ||
<?php | ||
|
||
namespace Rector\Core\Tests\Issues\EmptyBooleanCompare\Fixture; | ||
|
||
final class AlwaysExistsArrayDimFetchItem | ||
{ | ||
public function checkUrl(string $url) | ||
{ | ||
if (rand(0, 1)) { | ||
$parts = [ | ||
'host' => 'foo', | ||
]; | ||
} else { | ||
$parts = [ | ||
'host' => '', | ||
]; | ||
} | ||
|
||
if (!empty($parts['host'])) { | ||
return $parts['host']; | ||
} | ||
|
||
return null; | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Core\Tests\Issues\EmptyBooleanCompare\Fixture; | ||
|
||
final class AlwaysExistsArrayDimFetchItem | ||
{ | ||
public function checkUrl(string $url) | ||
{ | ||
if (rand(0, 1) !== 0) { | ||
$parts = [ | ||
'host' => 'foo', | ||
]; | ||
} else { | ||
$parts = [ | ||
'host' => '', | ||
]; | ||
} | ||
|
||
if (isset($parts['host']) && $parts['host'] !== '') { | ||
return $parts['host']; | ||
} | ||
|
||
return null; | ||
} | ||
} | ||
|
||
?> |
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
18 changes: 18 additions & 0 deletions
18
tests/Issues/EmptyBooleanCompare/Fixture/skip_array_dim_fetch_from_docblock.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,18 @@ | ||
<?php | ||
|
||
namespace Rector\Core\Tests\Issues\EmptyBooleanCompare\Fixture; | ||
|
||
final class SkipArrayDimFetchFromDocblock | ||
{ | ||
/** | ||
* @param array{host: string} $parts | ||
*/ | ||
public function checkUrl(array $parts) | ||
{ | ||
if (!empty($parts['host'])) { | ||
return $parts['host']; | ||
} | ||
|
||
return null; | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
tests/Issues/EmptyBooleanCompare/Fixture/skip_mixed_array_dim_fetch.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,15 @@ | ||
<?php | ||
|
||
namespace Rector\Core\Tests\Issues\EmptyBooleanCompare\Fixture; | ||
|
||
final class SkipMixedArrayDimFetch | ||
{ | ||
public function checkUrl(array $parts) | ||
{ | ||
if (!empty($parts['host'])) { | ||
return $parts['host']; | ||
} | ||
|
||
return null; | ||
} | ||
} |