10000 Remove our own custom FQCN visitor as we already use php-parser's `NameResolver` visitor by maks-rafalko · Pull Request #1967 · infection/infection · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Remove our own custom FQCN visitor as we already use php-parser's NameResolver visitor #1967

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

Merged
merged 1 commit into from
May 18, 2024
Merged
Show file tree
Hide file tree
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
2 changes: 0 additions & 2 deletions src/PhpParser/NodeTraverserFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@

namespace Infection\PhpParser;

use Infection\PhpParser\Visitor\FullyQualifiedClassNameVisitor;
use Infection\PhpParser\Visitor\IgnoreAllMutationsAnnotationReaderVisitor;
use Infection\PhpParser\Visitor\IgnoreNode\AbstractMethodIgnorer;
use Infection\PhpParser\Visitor\IgnoreNode\ChangingIgnorer;
Expand Down Expand Up @@ -79,7 +78,6 @@ public function create(NodeVisitor $mutationVisitor, array $nodeIgnorers): NodeT
]),
);
$traverser->addVisitor(new ParentConnectorVisitor());
$traverser->addVisitor(new FullyQualifiedClassNameVisitor());
$traverser->addVisitor(new ReflectionVisitor());
$traverser->addVisitor($mutationVisitor);

Expand Down
22 changes: 4 additions & 18 deletions src/PhpParser/Visitor/FullyQualifiedClassNameManipulator.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@

use Infection\CannotBeInstantiated;
use PhpParser\Node;
use PhpParser\Node\Name\FullyQualified;
use Webmozart\Assert\Assert;

/**
* @internal
Expand All @@ -47,22 +45,10 @@
{
use CannotBeInstantiated;

private const FQN_ATTRIBUTE = 'fullyQualifiedClassName';

public static function setFqcn(Node $node, ?FullyQualified $fqcn): void
{
$node->setAttribute(self::FQN_ATTRIBUTE, $fqcn);
}

public static function hasFqcn(Node $node): bool
public static function getFqcn(Node $node): ?Node\Name
{
return $node->hasAttribute(self::FQN_ATTRIBUTE);
}

public static function getFqcn(Node $node): ?FullyQualified
{
Assert::true(self::hasFqcn($node));

return $node->getAttribute(self::FQN_ATTRIBUTE);
return $node->namespacedName

Check warning on line 50 in src/PhpParser/Visitor/FullyQualifiedClassNameManipulator.php

View workflow job for this annotation

GitHub Actions / Mutation Testing Code Review Annotations 8.1

Escaped Mutant for Mutator "Coalesce": --- Original +++ New @@ @@ use CannotBeInstantiated; public static function getFqcn(Node $node): ?Node\Name { - return $node->namespacedName ?? $node->getAttribute('resolvedName') ?? $node->getAttribute('namespacedName'); + return $node->getAttribute('resolvedName') ?? $node->namespacedName ?? $node->getAttribute('namespacedName'); } }
?? $node->getAttribute('resolvedName')

Check warning on line 51 in src/PhpParser/Visitor/FullyQualifiedClassNameManipulator.php

View workflow job for this annotation

GitHub Actions / Mutation Testing Code Review Annotations 8.1

Escaped Mutant for Mutator "Coalesce": --- Original +++ New @@ @@ use CannotBeInstantiated; public static function getFqcn(Node $node): ?Node\Name { - return $node->namespacedName ?? $node->getAttribute('resolvedName') ?? $node->getAttribute('namespacedName'); + return $node->namespacedName ?? $node->getAttribute('namespacedName') ?? $node->getAttribute('resolvedName'); } }
?? $node->getAttribute('namespacedName');
}
}
72 changes: 0 additions & 72 deletions src/PhpParser/Visitor/FullyQualifiedClassNameVisitor.php

This file was deleted.

This file was deleted.

3 changes: 0 additions & 3 deletions tests/phpunit/PhpParser/NodeTraverserFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@

use function array_map;
use Infection\PhpParser\NodeTraverserFactory;
use Infection\PhpParser\Visitor\FullyQualifiedClassNameVisitor;
use Infection\PhpParser\Visitor\IgnoreAllMutationsAnnotationReaderVisitor;
use Infection\PhpParser\Visitor\IgnoreNode\AbstractMethodIgnorer;
use Infection\PhpParser\Visitor\IgnoreNode\ChangingIgnorer;
Expand Down Expand Up @@ -77,7 +76,6 @@ public function test_it_can_create_a_traverser(): void
NonMutableNodesIgnorerVisitor::class,
NameResolver::class,
ParentConnectorVisitor::class,
FullyQualifiedClassNameVisitor::class,
ReflectionVisitor::class,
FakeVisitor::class,
],
Expand Down Expand Up @@ -105,7 +103,6 @@ public function test_it_can_create_a_traverser_with_node_ignorers(): void
NonMutableNodesIgnorerVisitor::class,
NameResolver::class,
ParentConnectorVisitor::class,
FullyQualifiedClassNameVisitor::class,
ReflectionVisitor::class,
FakeVisitor::class,
],
Expand Down
57AE
Original file line number Diff line number Diff line change
Expand Up @@ -36,92 +36,26 @@
namespace Infection\Tests\PhpParser\Visitor;

use Infection\PhpParser\Visitor\FullyQualifiedClassNameManipulator;
use InvalidArgumentException;
use PhpParser\Node;
use PhpParser\Node\Name\FullyQualified;
use PhpParser\Node\Stmt\Nop;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;

#[CoversClass(FullyQualifiedClassNameManipulator::class)]
final class FullyQualifiedClassNameManipulatorTest extends TestCase
{
#[DataProvider('hasFqcnProvider')]
public function test_it_can_determine_if_the_given_node_has_a_fqcn_attribute(
Node $node,
bool $expected,
): void {
$this->assertSame($expected, FullyQualifiedClassNameManipulator::hasFqcn($node));
}

public function test_it_can_provide_the_node_fqcn(): void
{
$fqcn = new FullyQualified('Acme\Foo');
$node = new Nop(['fullyQualifiedClassName' => $fqcn]);
$node = new Nop(['resolvedName' => $fqcn]);

$this->assertSame($fqcn, FullyQualifiedClassNameManipulator::getFqcn($node));
}

public function test_it_can_provide_the_node_fqcn_for_an_anonymous_class(): void
{
$node = new Nop(['fullyQualifiedClassName' => null]);
$node = new Nop(['resolvedName' => null]);

$this->assertNull(FullyQualifiedClassNameManipulator::getFqcn($node));
}

public function test_it_cannot_provide_the_node_fqcn_if_has_not_be_set_yet(): void
{
$node = new Nop();

$this->expectException(InvalidArgumentException::class);

// We are not interested in a more helpful message here since it would be the result of
// a misconfiguration on our part rather than a user one. Plus this would require some
// extra processing on a part which is quite a hot path.

FullyQualifiedClassNameManipulator::getFqcn($node);
}

public function test_it_can_set_a_node_fqcn(): void
{
$fqcn = new FullyQualified('Acme\Foo');
$node = new Nop();

FullyQualifiedClassNameManipulator::setFqcn($node, $fqcn);

$this->assertSame($fqcn, FullyQualifiedClassNameManipulator::getFqcn($node));
}

public function test_it_can_set_a_node_fqcn_for_an_anonymous_class(): void
{
$node = new Nop();

FullyQualifiedClassNameManipulator::setFqcn($node, null);

$this->assertNull(FullyQualifiedClassNameManipulator::getFqcn($node));
}

public static function hasFqcnProvider(): iterable
{
yield 'no FQCN' => [
new Nop(),
false,
];

yield 'empty string FQCN' => [
new Nop(['fullyQualifiedClassName' => '']),
true,
];

yield 'null FQCN' => [
new Nop(['fullyQualifiedClassName' => null]),
true,
];

yield 'has FQCN' => [
new Nop(['fullyQualifiedClassName' => 'Acme\Foo']),
true,
];
}
}
Loading
Loading
0