Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

psalm 4.x -> 5.x #1728

Merged
merged 3 commits into from
Nov 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 1 addition & 6 deletions .github/workflows/static-analysis.yml
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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}>>
ostrolucky marked this conversation as resolved.
Show resolved Hide resolved
* @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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
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
4 changes: 2 additions & 2 deletions Tests/CacheSchemaSubscriberTest.php
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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