From aa7c160caec5716d4b9e065e4ed4a90a1cef9c50 Mon Sep 17 00:00:00 2001 From: Vincent Langlet Date: Sat, 6 Aug 2022 12:40:16 +0200 Subject: [PATCH] Allow to install with phpstan-extensions installer (#709) --- composer.json | 7 ++++++ .../TranslatableEventSubscriber.php | 6 ++--- src/Model/Tree/TreeNodeMethodsTrait.php | 23 ++++++------------- tests/ORM/UuidableTest.php | 4 ++-- 4 files changed, 19 insertions(+), 21 deletions(-) diff --git a/composer.json b/composer.json index dab044fb..e975e124 100644 --- a/composer.json +++ b/composer.json @@ -67,5 +67,12 @@ "composer/package-versions-deprecated": true, "phpstan/extension-installer": true } + }, + "extra": { + "phpstan": { + "includes": [ + "phpstan-extension.neon" + ] + } } } diff --git a/src/EventSubscriber/TranslatableEventSubscriber.php b/src/EventSubscriber/TranslatableEventSubscriber.php index 5611c8f6..2df494de 100644 --- a/src/EventSubscriber/TranslatableEventSubscriber.php +++ b/src/EventSubscriber/TranslatableEventSubscriber.php @@ -123,10 +123,10 @@ private function mapTranslation(ClassMetadataInfo $classMetadataInfo, ObjectMana ->getMethod('getTranslatableEntityClass') ->invoke(null); - /** @var ClassMetadataInfo $targetEntityClassMetadataInfo */ - $targetEntityClassMetadataInfo = $objectManager->getClassMetadata($targetEntity); + /** @var ClassMetadataInfo $classMetadata */ + $classMetadata = $objectManager->getClassMetadata($targetEntity); - $singleIdentifierFieldName = $targetEntityClassMetadataInfo->getSingleIdentifierFieldName(); + $singleIdentifierFieldName = $classMetadata->getSingleIdentifierFieldName(); $classMetadataInfo->mapManyToOne([ 'fieldName' => 'translatable', diff --git a/src/Model/Tree/TreeNodeMethodsTrait.php b/src/Model/Tree/TreeNodeMethodsTrait.php index e3201a4a..e195838f 100644 --- a/src/Model/Tree/TreeNodeMethodsTrait.php +++ b/src/Model/Tree/TreeNodeMethodsTrait.php @@ -197,7 +197,7 @@ public function toJson(?Closure $prepare = null): string public function toArray(?Closure $prepare = null, ?array &$tree = null): array { if ($prepare === null) { - $prepare = fn (TreeNodeInterface $node): string => (string) $node; + $prepare = static fn (TreeNodeInterface $node): string => (string) $node; } if ($tree === null) { @@ -229,9 +229,8 @@ public function toArray(?Closure $prepare = null, ?array &$tree = null): array public function toFlatArray(?Closure $prepare = null, ?array &$tree = null): array { if ($prepare === null) { - $prepare = function (TreeNodeInterface $treeNode) { + $prepare = static function (TreeNodeInterface $treeNode) { $pre = $treeNode->getNodeLevel() > 1 ? implode('', array_fill(0, $treeNode->getNodeLevel(), '--')) : ''; - return $pre . $treeNode; }; } @@ -251,36 +250,28 @@ public function toFlatArray(?Closure $prepare = null, ?array &$tree = null): arr } /** - * @param mixed $offset * @param TreeNodeInterface $node */ - public function offsetSet($offset, $node): void + public function offsetSet(mixed $offset, $node): void { /** @var TreeNodeInterface $this */ $node->setChildNodeOf($this); } - /** - * @param mixed $offset - */ - public function offsetExists($offset): bool + public function offsetExists(mixed $offset): bool { return isset($this->getChildNodes()[$offset]); } - /** - * @param mixed $offset - */ - public function offsetUnset($offset): void + public function offsetUnset(mixed $offset): void { unset($this->getChildNodes()[$offset]); } /** - * @param mixed $offset * @return mixed */ - public function offsetGet($offset) + public function offsetGet(mixed $offset) { return $this->getChildNodes()[$offset]; } @@ -297,6 +288,6 @@ protected function getExplodedPath(): array $path = explode($separator, $this->getRealMaterializedPath()); - return array_filter($path, fn ($item): bool => $item !== ''); + return array_filter($path, static fn ($item): bool => $item !== ''); } } diff --git a/tests/ORM/UuidableTest.php b/tests/ORM/UuidableTest.php index 41776577..e6ad61c3 100644 --- a/tests/ORM/UuidableTest.php +++ b/tests/ORM/UuidableTest.php @@ -23,10 +23,10 @@ public function testUuidLoading(): void $this->entityManager->clear(); - $uuidableRepository = $this->entityManager->getRepository(UuidableEntity::class); + $entityRepository = $this->entityManager->getRepository(UuidableEntity::class); /** @var UuidableInterface $entity */ - $entity = $uuidableRepository->find($id); + $entity = $entityRepository->find($id); $this->assertNotNull($entity); $this->assertInstanceOf(UuidInterface::class, $entity->getUuid());