-
-
Notifications
You must be signed in to change notification settings - Fork 362
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DeadCode] Handle crash on valid conditional type on RemoveUselessRet…
…urnTagRector (#6475) * [DeadCode] Handle crash on valid conditional type on RemoveUselessReturnTagRector * avoid using isArray()->yes() usage * fix * clean up isArray() check
- Loading branch information
1 parent
d49ace3
commit 2f77705
Showing
4 changed files
with
44 additions
and
11 deletions.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
...or/ClassMethod/RemoveUselessReturnTagRector/Fixture/skip_valid_conditional_return.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,37 @@ | ||
<?php | ||
|
||
declare(strict_types = 1); | ||
|
||
namespace Rector\Tests\DeadCode\Rector\ClassMethod\RemoveUselessReturnTagRector\Fixture; | ||
|
||
final readonly class SkipValidConditionalReturn | ||
{ | ||
/** | ||
* Groups an array by a key returned by a callback. | ||
* | ||
* Example: | ||
* | ||
* return SkipValidConditionalReturn::groupBy( | ||
* $results, | ||
* fn ($ticket) => (string) $ticket->getFile()->getId(), | ||
* ); | ||
* | ||
* @template TValue of mixed | ||
* @template TCallbackValue of mixed | ||
* @template TKey of array-key | ||
* @param array<TValue> $input | ||
* @param callable(TValue): TKey $keyCallback | ||
* @param null|callable(TValue): TCallbackValue $valueCallback | ||
* | ||
* @return ($valueCallback is null ? array<TKey, non-empty-list<TValue>> : array<TKey, non-empty-list<TCallbackValue>>) | ||
*/ | ||
public static function groupBy(array $input, callable $keyCallback, ?callable $valueCallback = null) : array | ||
{ | ||
$output = []; | ||
foreach ($input as $result) { | ||
$output[$keyCallback($result)][] = $valueCallback !== null ? $valueCallback($result) : $result; | ||
} | ||
|
||
return $output; | ||
} | ||
} |
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
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
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