Skip to content

Commit

Permalink
Drop Psalm in favor of PHPStan
Browse files Browse the repository at this point in the history
As per the decision we made during the hackathon.
I have left many psalm-suppress annotations that seem informative in the
codebase.
  • Loading branch information
greg0ire committed Jan 13, 2025
1 parent fc8dc01 commit 6890eaa
Show file tree
Hide file tree
Showing 19 changed files with 1,640 additions and 131 deletions.
3 changes: 2 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
.gitignore export-ignore
phpunit.xml.dist export-ignore
phpcs.xml.dist export-ignore
psalm.xml.dist export-ignore
phpstan-baseline.neon export-ignore
phpstan.neon.dist export-ignore
/docs export-ignore
/tests export-ignore
.symfony.bundle.yaml export-ignore
25 changes: 3 additions & 22 deletions .github/workflows/static-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,6 @@ on:
- "*.x"

jobs:
static-analysis-psalm:
name: "Static Analysis with Psalm"
runs-on: "ubuntu-latest"

steps:
- name: "Checkout code"
uses: "actions/checkout@v4"

- name: "Install PHP"
uses: "shivammathur/setup-php@v2"
with:
coverage: "none"
php-version: "8.2"

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

- name: "Install dependencies with Composer"
uses: "ramsey/composer-install@v3"

- name: "Run a static analysis with vimeo/psalm"
run: "vendor/bin/psalm --show-info=false --stats --output-format=github --find-unused-psalm-suppress"
static-analysis:
name: "Static Analysis"
uses: "doctrine/.github/.github/workflows/[email protected]"
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,10 @@
"doctrine/deprecations": "^1.0",
"doctrine/orm": "^2.17 || ^3.0",
"friendsofphp/proxy-manager-lts": "^1.0",
"phpstan/phpstan": "2.1.1",
"phpstan/phpstan-phpunit": "2.0.3",
"phpstan/phpstan-strict-rules": "^2",
"phpunit/phpunit": "^9.5.26",
"psalm/plugin-phpunit": "^0.18.4",
"psalm/plugin-symfony": "^5",
"psr/log": "^1.1.4 || ^2.0 || ^3.0",
"symfony/phpunit-bridge": "^6.1 || ^7.0",
"symfony/property-info": "^5.4 || ^6.0 || ^7.0",
Expand All @@ -65,8 +66,7 @@
"symfony/var-exporter": "^5.4 || ^6.2 || ^7.0",
"symfony/web-profiler-bundle": "^5.4 || ^6.0 || ^7.0",
"symfony/yaml": "^5.4 || ^6.0 || ^7.0",
"twig/twig": "^1.34 || ^2.12 || ^3.0",
"vimeo/psalm": "^5.15"
"twig/twig": "^1.34 || ^2.12 || ^3.0"
},
"conflict": {
"doctrine/annotations": ">=3.0",
Expand Down
1,603 changes: 1,603 additions & 0 deletions phpstan-baseline.neon

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
parameters:
level: 8
phpVersion: 80402
paths:
- src
- tests

excludePaths:
- src/Command/Proxy/ConvertMappingDoctrineCommand.php
- src/Command/Proxy/EnsureProductionSettingsDoctrineCommand.php

includes:
- phpstan-baseline.neon
66 changes: 0 additions & 66 deletions psalm.xml.dist

This file was deleted.

8 changes: 4 additions & 4 deletions src/ConnectionFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

use const PHP_EOL;

/** @psalm-import-type Params from DriverManager */
/** @phpstan-import-type Params from DriverManager */
class ConnectionFactory
{
/** @internal */
Expand Down Expand Up @@ -63,7 +63,7 @@ public function __construct(array $typesConfig, ?DsnParser $dsnParser = null)
*
* @param mixed[] $params
* @param array<string, string> $mappingTypes
* @psalm-param Params $params
* @phpstan-param Params $params
*
* @return Connection
*/
Expand Down Expand Up @@ -244,11 +244,11 @@ private function addDatabaseSuffix(array $params): array
* updated list of parameters.
*
* @param mixed[] $params The list of parameters.
* @psalm-param Params $params
* @phpstan-param Params $params
*
* @return mixed[] A modified list of parameters with info from a database
* URL extracted into individual parameter parts.
* @psalm-return Params
* @phpstan-return Params
*
* @throws DBALException
*/
Expand Down
10 changes: 5 additions & 5 deletions src/DataCollector/DoctrineDataCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@
use function usort;

/**
* @psalm-type QueryType = array{
* @phpstan-type QueryType = array{
* executionMS: float,
* explainable: bool,
* sql: string,
* params: ?array<array-key, mixed>,
* runnable: bool,
* types: ?array<array-key, Type|int|string|null>,
* }
* @psalm-type DataType = array{
* @phpstan-type DataType = array{
* caches: array{
* enabled: bool,
* counts: array<"puts"|"hits"|"misses", int>,
Expand All @@ -54,7 +54,7 @@ class DoctrineDataCollector extends BaseCollector

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

Expand Down Expand Up @@ -216,7 +216,7 @@ public function getCacheEnabled()

/**
* @return array<string, array<string, int>>
* @psalm-return array<"puts"|"hits"|"misses", array<string, int>>
* @phpstan-return array<"puts"|"hits"|"misses", array<string, int>>
*/
public function getCacheRegions()
{
Expand All @@ -237,7 +237,7 @@ public function getInvalidEntityCount()

/**
* @return string[][]
* @psalm-return array<string, list<QueryType&array{count: int, index: int, executionPercent?: float}>>
* @phpstan-return array<string, list<QueryType&array{count: int, index: int, executionPercent?: float}>>
*/
public function getGroupedQueries()
{
Expand Down
3 changes: 1 addition & 2 deletions src/DependencyInjection/DoctrineExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
* DoctrineExtension is an extension for the Doctrine DBAL and ORM library.
*
* @final since 2.9
* @psalm-type DBALConfig = array{
* @phpstan-type DBALConfig = array{
* connections: array<string, array{logging: bool, profiling: bool, profiling_collect_backtrace: bool, idle_connection_ttl: int}>,
* driver_schemes: array<string, string>,
* default_connection: string,
Expand Down Expand Up @@ -579,7 +579,6 @@ 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 Down
1 change: 0 additions & 1 deletion src/Middleware/BacktraceDebugDataHolder.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

use const DEBUG_BACKTRACE_IGNORE_ARGS;

/** @psalm-suppress MissingDependency */
class BacktraceDebugDataHolder extends DebugDataHolder
{
/** @var string[] */
Expand Down
1 change: 0 additions & 1 deletion src/Middleware/DebugMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ public function setConnectionName(string $name): void

public function wrap(DriverInterface $driver): DriverInterface
{
/** @psalm-suppress InternalClass,InternalMethod */
return new Driver($driver, $this->debugDataHolder, $this->stopwatch, $this->connectionName);
}
}
8 changes: 4 additions & 4 deletions src/Repository/ContainerRepositoryFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function __construct(ContainerInterface $container)
* @param class-string<T> $entityName
*
* @return ObjectRepository<T>
* @psalm-return ($strictTypeCheck is true ? EntityRepository<T> : ObjectRepository<T>)
* @phpstan-return ($strictTypeCheck is true ? EntityRepository<T> : ObjectRepository<T>)
*
* @template T of object
*/
Expand All @@ -67,7 +67,7 @@ private function doGetRepository(EntityManagerInterface $entityManager, string $
trigger_deprecation('doctrine/doctrine-bundle', '2.11', 'The service "%s" of type "%s" should extend "%s", not doing so is deprecated.', $repositoryServiceId, get_debug_type($repository), EntityRepository::class);
}

/** @psalm-var ObjectRepository<T> */
/** @phpstan-var ObjectRepository<T> */
return $repository;
}

Expand Down Expand Up @@ -99,13 +99,13 @@ private function getOrCreateRepository(
): ObjectRepository {
$repositoryHash = $metadata->getName() . spl_object_hash($entityManager);
if (isset($this->managedRepositories[$repositoryHash])) {
/** @psalm-var ObjectRepository<TEntity> */
/** @phpstan-var ObjectRepository<TEntity> */
return $this->managedRepositories[$repositoryHash];
}

$repositoryClassName = $metadata->customRepositoryClassName ?: $entityManager->getConfiguration()->getDefaultRepositoryClassName();

/** @psalm-var ObjectRepository<TEntity> */
/** @phpstan-var ObjectRepository<TEntity> */
return $this->managedRepositories[$repositoryHash] = new $repositoryClassName($entityManager, $metadata);
}
}
2 changes: 1 addition & 1 deletion src/Repository/LazyServiceEntityRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class LazyServiceEntityRepository extends EntityRepository implements ServiceEnt

/**
* @param string $entityClass The class name of the entity this repository manages
* @psalm-param class-string<T> $entityClass
* @phpstan-param class-string<T> $entityClass
*/
public function __construct(ManagerRegistry $registry, string $entityClass)
{
Expand Down
2 changes: 0 additions & 2 deletions tests/CacheSchemaSubscriberTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,6 @@ 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
Original file line number Diff line number Diff line change
Expand Up @@ -936,7 +936,6 @@ public function testAddCustomHydrationMode(): void
$container = $this->loadContainer('orm_hydration_mode');

$definition = $container->getDefinition('doctrine.orm.default_configuration');
/** @psalm-suppress UndefinedClass */
$this->assertDICDefinitionMethodCallOnce($definition, 'addCustomHydrationMode', ['test_hydrator', TestHydrator::class]);
}

Expand Down
6 changes: 0 additions & 6 deletions tests/Middleware/BacktraceDebugDataHolderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,6 @@
use function sprintf;
use function strpos;

/**
* @psalm-suppress UndefinedClass
* @psalm-suppress MissingDependency
* @psalm-suppress InternalMethod
* @psalm-suppress InternalClass
*/
class BacktraceDebugDataHolderTest extends TestCase
{
protected function setUp(): void
Expand Down
1 change: 0 additions & 1 deletion tests/Middleware/DebugMiddlewareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
use function sprintf;
use function strpos;

/** @psalm-suppress MissingDependency */
class DebugMiddlewareTest extends TestCase
{
protected function setUp(): void
Expand Down
8 changes: 0 additions & 8 deletions tests/ProfilerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,6 @@
use function preg_quote;
use function str_replace;

/**
* @psalm-suppress InternalMethod
* @psalm-suppress InternalClass
*/
class ProfilerTest extends BaseTestCase
{
private DebugDataHolder $debugDataHolder;
Expand Down Expand Up @@ -73,10 +69,6 @@ public function setUp(): void

$this->twig->addExtension(new RoutingExtension($urlGenerator));
$this->twig->addExtension(new HttpKernelExtension());
/**
* @psalm-suppress InternalClass
* @psalm-suppress InternalMethod
*/
$this->twig->addExtension(new WebProfilerExtension());
$this->twig->addExtension(new DoctrineExtension());

Expand Down
2 changes: 0 additions & 2 deletions tests/Repository/ServiceEntityRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ public function testConstructorThrowsExceptionWhenNoManagerFound(): void
$this->expectExceptionMessage(<<<'EXCEPTION'
Could not find the entity manager for class "Doctrine\Bundle\DoctrineBundle\Tests\Repository\TestEntity". Check your Doctrine configuration to make sure it is configured to load this entity’s metadata.
EXCEPTION);
/** @psalm-suppress UndefinedClass */
$repo = new ServiceEntityRepository($registry, TestEntity::class);
$repo->getClassName();
}
Expand All @@ -41,7 +40,6 @@ public function testConstructInitializesWhenImplementingLazyObjectInterface(): v
$registry = $this->getMockBuilder(ManagerRegistry::class)->getMock();
$this->expectException(LogicException::class);

/** @psalm-suppress UndefinedClass */
new class ($registry, TestEntity::class) extends ServiceEntityRepository implements LazyObjectInterface {
use LazyGhostTrait;
};
Expand Down

0 comments on commit 6890eaa

Please sign in to comment.