-
-
Notifications
You must be signed in to change notification settings - Fork 863
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f96fc80
commit 423a005
Showing
6 changed files
with
220 additions
and
0 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
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 @@ | ||
/vendor |
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,6 @@ | ||
{ | ||
"require-dev": { | ||
"phpstan/phpstan": "^1.6", | ||
"rector/rector": "^0.12.23" | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,7 @@ | ||
includes: | ||
- phar://phpstan.phar/conf/bleedingEdge.neon | ||
|
||
parameters: | ||
level: 8 | ||
paths: | ||
- src |
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,64 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Luxemate\PhpstanRectorError\Rector\Rule; | ||
|
||
use PhpParser\Node; | ||
use Rector\Core\Rector\AbstractRector; | ||
use Rector\NodeTypeResolver\Node\AttributeKey; | ||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; | ||
|
||
final class ImportPhpUnitFunctionsRector extends AbstractRector | ||
{ | ||
private const PHPUNIT_FUNC_NAMESPACE = 'PHPUnit\\Framework\\'; | ||
|
||
public function refactor(Node $node): ?Node | ||
{ | ||
if (!$node instanceof Node\Name) { | ||
return null; | ||
} | ||
|
||
$parentNode = $node->getAttribute(AttributeKey::PARENT_NODE); | ||
|
||
if (!$parentNode instanceof Node\Expr\FuncCall) { | ||
return null; | ||
} | ||
|
||
$resolvedName = $node->getAttribute(AttributeKey::RESOLVED_NAME); | ||
|
||
// If node has a resolved name, then it's probably an internal function | ||
if ($resolvedName instanceof Node\Name\FullyQualified) { | ||
return null; | ||
} | ||
|
||
/** @var string $functionName */ | ||
$functionName = $this->getName($node); | ||
|
||
// If function name is FQCN it's already imported or is a member of this file's namespace | ||
if (str_contains($functionName, '\\')) { | ||
return null; | ||
} | ||
|
||
$functionFullyQualifiedName = self::PHPUNIT_FUNC_NAMESPACE.$functionName; | ||
|
||
if (!function_exists($functionFullyQualifiedName)) { | ||
return null; | ||
} | ||
|
||
return new Node\Name\FullyQualified($functionFullyQualifiedName); | ||
} | ||
|
||
public function getRuleDefinition(): RuleDefinition | ||
{ | ||
return new RuleDefinition( | ||
'Adds import for non-imported PHPUnit functions.', | ||
[] | ||
); | ||
} | ||
|
||
public function getNodeTypes(): array | ||
{ | ||
return [Node\Name::class]; | ||
} | ||
} |