From 8cf3c9a7f9e60acc675b00d2cd637be2ae8c0536 Mon Sep 17 00:00:00 2001 From: Bernhard Schmitt Date: Wed, 16 Nov 2022 15:23:11 +0100 Subject: [PATCH] Properly run linter and static analyzer in CI --- .github/workflows/qa.yml | 8 ++------ Classes/Aspect/CompilingEvaluatorPreprocessor.php | 2 +- Classes/Domain/Component/PropType/UnionPropType.php | 1 + Classes/Domain/Enum/Enum.php | 2 +- Classes/Domain/Enum/EnumGenerator.php | 2 +- Classes/Domain/Enum/EnumName.php | 13 +++++++++++-- Classes/Infrastructure/UriService.php | 2 +- Classes/Presentation/Slot/Collection.php | 3 ++- Tests/Unit/Domain/DummyFactoryRendererTest.php | 5 ++++- composer.json | 3 ++- phpstan.neon | 2 +- 11 files changed, 27 insertions(+), 16 deletions(-) diff --git a/.github/workflows/qa.yml b/.github/workflows/qa.yml index 19cb8a7..72983af 100644 --- a/.github/workflows/qa.yml +++ b/.github/workflows/qa.yml @@ -18,11 +18,7 @@ jobs: - name: Run PHP Code Sniffer run: | - phpcs \ - --standard=PSR12 \ - --extensions=php \ - --exclude=Generic.Files.LineLength \ - Classes/ Tests/ + composer lint static-analysis: runs-on: ubuntu-20.04 @@ -53,7 +49,7 @@ jobs: - name: Run phpstan run: | - composer lint + composer analyze unit-tests: runs-on: ubuntu-20.04 diff --git a/Classes/Aspect/CompilingEvaluatorPreprocessor.php b/Classes/Aspect/CompilingEvaluatorPreprocessor.php index 03a01f9..07bc7ea 100644 --- a/Classes/Aspect/CompilingEvaluatorPreprocessor.php +++ b/Classes/Aspect/CompilingEvaluatorPreprocessor.php @@ -18,7 +18,7 @@ final class CompilingEvaluatorPreprocessor { #[Flow\Before('method(Neos\Eel\CompilingEvaluator->evaluate())')] - public function preprocessEvaluate(JoinPointInterface $joinPoint) + public function preprocessEvaluate(JoinPointInterface $joinPoint): void { $context = $joinPoint->getMethodArgument('context'); $joinPoint->setMethodArgument( diff --git a/Classes/Domain/Component/PropType/UnionPropType.php b/Classes/Domain/Component/PropType/UnionPropType.php index 1a4ab5f..43407e9 100644 --- a/Classes/Domain/Component/PropType/UnionPropType.php +++ b/Classes/Domain/Component/PropType/UnionPropType.php @@ -22,6 +22,7 @@ public function __construct( private readonly bool $nullable, PropTypeInterface ...$propTypes ) { + /** @var array $propTypes */ $this->propTypes = $propTypes; } diff --git a/Classes/Domain/Enum/Enum.php b/Classes/Domain/Enum/Enum.php index 4896c97..6e183f8 100644 --- a/Classes/Domain/Enum/Enum.php +++ b/Classes/Domain/Enum/Enum.php @@ -74,7 +74,7 @@ private function getConstantName(string $value): string private function camelCaseToUpperSnakeCase(string $value): string { - return strtoupper(preg_replace('/(?componentName->getPhpNamespace() . '\\' . $this->name; + /** @var class-string $name */ + $name = $this->componentName->getPhpNamespace() . '\\' . $this->name; + + return $name; } + /** + * @return class-string + */ public function getProviderName(): string { - return $this->name . 'Provider'; + /** @var class-string $name */ + $name = $this->name . 'Provider'; + + return $name; } public function getPhpFilePath(string $packagePath, bool $colocate): string diff --git a/Classes/Infrastructure/UriService.php b/Classes/Infrastructure/UriService.php index 0064d47..8af2a31 100644 --- a/Classes/Infrastructure/UriService.php +++ b/Classes/Infrastructure/UriService.php @@ -89,7 +89,7 @@ public function getPersistentResourceUri(PersistentResource $resource): ?Uri { $uri = $this->resourceManager->getPublicPersistentResourceUri($resource); - return $uri + return is_string($uri) ? new Uri($uri) : null; } diff --git a/Classes/Presentation/Slot/Collection.php b/Classes/Presentation/Slot/Collection.php index a13a248..bbc5c5c 100644 --- a/Classes/Presentation/Slot/Collection.php +++ b/Classes/Presentation/Slot/Collection.php @@ -22,10 +22,11 @@ final class Collection implements SlotInterface private function __construct(SlotInterface ...$items) { + /** @var array $items */ $this->items = $items; } - public static function fromSlots(SlotInterface ...$items) + public static function fromSlots(SlotInterface ...$items): self { return new self(...$items); } diff --git a/Tests/Unit/Domain/DummyFactoryRendererTest.php b/Tests/Unit/Domain/DummyFactoryRendererTest.php index 52d2edd..ee1caf4 100644 --- a/Tests/Unit/Domain/DummyFactoryRendererTest.php +++ b/Tests/Unit/Domain/DummyFactoryRendererTest.php @@ -64,6 +64,9 @@ public function setUp(): void public function testGetFactoryContent(): void { + /** @var Component $object */ + $object = $this->component; + Assert::assertSame( 'renderFactoryContent($this->component) + (new DummyFactoryRenderer())->renderFactoryContent($object) ); } } diff --git a/composer.json b/composer.json index e34bd83..c78f361 100755 --- a/composer.json +++ b/composer.json @@ -29,7 +29,8 @@ "sitegeist/monocle-presentationobjects": "For Monocle integration" }, "scripts": { - "lint": "bin/phpunit -c phpunit.xml --enforce-time-limit --coverage-html Build/Reports/coverage Tests", + "lint": "bin/phpcs --standard=PSR12 --extensions=php --exclude=Generic.Files.LineLength Classes/ Tests/", + "analyse": "bin/phpstan analyse --level 8 Tests/Unit Classes", "test": "bin/phpunit -c phpunit.xml --enforce-time-limit --coverage-html Build/Reports/coverage Tests" }, "config": { diff --git a/phpstan.neon b/phpstan.neon index 588bdd5..5d61a14 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -6,7 +6,7 @@ parameters: - Packages/Framework/Neos.Flow/Tests/UnitTestCase.php - Packages/Framework/Neos.Flow/Tests/FunctionalTestCase.php - Tests/Unit/Fixtures/Site/Presentation/Component/MyReflectionComponent/MyReflectionComponent.php - - Tests/Unit/Fixtures/Site/Presentation/Component/MyNewComponent/MyStringPseudoEnum.php + - Tests/Unit/Fixtures/Site/Presentation/Component/MyNewComponent/MyStringEnum.php - phpstan.bootstrap.php excludes_analyse: - Tests/Unit/Helper/*