Skip to content

Commit

Permalink
Fix phpstan errors
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-schranz committed Jun 22, 2021
1 parent a03a21c commit 390fe54
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 18 deletions.
37 changes: 24 additions & 13 deletions .github/workflows/test-application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:[email protected]:3306/su_headless_test?serverVersion=5.7
DATABASE_URL: mysql://root:[email protected]:3306/su_content_test?serverVersion=5.7
DATABASE_CHARSET: utf8mb4
DATABASE_COLLATE: utf8mb4_unicode_ci

Expand All @@ -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

Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
10 changes: 10 additions & 0 deletions Content/Infrastructure/Doctrine/MetadataLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public function getSubscribedEvents()

public function loadClassMetadata(LoadClassMetadataEventArgs $event): void
{
/** @var ClassMetadataInfo<DimensionContentInterface|SeoInterface|TemplateInterface|ExcerptInterface|WorkflowInterface> $metadata */
$metadata = $event->getClassMetadata();
$reflection = $metadata->getReflectionClass();

Expand Down Expand Up @@ -102,6 +103,8 @@ public function loadClassMetadata(LoadClassMetadataEventArgs $event): void

/**
* @codeCoverageIgnore
*
* @param ClassMetadataInfo<DimensionContentInterface|SeoInterface|TemplateInterface|ExcerptInterface|WorkflowInterface> $metadata
*/
private function addManyToOne(
LoadClassMetadataEventArgs $event,
Expand Down Expand Up @@ -131,6 +134,9 @@ private function addManyToOne(
]);
}

/**
* @param ClassMetadataInfo<DimensionContentInterface|SeoInterface|TemplateInterface|ExcerptInterface|WorkflowInterface> $metadata
*/
private function addManyToMany(
LoadClassMetadataEventArgs $event,
ClassMetadataInfo $metadata,
Expand Down Expand Up @@ -173,6 +179,7 @@ private function addManyToMany(
}

/**
* @param ClassMetadataInfo<DimensionContentInterface|SeoInterface|TemplateInterface|ExcerptInterface|WorkflowInterface> $metadata
* @param mixed[] $mapping
*/
private function addField(ClassMetadataInfo $metadata, string $name, string $type = 'string', array $mapping = []): void
Expand All @@ -194,6 +201,9 @@ private function addField(ClassMetadataInfo $metadata, string $name, string $typ
], $mapping));
}

/**
* @param ClassMetadataInfo<DimensionContentInterface|SeoInterface|TemplateInterface|ExcerptInterface|WorkflowInterface> $metadata
*/
private function getRelationTableName(ClassMetadataInfo $metadata, string $relationName): string
{
$inflector = InflectorFactory::create()->build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -48,7 +48,7 @@ class ContentDataProviderRepository implements DataProviderRepositoryInterface
protected $contentRichEntityClass;

/**
* @var ClassMetadata
* @var ClassMetadataInfo<ContentRichEntityInterface>
*/
protected $contentRichEntityClassMetadata;

Expand All @@ -67,7 +67,9 @@ public function __construct(
$this->showDrafts = $showDrafts;
$this->contentRichEntityClass = $contentRichEntityClass;

$this->contentRichEntityClassMetadata = $this->entityManager->getClassMetadata($this->contentRichEntityClass);
/** @var ClassMetadataInfo<ContentRichEntityInterface> $contentRichEntityClassMetadata */
$contentRichEntityClassMetadata = $this->entityManager->getClassMetadata($this->contentRichEntityClass);
$this->contentRichEntityClassMetadata = $contentRichEntityClassMetadata;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion Tests/Application/.env
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion Tests/Application/.env.dev
Original file line number Diff line number Diff line change
@@ -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
27 changes: 27 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -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

1 change: 1 addition & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 390fe54

Please sign in to comment.