From fe8bc30211c955ce08629fecf69b87ab4ad3c0f4 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Thu, 17 Apr 2025 15:36:39 +0200 Subject: [PATCH] Fix reported PHPCS errors --- finder.php | 4 +++- src/Visitor.php | 15 +++++++++------ tests/TypeInferenceTest.php | 4 +++- visitor.php | 4 +++- 4 files changed, 18 insertions(+), 9 deletions(-) diff --git a/finder.php b/finder.php index 0eeebc61..111886b3 100644 --- a/finder.php +++ b/finder.php @@ -2,9 +2,11 @@ declare(strict_types=1); +use StubsGenerator\Finder; + // phpcs:disable Squiz.PHP.CommentedOutCode -return \StubsGenerator\Finder::create() +return Finder::create() ->in('source/wordpress') // Shim for load-styles.php and load-scripts.php. ->notPath('wp-admin/includes/noop.php') diff --git a/src/Visitor.php b/src/Visitor.php index 3a07bb10..386000e9 100644 --- a/src/Visitor.php +++ b/src/Visitor.php @@ -30,6 +30,9 @@ use PhpParser\Node\Stmt\Property; use PhpParser\Node\Stmt\Return_ as Stmt_Return; use StubsGenerator\NodeVisitor; +use phpDocumentor\Reflection\DocBlockFactoryInterface; +use phpDocumentor\Reflection\DocBlockFactory; +use function assert; // phpcs:disable SlevomatCodingStandard.Functions.FunctionLength.FunctionLength,NeutronStandard.Functions.TypeHint.NoReturnType @@ -40,7 +43,7 @@ class Visitor extends NodeVisitor */ private const WP_INDENT_SIZE = 4; - private \phpDocumentor\Reflection\DocBlockFactoryInterface $docBlockFactory; + private DocBlockFactoryInterface $docBlockFactory; /** @var array> */ private array $functionMap; @@ -51,11 +54,11 @@ class Visitor extends NodeVisitor /** @var array> */ private array $additionalTagStrings = []; - private \PhpParser\NodeFinder $nodeFinder; + private NodeFinder $nodeFinder; public function __construct() { - $this->docBlockFactory = \phpDocumentor\Reflection\DocBlockFactory::createInstance(); + $this->docBlockFactory = DocBlockFactory::createInstance(); $this->nodeFinder = new NodeFinder(); $this->functionMap = require sprintf('%s/functionMap.php', dirname(__DIR__)); } @@ -124,15 +127,15 @@ private function getSymbolName(Node $node): string $name = $node->props[0]->name->name; } - \assert(isset($name), 'Node does not have a name'); + assert(isset($name), 'Node does not have a name'); if ($node instanceof Function_ || $node instanceof Class_) { return $name; } $parent = $this->stack[count($this->stack) - 2]; - \assert($parent instanceof \PhpParser\Node\Stmt\ClassLike); - \assert($parent->name instanceof \PhpParser\Node\Identifier); + assert($parent instanceof ClassLike); + assert($parent->name instanceof Identifier); return sprintf( '%1$s::%2$s%3$s', diff --git a/tests/TypeInferenceTest.php b/tests/TypeInferenceTest.php index 42067a55..1b82760a 100644 --- a/tests/TypeInferenceTest.php +++ b/tests/TypeInferenceTest.php @@ -4,7 +4,9 @@ namespace PhpStubs\WordPress\Core\Tests; -class TypeInferenceTest extends \PHPStan\Testing\TypeInferenceTestCase +use PHPStan\Testing\TypeInferenceTestCase; + +class TypeInferenceTest extends TypeInferenceTestCase { /** @return iterable */ public function dataFileAsserts(): iterable diff --git a/visitor.php b/visitor.php index 8e41764a..355ef144 100644 --- a/visitor.php +++ b/visitor.php @@ -2,6 +2,8 @@ declare(strict_types=1); +use PhpStubs\WordPress\Core\Visitor; + require sprintf('%s/vendor/autoload.php', __DIR__); -return new PhpStubs\WordPress\Core\Visitor(); +return new Visitor();