Skip to content

Commit

Permalink
Run psalm under php 8.2
Browse files Browse the repository at this point in the history
  • Loading branch information
ostrolucky committed Nov 16, 2023
1 parent eb96246 commit c9c29de
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 44 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/static-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
strategy:
matrix:
php-version:
- "7.4"
- "8.2"

steps:
- name: "Checkout code"
Expand Down
2 changes: 1 addition & 1 deletion DependencyInjection/DoctrineExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ protected function dbalLoad(array $config, ContainerBuilder $container)
$connections = [];

foreach (array_keys($config['connections']) as $name) {
/** @psalm-suppress InvalidArrayOffset */
/** @psalm-suppress InvalidArrayOffset https://github.com/vimeo/psalm/issues/10382 */
$connections[$name] = sprintf('doctrine.dbal.%s_connection', $name);
}

Expand Down
21 changes: 19 additions & 2 deletions Repository/ServiceEntityRepositoryProxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,25 +41,35 @@ public function __construct(
$this->repository = $this->resolveRepository();
}

/** @psalm-suppress MethodSignatureMismatch This proxy is used only in combination with newer parent class */
public function createQueryBuilder(string $alias, ?string $indexBy = null): QueryBuilder
{
return ($this->repository ??= $this->resolveRepository())
->createQueryBuilder($alias, $indexBy);
}

/** @psalm-suppress MethodSignatureMismatch This proxy is used only in combination with newer parent class */
public function createResultSetMappingBuilder(string $alias): ResultSetMappingBuilder
{
return ($this->repository ??= $this->resolveRepository())
->createResultSetMappingBuilder($alias);
}

/** @psalm-suppress MethodSignatureMismatch This proxy is used only in combination with newer parent class */
public function find(mixed $id, LockMode|int|null $lockMode = null, int|null $lockVersion = null): object|null
{
/** @psalm-suppress InvalidReturnStatement This proxy is used only in combination with newer parent class */
return ($this->repository ??= $this->resolveRepository())
->find($id, $lockMode, $lockVersion);
}

/** {@inheritDoc} */
/**
* {@inheritDoc}
*
* @psalm-suppress InvalidReturnStatement This proxy is used only in combination with newer parent class
* @psalm-suppress MethodSignatureMismatch This proxy is used only in combination with newer parent class
* @psalm-suppress InvalidReturnType This proxy is used only in combination with newer parent class
*/
public function findBy(array $criteria, ?array $orderBy = null, ?int $limit = null, ?int $offset = null): array
{
return ($this->repository ??= $this->resolveRepository())
Expand All @@ -69,6 +79,7 @@ public function findBy(array $criteria, ?array $orderBy = null, ?int $limit = nu
/** {@inheritDoc} */
public function findOneBy(array $criteria, ?array $orderBy = null): object|null
{
/** @psalm-suppress InvalidReturnStatement This proxy is used only in combination with newer parent class */
return ($this->repository ??= $this->resolveRepository())
->findOneBy($criteria, $orderBy);
}
Expand All @@ -79,7 +90,11 @@ public function count(array $criteria = []): int
return ($this->repository ??= $this->resolveRepository())->count($criteria);
}

/** {@inheritDoc} */
/**
* {@inheritDoc}
*
* @psalm-suppress MethodSignatureMismatch This proxy is used only in combination with newer parent class
*/
public function __call(string $method, array $arguments): mixed
{
return ($this->repository ??= $this->resolveRepository())->$method(...$arguments);
Expand All @@ -95,8 +110,10 @@ protected function getEntityManager(): EntityManagerInterface
return ($this->repository ??= $this->resolveRepository())->getEntityManager();
}

/** @psalm-suppress InvalidReturnType This proxy is used only in combination with newer parent class */
protected function getClassMetadata(): ClassMetadata
{
/** @psalm-suppress InvalidReturnStatement This proxy is used only in combination with newer parent class */
return ($this->repository ??= $this->resolveRepository())->getClassMetadata();
}

Expand Down
2 changes: 2 additions & 0 deletions Tests/CacheSchemaSubscriberTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ public function getSchemaSubscribers(): Generator

/**
* available in Symfony 5.1 and up to Symfony 5.4 (deprecated)
*
* @psalm-suppress UndefinedClass
*/
yield ['cache.adapter.pdo', 'doctrine.orm.listeners.pdo_cache_adapter_doctrine_schema_subscriber', PdoCacheAdapterDoctrineSchemaSubscriber::class];
}
Expand Down
5 changes: 1 addition & 4 deletions Tests/DependencyInjection/AbstractDoctrineExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -363,10 +363,7 @@ public function testLoadSimpleSingleConnectionWithoutDbName(): void

$container = $this->loadContainer('orm_service_simple_single_entity_manager_without_dbname');

$definition = $container->getDefinition('doctrine.dbal.default_connection');
assert($definition instanceof Definition);

$this->assertDICConstructorArguments($definition, [
$this->assertDICConstructorArguments($container->getDefinition('doctrine.dbal.default_connection'), [
[
'host' => 'localhost',
'port' => null,
Expand Down
12 changes: 4 additions & 8 deletions Tests/DependencyInjection/DoctrineExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1001,16 +1001,12 @@ public function testMessengerIntegration(): void
->build();
$extension->load([$config], $container);

$this->assertNotNull($middlewarePrototype = $container->getDefinition('messenger.middleware.doctrine_transaction'));
$this->assertCount(1, $middlewarePrototype->getArguments());
$this->assertNotNull($middlewarePrototype = $container->getDefinition('messenger.middleware.doctrine_ping_connection'));
$this->assertCount(1, $middlewarePrototype->getArguments());
$this->assertNotNull($middlewarePrototype = $container->getDefinition('messenger.middleware.doctrine_close_connection'));
$this->assertCount(1, $middlewarePrototype->getArguments());
$this->assertCount(1, $container->getDefinition('messenger.middleware.doctrine_transaction')->getArguments());
$this->assertCount(1, $container->getDefinition('messenger.middleware.doctrine_ping_connection')->getArguments());
$this->assertCount(1, $container->getDefinition('messenger.middleware.doctrine_close_connection')->getArguments());

if (class_exists(DoctrineClearEntityManagerWorkerSubscriber::class)) {
$this->assertNotNull($subscriber = $container->getDefinition('doctrine.orm.messenger.event_subscriber.doctrine_clear_entity_manager'));
$this->assertCount(1, $subscriber->getArguments());
$this->assertCount(1, $container->getDefinition('doctrine.orm.messenger.event_subscriber.doctrine_clear_entity_manager')->getArguments());
} else {
$this->assertFalse($container->hasDefinition('doctrine.orm.messenger.event_subscriber.doctrine_clear_entity_manager'));
}
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"doctrine/deprecations": "^1.0",
"doctrine/orm": "^2.14 || ^3.0",
"friendsofphp/proxy-manager-lts": "^1.0",
"phpunit/phpunit": "^9.5.26 || ^10.0",
"phpunit/phpunit": "^9.5.26",
"psalm/plugin-phpunit": "^0.18.4",
"psalm/plugin-symfony": "^5",
"psr/log": "^1.1.4 || ^2.0 || ^3.0",
Expand Down
28 changes: 1 addition & 27 deletions psalm.xml.dist
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?xml version="1.0"?>
<psalm
errorLevel="4"
phpVersion="8.2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
findUnusedBaselineEntry="true"
Expand All @@ -18,10 +19,6 @@
<file name="Command/ImportMappingDoctrineCommand.php"/>
<file name="Command/Proxy/OrmProxyCommand.php"/>
<file name="DependencyInjection/Compiler/WellKnownSchemaFilterPass.php"/>
<!-- We need to run Psalm under >= PHP 8.1 to analyze this file due to intersection types (ParseError) -->
<file name="Repository/ServiceEntityRepositoryProxy.php"/>
<!-- Psalm crashes on this file if we attempt to suppress UndefinedClass for LazyObjectInterface -->
<file name="Repository/LazyServiceEntityRepository.php"/>
</ignoreFiles>
<directory name="CacheWarmer"/>
<directory name="Command"/>
Expand All @@ -40,12 +37,6 @@
<file name="Registry.php"/>
</projectFiles>
<issueHandlers>
<InvalidArrayOffset>
<errorLevel type="suppress">
<!-- requires a release of https://github.com/doctrine/dbal/pull/5261 -->
<file name="Tests/ConnectionFactoryTest.php"/>
</errorLevel>
</InvalidArrayOffset>
<RedundantPropertyInitializationCheck>
<errorLevel type="suppress">
<!-- Properties can be uninitialized in tests if setUp() fails. -->
Expand All @@ -56,25 +47,8 @@
<errorLevel type="suppress">
<!-- We use the "Foo" namespace in unit tests. We are aware that those classes don't exist. -->
<referencedClass name="Foo\*"/>
<referencedClass name="Symfony\Bridge\Doctrine\Attribute\MapEntity"/>
<!-- Since Symfony 6.2 -->
<referencedClass name="Symfony\Component\VarExporter\LazyObjectInterface"/>
</errorLevel>
</UndefinedClass>
<UndefinedDocblockClass>
<errorLevel type="suppress">
<!-- https://github.com/symfony/symfony/issues/45609 -->
<referencedClass name="UnitEnum" />
<directory name="DependencyInjection"/>
<directory name="Tests/DependencyInjection"/>
</errorLevel>
</UndefinedDocblockClass>
<UndefinedTrait>
<errorLevel type="suppress">
<!-- Consumer is meant to check if trait exists before using this class -->
<file name="Repository/LazyServiceEntityRepository.php"/>
</errorLevel>
</UndefinedTrait>
<DuplicateClass>
<errorLevel type="suppress">
<!-- Conditional class definition-->
Expand Down

0 comments on commit c9c29de

Please sign in to comment.