Skip to content

Commit

Permalink
psalm 4.x -> 5.x (#1728)
Browse files Browse the repository at this point in the history
  • Loading branch information
ostrolucky committed Nov 18, 2023
1 parent 4089f14 commit ecfd2b3
Show file tree
Hide file tree
Showing 28 changed files with 113 additions and 164 deletions.
7 changes: 1 addition & 6 deletions .github/workflows/static-analysis.yml
Expand Up @@ -14,11 +14,6 @@ jobs:
name: "Static Analysis with Psalm"
runs-on: "ubuntu-22.04"

strategy:
matrix:
php-version:
- "7.4"

steps:
- name: "Checkout code"
uses: "actions/checkout@v4"
Expand All @@ -27,7 +22,7 @@ jobs:
uses: "shivammathur/setup-php@v2"
with:
coverage: "none"
php-version: "${{ matrix.php-version }}"
php-version: "8.2"

- name: "Enforce using stable dependencies"
run: "composer config minimum-stability stable"
Expand Down
2 changes: 2 additions & 0 deletions ConnectionFactory.php
Expand Up @@ -78,6 +78,7 @@ public function createConnection(array $params, ?Configuration $config = null, ?
}

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

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

Expand Down
8 changes: 4 additions & 4 deletions DataCollector/DoctrineDataCollector.php
Expand Up @@ -41,7 +41,7 @@
* regions: array<"puts"|"hits"|"misses", array<string, int>>,
* },
* connections: list<string>,
* entities: array<string, array<class-string, class-string>>,
* entities: array<string, array<class-string, array{class: class-string, file: false|string, line: false|int}>>,
* errors: array<string, array<class-string, list<string>>>,
* managers: list<string>,
* queries: array<string, list<QueryType>>,
Expand All @@ -55,7 +55,7 @@ class DoctrineDataCollector extends BaseCollector

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

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

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

/**
* @return string[][]
* @psalm-return array<string, list<QueryType&array{count: int, index: int, executionPercent: float}>>
* @psalm-return array<string, list<QueryType&array{count: int, index: int, executionPercent?: float}>>
*/
public function getGroupedQueries()
{
Expand Down
2 changes: 1 addition & 1 deletion DependencyInjection/Compiler/EntityListenerPass.php
Expand Up @@ -94,7 +94,7 @@ public function process(ContainerBuilder $container)
}
}

/** @param array{entity: class-string, event?: ?string} $attributes */
/** @param array{entity: class-string, event?: ?string, method?: string} $attributes */
private function attachToListener(ContainerBuilder $container, string $name, string $class, array $attributes): void
{
$listenerId = sprintf('doctrine.orm.%s_listeners.attach_entity_listeners', $name);
Expand Down
5 changes: 4 additions & 1 deletion DependencyInjection/DoctrineExtension.php
Expand Up @@ -181,6 +181,7 @@ protected function dbalLoad(array $config, ContainerBuilder $container)
$connections = [];

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

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

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

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

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

$container->getDefinition($this->getObjectManagerElementName($entityManager['name'] . '_metadata_driver'));
/** @psalm-suppress NoValue $this->drivers is set by $this->loadMappingInformation() call */
foreach (array_keys($this->drivers) as $driverType) {
$mappingService = $this->getObjectManagerElementName($entityManager['name'] . '_' . $driverType . '_metadata_driver');
$mappingDriverDef = $container->getDefinition($mappingService);
$args = $mappingDriverDef->getArguments();
/** @psalm-suppress TypeDoesNotContainType $this->drivers is set by $this->loadMappingInformation() call */
if ($driverType === 'annotation') {
$args[2] = $entityManager['report_fields_where_declared'];
} elseif ($driverType === 'attribute') {
Expand Down
1 change: 1 addition & 0 deletions DoctrineBundle.php
Expand Up @@ -97,6 +97,7 @@ public function boot()

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

$proxyGenerator = static function ($proxyDir, $proxyNamespace, $class) use (&$container): void {
Expand Down
2 changes: 2 additions & 0 deletions Mapping/DisconnectedMetadataFactory.php
Expand Up @@ -117,10 +117,12 @@ public function findNamespaceAndPathForMetadata(ClassMetadataCollection $metadat
$ns = $r->getNamespaceName();
} elseif ($path) {
// Get namespace by removing the last component of the FQCN
/** @psalm-suppress NoValue */
$nsParts = explode('\\', $all[0]->name);
array_pop($nsParts);
$ns = implode('\\', $nsParts);
} else {
/** @psalm-suppress NoValue */
throw new RuntimeException(sprintf('Unable to determine where to save the "%s" class (use the --path option).', $all[0]->name));
}

Expand Down
21 changes: 19 additions & 2 deletions Repository/ServiceEntityRepositoryProxy.php
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
4 changes: 2 additions & 2 deletions Tests/CacheSchemaSubscriberTest.php
Expand Up @@ -95,13 +95,13 @@ public function getSchemaSubscribers(): Generator
{
/**
* available in Symfony 6.3
*
* @psalm-suppress UndefinedClass
*/
yield ['cache.adapter.doctrine_dbal', 'doctrine.orm.listeners.doctrine_dbal_cache_adapter_schema_listener', DoctrineDbalCacheAdapterSchemaListener::class];

/**
* 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
2 changes: 1 addition & 1 deletion Tests/Command/CreateDatabaseDoctrineTest.php
Expand Up @@ -86,7 +86,7 @@ private function getMockContainer(string $connectionName, ?array $params = null)
->willReturn($mockConnection);

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

$mockContainer->expects($this->any())
Expand Down
2 changes: 1 addition & 1 deletion Tests/Command/DropDatabaseDoctrineTest.php
Expand Up @@ -168,7 +168,7 @@ private function getMockContainer(string $connectionName, array $params): MockOb
->willReturn($mockConnection);

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

$mockContainer->expects($this->any())
Expand Down
3 changes: 3 additions & 0 deletions Tests/ConnectionFactoryTest.php
Expand Up @@ -96,6 +96,7 @@ public function testConnectionOverrideOptions(): void
'password' => 'wordpass',
];

/** @psalm-suppress InvalidArgument We should adjust when https://github.com/vimeo/psalm/issues/8984 is fixed */
$connection = (new ConnectionFactory([]))->createConnection(
[
'url' => 'mysql://root:password@database:3306/main?serverVersion=mariadb-10.5.8',
Expand All @@ -119,6 +120,7 @@ public function testConnectionCharsetFromUrl()

public function testDbnameSuffix(): void
{
/** @psalm-suppress InvalidArgument We should adjust when https://github.com/vimeo/psalm/issues/8984 is fixed */
$connection = (new ConnectionFactory([]))->createConnection(
[
'url' => 'mysql://root:password@database:3306/main?serverVersion=mariadb-10.5.8',
Expand All @@ -132,6 +134,7 @@ public function testDbnameSuffix(): void

public function testDbnameSuffixForReplicas(): void
{
/** @psalm-suppress InvalidArgument We should adjust when https://github.com/vimeo/psalm/issues/8984 is fixed */
$connection = (new ConnectionFactory([]))->createConnection(
[
'driver' => 'pdo_mysql',
Expand Down

0 comments on commit ecfd2b3

Please sign in to comment.