Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancement: Allow configuring Arrays\SortAssociativeArrayByKeyRector #174

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/Arrays/SortAssociativeArrayByKeyRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@

use PhpParser\Node;
use PHPStan\Reflection\ClassReflection;
use Rector\Contract;
use Rector\Rector;
use Rector\Reflection;
use Symplify\RuleDocGenerator;

final class SortAssociativeArrayByKeyRector extends Rector\AbstractRector
final class SortAssociativeArrayByKeyRector extends Rector\AbstractRector implements Contract\Rector\ConfigurableRectorInterface
{
private Reflection\ReflectionResolver $reflectionResolver;

Expand Down Expand Up @@ -75,7 +76,7 @@

public function refactor(Node $node): ?Node
{
if (!$node instanceof Node\Expr\Array_) {

Check warning on line 79 in src/Arrays/SortAssociativeArrayByKeyRector.php

View workflow job for this annotation

GitHub Actions / Mutation Tests (7.4, locked)

Escaped Mutant for Mutator "InstanceOf_": --- Original +++ New @@ @@ } public function refactor(Node $node) : ?Node { - if (!$node instanceof Node\Expr\Array_) { + if (!true) { return null; } if ($this->isScopeInTest($node)) {
return null;
}

Expand All @@ -85,7 +86,7 @@

/** @var array<int, Node\Expr\ArrayItem> $items */
$items = \array_filter($node->items, static function ($item): bool {
if (!$item instanceof Node\Expr\ArrayItem) {

Check warning on line 89 in src/Arrays/SortAssociativeArrayByKeyRector.php

View workflow job for this annotation

GitHub Actions / Mutation Tests (7.4, locked)

Escaped Mutant for Mutator "InstanceOf_": --- Original +++ New @@ @@ } /** @var array<int, Node\Expr\ArrayItem> $items */ $items = \array_filter($node->items, static function ($item) : bool { - if (!$item instanceof Node\Expr\ArrayItem) { + if (!true) { return false; } if (!$item->key instanceof Node\Scalar\String_) {
return false;
}

Expand All @@ -101,11 +102,11 @@
}

\usort($items, static function (Node\Expr\ArrayItem $a, Node\Expr\ArrayItem $b): int {
if (!$a->key instanceof Node\Scalar\String_) {

Check warning on line 105 in src/Arrays/SortAssociativeArrayByKeyRector.php

View workflow job for this annotation

GitHub Actions / Mutation Tests (7.4, locked)

Escaped Mutant for Mutator "InstanceOf_": --- Original +++ New @@ @@ return null; } \usort($items, static function (Node\Expr\ArrayItem $a, Node\Expr\ArrayItem $b) : int { - if (!$a->key instanceof Node\Scalar\String_) { + if (!true) { throw new \RuntimeException('This should not happen.'); } if (!$b->key instanceof Node\Scalar\String_) {
throw new \RuntimeException('This should not happen.');
}

if (!$b->key instanceof Node\Scalar\String_) {

Check warning on line 109 in src/Arrays/SortAssociativeArrayByKeyRector.php

View workflow job for this annotation

GitHub Actions / Mutation Tests (7.4, locked)

Escaped Mutant for Mutator "InstanceOf_": --- Original +++ New @@ @@ if (!$a->key instanceof Node\Scalar\String_) { throw new \RuntimeException('This should not happen.'); } - if (!$b->key instanceof Node\Scalar\String_) { + if (!true) { throw new \RuntimeException('This should not happen.'); } return \strcmp($a->key->value, $b->key->value);
throw new \RuntimeException('This should not happen.');
}

Expand Down Expand Up @@ -134,4 +135,9 @@

return true;
}

public function configure(array $configuration): void
{
// TODO: Implement configure() method.
}
}
Loading