-
-
Notifications
You must be signed in to change notification settings - Fork 345
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
[PHPStan 1.0] Remove node naming visitors and re-use PHPStan ones #1144
Changes from all commits
059f54e
f40a02b
a8044ed
939846c
695764e
830e7f2
063002e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,9 @@ | |
|
||
use Symplify\SmartFileSystem\SmartFileInfo; | ||
|
||
/** | ||
* @enum | ||
*/ | ||
final class AttributeKey | ||
{ | ||
/** | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,18 +11,3 @@ class SkipSameNamespacedUsedClass | |
{ | ||
} | ||
} | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\CodingStyle\Rector\Namespace_\ImportFullyQualifiedNamesRector\Fixture; | ||
|
||
use Rector\Tests\CodingStyle\Rector\Namespace_\ImportFullyQualifiedNamesRector\Source\SharedShortName; | ||
class SkipSameNamespacedUsedClass | ||
{ | ||
/** | ||
* @return SharedShortName | ||
*/ | ||
public function run(): SharedShortName | ||
{ | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this expected output seems previously correct, as the docblock |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -64,7 +64,7 @@ use PhpSpec\ObjectBehavior; | |
class RatesTest extends \PHPUnit\Framework\TestCase | ||
{ | ||
private \Rector\Tests\PhpSpecToPHPUnit\Rector\Variable\PhpSpecToPHPUnitRector\Fixture\Rates $rates; | ||
private \PHPUnit\Framework\MockObject\MockObject|\spec\Rector\Tests\PhpSpecToPHPUnit\Rector\Variable\PhpSpecToPHPUnitRector\Fixture\Provider $provider; | ||
private \PHPUnit\Framework\MockObject\MockObject|\Provider $provider; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this should be |
||
protected function setUp() | ||
{ | ||
$this->provider = $this->createMock(Provider::class); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -70,7 +70,7 @@ class CreateMeTest extends \PHPUnit\Framework\TestCase | |
|
||
public function testCalled() | ||
{ | ||
/** @var spec\Rector\Tests\PhpSpecToPHPUnit\Rector\Variable\PhpSpecToPHPUnitRector\Fixture\Cart|\PHPUnit\Framework\MockObject\MockObject $cart */ | ||
/** @var Cart|\PHPUnit\Framework\MockObject\MockObject $cart */ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is incorrect, same with property to use namespaced name, the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. or possibly not, it depends on if actually the class used moved or not after namespace changed, as next it is ok then for now. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the outside class type actualy need to be moved under |
||
$cart = $this->createMock(Cart::class); | ||
$cart->expects($this->atLeastOnce())->method('price')->willReturn(5); | ||
$cart->expects($this->atLeastOnce())->method('shippingAddress')->with($this->isInstanceOf(Address::class)); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -67,7 +67,7 @@ use Symfony\Component\Routing\Generator\UrlGeneratorInterface; | |
class PageLinksGeneratorTest extends \PHPUnit\Framework\TestCase | ||
{ | ||
private \Rector\Tests\PhpSpecToPHPUnit\Rector\Variable\PhpSpecToPHPUnitRector\Fixture\PageLinksGenerator $pageLinksGenerator; | ||
private \PHPUnit\Framework\MockObject\MockObject|\Symfony\Bundle\FrameworkBundle\Routing\Router $router; | ||
private \PHPUnit\Framework\MockObject\MockObject|\Router $router; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is also incorrect for |
||
public function testInitializable() | ||
{ | ||
$this->assertInstanceOf(PageLinksGenerator::class, $this->pageLinksGenerator); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,7 +31,7 @@ use Rector\Tests\PhpSpecToPHPUnit\Rector\Variable\PhpSpecToPHPUnitRector\Source\ | |
class MockPropertiesTest extends \PHPUnit\Framework\TestCase | ||
{ | ||
private \Rector\Tests\PhpSpecToPHPUnit\Rector\Variable\PhpSpecToPHPUnitRector\Fixture\MockProperties $mockProperties; | ||
private \PHPUnit\Framework\MockObject\MockObject|\Rector\Tests\PhpSpecToPHPUnit\Rector\Variable\PhpSpecToPHPUnitRector\Source\OrderFactory $factory; | ||
private \OrderFactory|\PHPUnit\Framework\MockObject\MockObject $factory; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is incorrect as |
||
protected function setUp() | ||
{ | ||
$this->factory = $this->createMock(OrderFactory::class); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,10 +6,7 @@ | |
|
||
use PhpParser\Node; | ||
use PhpParser\Node\Expr; | ||
use PhpParser\Node\Name; | ||
use PHPStan\Analyser\Scope; | ||
use Rector\Core\PhpParser\Node\BetterNodeFinder; | ||
use Rector\NodeTypeResolver\Node\AttributeKey; | ||
|
||
final class ExprUsedInNextNodeAnalyzer | ||
{ | ||
|
@@ -19,26 +16,11 @@ public function __construct( | |
) { | ||
} | ||
|
||
/** | ||
* $isCheckNameScope parameter is used to whether to check scope of Name that may be renamed | ||
* @see https://github.com/rectorphp/rector/issues/6675 | ||
*/ | ||
public function isUsed(Expr $expr, bool $isCheckNameScope = false): bool | ||
public function isUsed(Expr $expr): bool | ||
{ | ||
return (bool) $this->betterNodeFinder->findFirstNext( | ||
$expr, | ||
function (Node $node) use ($expr, $isCheckNameScope): bool { | ||
if ($isCheckNameScope && $node instanceof Name) { | ||
$scope = $node->getAttribute(AttributeKey::SCOPE); | ||
$resolvedName = $node->getAttribute(AttributeKey::RESOLVED_NAME); | ||
|
||
if (! $scope instanceof Scope && ! $resolvedName instanceof Name) { | ||
return true; | ||
} | ||
} | ||
|
||
return $this->exprUsedInNodeAnalyzer->isUsed($node, $expr); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This cause invalid result on mysql to mysqli on multiple rules applied like in my previous comment |
||
fn (Node $node): bool => $this->exprUsedInNodeAnalyzer->isUsed($node, $expr) | ||
); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Main point of this PR is to remove these 2 node name traversers. Why?
Pros
They already happen in PHPStan parser that we now use since PHPStan 1.0
Here are used to work around PHPStan changing names without keeping the originals, without those, Rector would print nodes in FQN forms everywhere
Cons
It has downside in losing rules that rely deply on original node names without overriding, mainly with alias imports in union. Thus 2 rules had to removed:
Yet, I think it's worth it, as we cut 3 traverses to 1 and based on shared names with PHPStan traversing, making complexity lower in general.