Skip to content

Commit ecfd2b3

Browse files
authored
psalm 4.x -> 5.x (#1728)
1 parent 4089f14 commit ecfd2b3

28 files changed

+113
-164
lines changed

.github/workflows/static-analysis.yml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,6 @@ jobs:
1414
name: "Static Analysis with Psalm"
1515
runs-on: "ubuntu-22.04"
1616

17-
strategy:
18-
matrix:
19-
php-version:
20-
- "7.4"
21-
2217
steps:
2318
- name: "Checkout code"
2419
uses: "actions/checkout@v4"
@@ -27,7 +22,7 @@ jobs:
2722
uses: "shivammathur/setup-php@v2"
2823
with:
2924
coverage: "none"
30-
php-version: "${{ matrix.php-version }}"
25+
php-version: "8.2"
3126

3227
- name: "Enforce using stable dependencies"
3328
run: "composer config minimum-stability stable"

ConnectionFactory.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ public function createConnection(array $params, ?Configuration $config = null, ?
7878
}
7979

8080
$overriddenOptions = [];
81+
/** @psalm-suppress InvalidArrayOffset We should adjust when https://github.com/vimeo/psalm/issues/8984 is fixed */
8182
if (isset($params['connection_override_options'])) {
8283
trigger_deprecation('doctrine/doctrine-bundle', '2.4', 'The "connection_override_options" connection parameter is deprecated');
8384
$overriddenOptions = $params['connection_override_options'];
@@ -97,6 +98,7 @@ public function createConnection(array $params, ?Configuration $config = null, ?
9798
}
9899
}
99100

101+
/** @psalm-suppress InvalidArrayOffset We should adjust when https://github.com/vimeo/psalm/issues/8984 is fixed */
100102
if (! isset($params['pdo']) && (! isset($params['charset']) || $overriddenOptions || isset($params['dbname_suffix']))) {
101103
$wrapperClass = null;
102104

DataCollector/DoctrineDataCollector.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
* regions: array<"puts"|"hits"|"misses", array<string, int>>,
4242
* },
4343
* connections: list<string>,
44-
* entities: array<string, array<class-string, class-string>>,
44+
* entities: array<string, array<class-string, array{class: class-string, file: false|string, line: false|int}>>,
4545
* errors: array<string, array<class-string, list<string>>>,
4646
* managers: list<string>,
4747
* queries: array<string, list<QueryType>>,
@@ -55,7 +55,7 @@ class DoctrineDataCollector extends BaseCollector
5555

5656
/**
5757
* @var mixed[][]|null
58-
* @psalm-var ?array<string, list<QueryType&array{count: int, index: int, executionPercent: float}>>
58+
* @psalm-var ?array<string, list<QueryType&array{count: int, index: int, executionPercent?: float}>>
5959
*/
6060
private ?array $groupedQueries = null;
6161

@@ -184,7 +184,7 @@ public function collect(Request $request, Response $response, ?Throwable $except
184184
$this->groupedQueries = null;
185185
}
186186

187-
/** @return array<string, array<string, string>> */
187+
/** @return array<string, array<class-string, array{class: class-string, file: false|string, line: false|int}>> */
188188
public function getEntities()
189189
{
190190
return $this->data['entities'];
@@ -243,7 +243,7 @@ public function getInvalidEntityCount()
243243

244244
/**
245245
* @return string[][]
246-
* @psalm-return array<string, list<QueryType&array{count: int, index: int, executionPercent: float}>>
246+
* @psalm-return array<string, list<QueryType&array{count: int, index: int, executionPercent?: float}>>
247247
*/
248248
public function getGroupedQueries()
249249
{

DependencyInjection/Compiler/EntityListenerPass.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public function process(ContainerBuilder $container)
9494
}
9595
}
9696

97-
/** @param array{entity: class-string, event?: ?string} $attributes */
97+
/** @param array{entity: class-string, event?: ?string, method?: string} $attributes */
9898
private function attachToListener(ContainerBuilder $container, string $name, string $class, array $attributes): void
9999
{
100100
$listenerId = sprintf('doctrine.orm.%s_listeners.attach_entity_listeners', $name);

DependencyInjection/DoctrineExtension.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ protected function dbalLoad(array $config, ContainerBuilder $container)
181181
$connections = [];
182182

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

@@ -533,6 +534,7 @@ protected function ormLoad(array $config, ContainerBuilder $container)
533534

534535
$entityManagers = [];
535536
foreach (array_keys($config['entity_managers']) as $name) {
537+
/** @psalm-suppress InvalidArrayOffset */
536538
$entityManagers[$name] = sprintf('doctrine.orm.%s_entity_manager', $name);
537539
}
538540

@@ -547,7 +549,6 @@ protected function ormLoad(array $config, ContainerBuilder $container)
547549

548550
if ($config['enable_lazy_ghost_objects'] ?? false) {
549551
// available in Symfony 6.2 and higher
550-
/** @psalm-suppress UndefinedClass */
551552
if (! trait_exists(LazyGhostTrait::class)) {
552553
throw new LogicException(
553554
'Lazy ghost objects cannot be enabled because the "symfony/var-exporter" library'
@@ -838,10 +839,12 @@ protected function loadOrmEntityManagerMappingInformation(array $entityManager,
838839
$this->registerMappingDrivers($entityManager, $container);
839840

840841
$container->getDefinition($this->getObjectManagerElementName($entityManager['name'] . '_metadata_driver'));
842+
/** @psalm-suppress NoValue $this->drivers is set by $this->loadMappingInformation() call */
841843
foreach (array_keys($this->drivers) as $driverType) {
842844
$mappingService = $this->getObjectManagerElementName($entityManager['name'] . '_' . $driverType . '_metadata_driver');
843845
$mappingDriverDef = $container->getDefinition($mappingService);
844846
$args = $mappingDriverDef->getArguments();
847+
/** @psalm-suppress TypeDoesNotContainType $this->drivers is set by $this->loadMappingInformation() call */
845848
if ($driverType === 'annotation') {
846849
$args[2] = $entityManager['report_fields_where_declared'];
847850
} elseif ($driverType === 'attribute') {

DoctrineBundle.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ public function boot()
9797

9898
if ($this->container->getParameter('doctrine.orm.auto_generate_proxy_classes')) {
9999
// See https://github.com/symfony/symfony/pull/3419 for usage of references
100+
/** @psalm-suppress UnsupportedPropertyReferenceUsage */
100101
$container = &$this->container;
101102

102103
$proxyGenerator = static function ($proxyDir, $proxyNamespace, $class) use (&$container): void {

Mapping/DisconnectedMetadataFactory.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,12 @@ public function findNamespaceAndPathForMetadata(ClassMetadataCollection $metadat
117117
$ns = $r->getNamespaceName();
118118
} elseif ($path) {
119119
// Get namespace by removing the last component of the FQCN
120+
/** @psalm-suppress NoValue */
120121
$nsParts = explode('\\', $all[0]->name);
121122
array_pop($nsParts);
122123
$ns = implode('\\', $nsParts);
123124
} else {
125+
/** @psalm-suppress NoValue */
124126
throw new RuntimeException(sprintf('Unable to determine where to save the "%s" class (use the --path option).', $all[0]->name));
125127
}
126128

Repository/ServiceEntityRepositoryProxy.php

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,25 +41,35 @@ public function __construct(
4141
$this->repository = $this->resolveRepository();
4242
}
4343

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

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

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

62-
/** {@inheritDoc} */
66+
/**
67+
* {@inheritDoc}
68+
*
69+
* @psalm-suppress InvalidReturnStatement This proxy is used only in combination with newer parent class
70+
* @psalm-suppress MethodSignatureMismatch This proxy is used only in combination with newer parent class
71+
* @psalm-suppress InvalidReturnType This proxy is used only in combination with newer parent class
72+
*/
6373
public function findBy(array $criteria, ?array $orderBy = null, ?int $limit = null, ?int $offset = null): array
6474
{
6575
return ($this->repository ??= $this->resolveRepository())
@@ -69,6 +79,7 @@ public function findBy(array $criteria, ?array $orderBy = null, ?int $limit = nu
6979
/** {@inheritDoc} */
7080
public function findOneBy(array $criteria, ?array $orderBy = null): object|null
7181
{
82+
/** @psalm-suppress InvalidReturnStatement This proxy is used only in combination with newer parent class */
7283
return ($this->repository ??= $this->resolveRepository())
7384
->findOneBy($criteria, $orderBy);
7485
}
@@ -79,7 +90,11 @@ public function count(array $criteria = []): int
7990
return ($this->repository ??= $this->resolveRepository())->count($criteria);
8091
}
8192

82-
/** {@inheritDoc} */
93+
/**
94+
* {@inheritDoc}
95+
*
96+
* @psalm-suppress MethodSignatureMismatch This proxy is used only in combination with newer parent class
97+
*/
8398
public function __call(string $method, array $arguments): mixed
8499
{
85100
return ($this->repository ??= $this->resolveRepository())->$method(...$arguments);
@@ -95,8 +110,10 @@ protected function getEntityManager(): EntityManagerInterface
95110
return ($this->repository ??= $this->resolveRepository())->getEntityManager();
96111
}
97112

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

Tests/CacheSchemaSubscriberTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,13 @@ public function getSchemaSubscribers(): Generator
9595
{
9696
/**
9797
* available in Symfony 6.3
98-
*
99-
* @psalm-suppress UndefinedClass
10098
*/
10199
yield ['cache.adapter.doctrine_dbal', 'doctrine.orm.listeners.doctrine_dbal_cache_adapter_schema_listener', DoctrineDbalCacheAdapterSchemaListener::class];
102100

103101
/**
104102
* available in Symfony 5.1 and up to Symfony 5.4 (deprecated)
103+
*
104+
* @psalm-suppress UndefinedClass
105105
*/
106106
yield ['cache.adapter.pdo', 'doctrine.orm.listeners.pdo_cache_adapter_doctrine_schema_subscriber', PdoCacheAdapterDoctrineSchemaSubscriber::class];
107107
}

Tests/Command/CreateDatabaseDoctrineTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ private function getMockContainer(string $connectionName, ?array $params = null)
8686
->willReturn($mockConnection);
8787

8888
$mockContainer = $this->getMockBuilder(Container::class)
89-
->setMethods(['get'])
89+
->onlyMethods(['get'])
9090
->getMock();
9191

9292
$mockContainer->expects($this->any())

0 commit comments

Comments
 (0)