diff --git a/src/HookDocsRule.php b/src/HookDocsRule.php index 4d386aa..5579448 100644 --- a/src/HookDocsRule.php +++ b/src/HookDocsRule.php @@ -11,7 +11,10 @@ use PhpParser\Node; use PhpParser\Node\Arg; use PhpParser\Node\Expr\FuncCall; +use PhpParser\Node\Expr\Variable; +use PhpParser\Node\Name; use PHPStan\Analyser\Scope; +use PHPStan\PhpDoc\ResolvedPhpDocBlock; use PHPStan\PhpDoc\Tag\ParamTag; use PHPStan\Rules\RuleErrorBuilder; use PHPStan\Rules\RuleLevelHelper; @@ -67,7 +70,7 @@ public function processNode(Node $node, Scope $scope): array $this->currentNode = $node; $this->currentScope = $scope; - if (!($name instanceof \PhpParser\Node\Name)) { + if (!($name instanceof Name)) { return []; } @@ -91,7 +94,7 @@ public function processNode(Node $node, Scope $scope): array * @param \PHPStan\PhpDoc\ResolvedPhpDocBlock $resolvedPhpDoc * @return array */ - public function validateDocBlock(\PHPStan\PhpDoc\ResolvedPhpDocBlock $resolvedPhpDoc): array + public function validateDocBlock(ResolvedPhpDocBlock $resolvedPhpDoc): array { // Count all documented `@param` tag strings in the docblock. $numberOfParamTagStrings = substr_count($resolvedPhpDoc->getPhpDocString(), '* @param '); @@ -169,7 +172,7 @@ public function validateParamCount(int $numberOfParamTagStrings): void */ public function validateParamDocumentation( int $numberOfParamTags, - \PHPStan\PhpDoc\ResolvedPhpDocBlock $resolvedPhpDoc + ResolvedPhpDocBlock $resolvedPhpDoc ): void { $nodeArgs = $this->currentNode->getArgs(); $numberOfParams = count($nodeArgs) - 1; @@ -182,7 +185,7 @@ public function validateParamDocumentation( // We might have an invalid `@param` tag because it's named `$this`. if (strpos($resolvedPhpDoc->getPhpDocString(), ' $this') !== false) { foreach ($nodeArgs as $param) { - if (($param->value instanceof \PhpParser\Node\Expr\Variable) && $param->value->name === 'this') { + if (($param->value instanceof Variable) && $param->value->name === 'this') { // PHPStan does not detect param tags named `$this`, it skips the tag. // We can indirectly detect this by checking the actual parameter name, // and if one of them is `$this` assume that's the problem. diff --git a/src/IsWpErrorRule.php b/src/IsWpErrorRule.php index 4c27be9..fcb14ea 100644 --- a/src/IsWpErrorRule.php +++ b/src/IsWpErrorRule.php @@ -10,6 +10,7 @@ use PhpParser\Node\Expr\FuncCall; use PhpParser\Node; +use PhpParser\Node\Name; use PHPStan\Analyser\Scope; use PHPStan\Rules\RuleErrorBuilder; use PHPStan\Rules\RuleLevelHelper; @@ -46,7 +47,7 @@ public function processNode(Node $node, Scope $scope): array { $name = $node->name; - if (! ($name instanceof \PhpParser\Node\Name)) { + if (! ($name instanceof Name)) { return []; } diff --git a/src/WpThemeGetDynamicMethodReturnTypeExtension.php b/src/WpThemeGetDynamicMethodReturnTypeExtension.php index b463be7..e173fd5 100644 --- a/src/WpThemeGetDynamicMethodReturnTypeExtension.php +++ b/src/WpThemeGetDynamicMethodReturnTypeExtension.php @@ -20,6 +20,7 @@ use PHPStan\Type\StringType; use PHPStan\Type\Type; use PHPStan\Type\TypeCombinator; +use WP_Theme; class WpThemeGetDynamicMethodReturnTypeExtension implements \PHPStan\Type\DynamicMethodReturnTypeExtension { @@ -46,7 +47,7 @@ class WpThemeGetDynamicMethodReturnTypeExtension implements \PHPStan\Type\Dynami public function getClass(): string { - return 'WP_Theme'; + return WP_Theme::class; } public function isMethodSupported(MethodReflection $methodReflection): bool diff --git a/tests/HookDocsRuleTest.php b/tests/HookDocsRuleTest.php index bb1ca46..73e1184 100644 --- a/tests/HookDocsRuleTest.php +++ b/tests/HookDocsRuleTest.php @@ -4,6 +4,7 @@ namespace SzepeViktor\PHPStan\WordPress\Tests; +use PHPStan\Rules\Rule; use PHPStan\Rules\RuleLevelHelper; use PHPStan\Type\FileTypeMapper; use SzepeViktor\PHPStan\WordPress\HookDocsRule; @@ -13,7 +14,7 @@ */ class HookDocsRuleTest extends \PHPStan\Testing\RuleTestCase { - protected function getRule(): \PHPStan\Rules\Rule + protected function getRule(): Rule { /** @var \PHPStan\Type\FileTypeMapper */ $fileTypeMapper = self::getContainer()->getByType(FileTypeMapper::class); diff --git a/tests/IsWpErrorRuleTest.php b/tests/IsWpErrorRuleTest.php index a744fee..afce04c 100644 --- a/tests/IsWpErrorRuleTest.php +++ b/tests/IsWpErrorRuleTest.php @@ -4,6 +4,7 @@ namespace SzepeViktor\PHPStan\WordPress\Tests; +use PHPStan\Rules\Rule; use PHPStan\Rules\RuleLevelHelper; use SzepeViktor\PHPStan\WordPress\IsWpErrorRule; @@ -12,7 +13,7 @@ */ class IsWpErrorRuleTest extends \PHPStan\Testing\RuleTestCase { - protected function getRule(): \PHPStan\Rules\Rule + protected function getRule(): Rule { /** @var \PHPStan\Rules\RuleLevelHelper */ $ruleLevelHelper = self::getContainer()->getByType(RuleLevelHelper::class); diff --git a/tests/data/esc_sql.php b/tests/data/esc_sql.php index 0bdc14a..c75ed13 100644 --- a/tests/data/esc_sql.php +++ b/tests/data/esc_sql.php @@ -18,4 +18,4 @@ assertType('string', esc_sql('someValueToEscape')); // Wrong type provided (esc_sql() returns an empty string in that case) -assertType('string', esc_sql(new \stdClass())); +assertType('string', esc_sql(new stdClass())); diff --git a/tests/data/get_post.php b/tests/data/get_post.php index 4f8fa82..6e03324 100644 --- a/tests/data/get_post.php +++ b/tests/data/get_post.php @@ -4,10 +4,11 @@ namespace SzepeViktor\PHPStan\WordPress\Tests; +use stdClass; use function PHPStan\Testing\assertType; /** @var \WP_Post $wpPostType */ -$wpPostType = new \stdClass(); +$wpPostType = new stdClass(); // Default output assertType('WP_Post|null', get_post());