From 390fe54f4dca83e10789b07199c4f1838b455296 Mon Sep 17 00:00:00 2001 From: Alexander Schranz Date: Tue, 22 Jun 2021 20:11:30 +0200 Subject: [PATCH] Fix phpstan errors --- .github/workflows/test-application.yaml | 37 ++++++++++++------- .../Doctrine/MetadataLoader.php | 10 +++++ .../ContentDataProviderRepository.php | 8 ++-- Tests/Application/.env | 2 +- Tests/Application/.env.dev | 2 +- phpstan-baseline.neon | 27 ++++++++++++++ phpstan.neon | 1 + 7 files changed, 69 insertions(+), 18 deletions(-) create mode 100644 phpstan-baseline.neon diff --git a/.github/workflows/test-application.yaml b/.github/workflows/test-application.yaml index 262ed179..bbd7cbc4 100644 --- a/.github/workflows/test-application.yaml +++ b/.github/workflows/test-application.yaml @@ -9,11 +9,11 @@ on: jobs: test: - name: 'PHP ${{ matrix.php-version }} (${{ matrix.dependency-versions }}, Lint ${{ matrix.lint }}, Coverage ${{ matrix.coverage }})' + name: 'PHP ${{ matrix.php-version }} (${{ matrix.dependency-versions }}, Coverage ${{ matrix.coverage }})' runs-on: ubuntu-latest env: - DATABASE_URL: mysql://root:root@127.0.0.1:3306/su_headless_test?serverVersion=5.7 + DATABASE_URL: mysql://root:root@127.0.0.1:3306/su_content_test?serverVersion=5.7 DATABASE_CHARSET: utf8mb4 DATABASE_COLLATE: utf8mb4_unicode_ci @@ -22,26 +22,20 @@ jobs: matrix: include: - php-version: '7.2' - lint: false coverage: false dependency-versions: 'lowest' - tools: 'composer:v1' env: SYMFONY_DEPRECATIONS_HELPER: disabled - php-version: '7.4' - lint: true coverage: true dependency-versions: 'highest' - tools: 'composer:v2' env: SYMFONY_DEPRECATIONS_HELPER: weak - php-version: '8.0' - lint: false coverage: false dependency-versions: 'highest' - tools: 'composer:v2' env: SYMFONY_DEPRECATIONS_HELPER: weak @@ -64,7 +58,6 @@ jobs: php-version: ${{ matrix.php-version }} extensions: ctype, iconv, mysql coverage: pcov - tools: ${{ matrix.tools }} - name: Install composer dependencies uses: ramsey/composer-install@v1 @@ -75,10 +68,6 @@ jobs: - name: Bootstrap test environment run: composer bootstrap-test-environment - - name: Lint Code - if: ${{ matrix.lint }} - run: composer lint - - name: Execute test cases if: matrix.coverage == false run: composer test @@ -98,3 +87,25 @@ jobs: - name: Check code coverage if: ${{ matrix.coverage }} run: composer check-coverage + + lint: + name: "PHP Lint" + runs-on: ubuntu-latest + + steps: + - name: Checkout project + uses: actions/checkout@v2 + + - name: Install and configure PHP + uses: shivammathur/setup-php@v2 + with: + php-version: 8.0 + extensions: ctype, iconv, mysql + + - name: Install composer dependencies + uses: ramsey/composer-install@v1 + with: + dependency-versions: highest + + - name: Lint Code + run: composer lint diff --git a/Content/Infrastructure/Doctrine/MetadataLoader.php b/Content/Infrastructure/Doctrine/MetadataLoader.php index 6d460b30..9fdb0c14 100644 --- a/Content/Infrastructure/Doctrine/MetadataLoader.php +++ b/Content/Infrastructure/Doctrine/MetadataLoader.php @@ -41,6 +41,7 @@ public function getSubscribedEvents() public function loadClassMetadata(LoadClassMetadataEventArgs $event): void { + /** @var ClassMetadataInfo $metadata */ $metadata = $event->getClassMetadata(); $reflection = $metadata->getReflectionClass(); @@ -102,6 +103,8 @@ public function loadClassMetadata(LoadClassMetadataEventArgs $event): void /** * @codeCoverageIgnore + * + * @param ClassMetadataInfo $metadata */ private function addManyToOne( LoadClassMetadataEventArgs $event, @@ -131,6 +134,9 @@ private function addManyToOne( ]); } + /** + * @param ClassMetadataInfo $metadata + */ private function addManyToMany( LoadClassMetadataEventArgs $event, ClassMetadataInfo $metadata, @@ -173,6 +179,7 @@ private function addManyToMany( } /** + * @param ClassMetadataInfo $metadata * @param mixed[] $mapping */ private function addField(ClassMetadataInfo $metadata, string $name, string $type = 'string', array $mapping = []): void @@ -194,6 +201,9 @@ private function addField(ClassMetadataInfo $metadata, string $name, string $typ ], $mapping)); } + /** + * @param ClassMetadataInfo $metadata + */ private function getRelationTableName(ClassMetadataInfo $metadata, string $relationName): string { $inflector = InflectorFactory::create()->build(); diff --git a/Content/Infrastructure/Sulu/SmartContent/Repository/ContentDataProviderRepository.php b/Content/Infrastructure/Sulu/SmartContent/Repository/ContentDataProviderRepository.php index 0158c70f..02369b73 100644 --- a/Content/Infrastructure/Sulu/SmartContent/Repository/ContentDataProviderRepository.php +++ b/Content/Infrastructure/Sulu/SmartContent/Repository/ContentDataProviderRepository.php @@ -14,7 +14,7 @@ namespace Sulu\Bundle\ContentBundle\Content\Infrastructure\Sulu\SmartContent\Repository; use Doctrine\ORM\EntityManagerInterface; -use Doctrine\ORM\Mapping\ClassMetadata; +use Doctrine\ORM\Mapping\ClassMetadataInfo; use Doctrine\ORM\QueryBuilder; use Sulu\Bundle\ContentBundle\Content\Application\ContentManager\ContentManagerInterface; use Sulu\Bundle\ContentBundle\Content\Domain\Model\ContentRichEntityInterface; @@ -48,7 +48,7 @@ class ContentDataProviderRepository implements DataProviderRepositoryInterface protected $contentRichEntityClass; /** - * @var ClassMetadata + * @var ClassMetadataInfo */ protected $contentRichEntityClassMetadata; @@ -67,7 +67,9 @@ public function __construct( $this->showDrafts = $showDrafts; $this->contentRichEntityClass = $contentRichEntityClass; - $this->contentRichEntityClassMetadata = $this->entityManager->getClassMetadata($this->contentRichEntityClass); + /** @var ClassMetadataInfo $contentRichEntityClassMetadata */ + $contentRichEntityClassMetadata = $this->entityManager->getClassMetadata($this->contentRichEntityClass); + $this->contentRichEntityClassMetadata = $contentRichEntityClassMetadata; } /** diff --git a/Tests/Application/.env b/Tests/Application/.env index fd56afbb..a33dd03a 100644 --- a/Tests/Application/.env +++ b/Tests/Application/.env @@ -1,4 +1,4 @@ APP_ENV=test -DATABASE_URL=mysql://root:@127.0.0.1:3306/su_content_test +DATABASE_URL=mysql://root:@127.0.0.1:3306/su_content_test?serverVersion=5.7 DATABASE_CHARSET=utf8mb4 DATABASE_COLLATE=utf8mb4_unicode_ci diff --git a/Tests/Application/.env.dev b/Tests/Application/.env.dev index f28f8a4f..393bcccd 100644 --- a/Tests/Application/.env.dev +++ b/Tests/Application/.env.dev @@ -1 +1 @@ -DATABASE_URL=mysql://root:@127.0.0.1:3306/su_content_test_dev +DATABASE_URL=mysql://root:@127.0.0.1:3306/su_content_test_dev?serverVersion=5.7 diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon new file mode 100644 index 00000000..f327aa51 --- /dev/null +++ b/phpstan-baseline.neon @@ -0,0 +1,27 @@ +parameters: + ignoreErrors: + - + message: "#^Method Sulu\\\\Bundle\\\\ContentBundle\\\\Content\\\\Infrastructure\\\\Doctrine\\\\MetadataLoader\\:\\:addField\\(\\) has parameter \\$metadata with generic class Doctrine\\\\ORM\\\\Mapping\\\\ClassMetadataInfo but does not specify its types\\: T$#" + count: 1 + path: Content/Infrastructure/Doctrine/MetadataLoader.php + + - + message: "#^Method Sulu\\\\Bundle\\\\ContentBundle\\\\Content\\\\Infrastructure\\\\Doctrine\\\\MetadataLoader\\:\\:addManyToMany\\(\\) has parameter \\$metadata with generic class Doctrine\\\\ORM\\\\Mapping\\\\ClassMetadataInfo but does not specify its types\\: T$#" + count: 1 + path: Content/Infrastructure/Doctrine/MetadataLoader.php + + - + message: "#^Method Sulu\\\\Bundle\\\\ContentBundle\\\\Content\\\\Infrastructure\\\\Doctrine\\\\MetadataLoader\\:\\:addManyToOne\\(\\) has parameter \\$metadata with generic class Doctrine\\\\ORM\\\\Mapping\\\\ClassMetadataInfo but does not specify its types\\: T$#" + count: 1 + path: Content/Infrastructure/Doctrine/MetadataLoader.php + + - + message: "#^Method Sulu\\\\Bundle\\\\ContentBundle\\\\Content\\\\Infrastructure\\\\Doctrine\\\\MetadataLoader\\:\\:getRelationTableName\\(\\) has parameter \\$metadata with generic class Doctrine\\\\ORM\\\\Mapping\\\\ClassMetadataInfo but does not specify its types\\: T$#" + count: 1 + path: Content/Infrastructure/Doctrine/MetadataLoader.php + + - + message: "#^Property Sulu\\\\Bundle\\\\ContentBundle\\\\Content\\\\Infrastructure\\\\Sulu\\\\SmartContent\\\\Repository\\\\ContentDataProviderRepository\\:\\:\\$contentRichEntityClassMetadata with generic class Doctrine\\\\ORM\\\\Mapping\\\\ClassMetadata does not specify its types\\: T$#" + count: 1 + path: Content/Infrastructure/Sulu/SmartContent/Repository/ContentDataProviderRepository.php + diff --git a/phpstan.neon b/phpstan.neon index b95a3e16..32c07cc4 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -19,6 +19,7 @@ parameters: symfony: container_xml_path: %currentWorkingDirectory%/Tests/Application/var/cache/admin/dev/Sulu_Bundle_ContentBundle_Tests_Application_KernelDevDebugContainer.xml console_application_loader: Tests/phpstan/console-application.php + constant_hassers: false doctrine: objectManagerLoader: Tests/phpstan/object-manager.php bootstrapFiles: