Skip to content

Commit 9f83e13

Browse files
committed
Cover all directories with our tooling
The goal is to hold new code with higher standards, and to have the same configuration on all branches. Since I have no proof addressing static analysis issues fixes any actual bugs, let us ignore them all on this branch.
1 parent e60395b commit 9f83e13

9 files changed

+110
-43
lines changed

Collector/MigrationsCollector.php

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@
1010
use Symfony\Component\HttpFoundation\Request;
1111
use Symfony\Component\HttpFoundation\Response;
1212
use Symfony\Component\HttpKernel\DataCollector\DataCollector;
13+
use Symfony\Component\VarDumper\Cloner\Data;
14+
use Throwable;
15+
16+
use function count;
17+
use function get_class;
1318

1419
class MigrationsCollector extends DataCollector
1520
{
@@ -21,20 +26,18 @@ class MigrationsCollector extends DataCollector
2126
public function __construct(DependencyFactory $dependencyFactory, MigrationsFlattener $migrationsFlattener)
2227
{
2328
$this->dependencyFactory = $dependencyFactory;
24-
$this->flattener = $migrationsFlattener;
29+
$this->flattener = $migrationsFlattener;
2530
}
2631

27-
/**
28-
* @return void
29-
*/
30-
public function collect(Request $request, Response $response, \Throwable $exception = null)
32+
/** @return void */
33+
public function collect(Request $request, Response $response, ?Throwable $exception = null)
3134
{
32-
if (!empty($this->data)) {
35+
if (! empty($this->data)) {
3336
return;
3437
}
3538

3639
$metadataStorage = $this->dependencyFactory->getMetadataStorage();
37-
$planCalculator = $this->dependencyFactory->getMigrationPlanCalculator();
40+
$planCalculator = $this->dependencyFactory->getMigrationPlanCalculator();
3841

3942
try {
4043
$executedMigrations = $metadataStorage->getExecutedMigrations();
@@ -49,45 +52,42 @@ public function collect(Request $request, Response $response, \Throwable $except
4952

5053
$availableMigrations = $planCalculator->getMigrations();
5154

52-
$this->data['available_migrations_count'] = count($availableMigrations);
53-
$unavailableMigrations = $executedMigrations->unavailableSubset($availableMigrations);
55+
$this->data['available_migrations_count'] = count($availableMigrations);
56+
$unavailableMigrations = $executedMigrations->unavailableSubset($availableMigrations);
5457
$this->data['unavailable_migrations_count'] = count($unavailableMigrations);
5558

56-
$newMigrations = $availableMigrations->newSubset($executedMigrations);
57-
$this->data['new_migrations'] = $this->flattener->flattenAvailableMigrations($newMigrations);
59+
$newMigrations = $availableMigrations->newSubset($executedMigrations);
60+
$this->data['new_migrations'] = $this->flattener->flattenAvailableMigrations($newMigrations);
5861
$this->data['executed_migrations'] = $this->flattener->flattenExecutedMigrations($executedMigrations, $availableMigrations);
5962

6063
$this->data['storage'] = get_class($metadataStorage);
61-
$configuration = $this->dependencyFactory->getConfiguration();
62-
$storage = $configuration->getMetadataStorageConfiguration();
64+
$configuration = $this->dependencyFactory->getConfiguration();
65+
$storage = $configuration->getMetadataStorageConfiguration();
6366
if ($storage instanceof TableMetadataStorageConfiguration) {
64-
$this->data['table'] = $storage->getTableName();
67+
$this->data['table'] = $storage->getTableName();
6568
$this->data['column'] = $storage->getVersionColumnName();
6669
}
6770

68-
$connection = $this->dependencyFactory->getConnection();
71+
$connection = $this->dependencyFactory->getConnection();
6972
$this->data['driver'] = get_class($connection->getDriver());
70-
$this->data['name'] = $connection->getDatabase();
73+
$this->data['name'] = $connection->getDatabase();
7174

7275
$this->data['namespaces'] = $configuration->getMigrationDirectories();
7376
}
7477

75-
/**
76-
* @return string
77-
*/
78+
/** @return string */
7879
public function getName()
7980
{
8081
return 'doctrine_migrations';
8182
}
8283

84+
/** @return array<string, mixed>|Data */
8385
public function getData()
8486
{
8587
return $this->data;
8688
}
8789

88-
/**
89-
* @return void
90-
*/
90+
/** @return void */
9191
public function reset()
9292
{
9393
$this->data = [];

Collector/MigrationsFlattener.php

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,44 +4,69 @@
44

55
namespace Doctrine\Bundle\MigrationsBundle\Collector;
66

7+
use DateTimeImmutable;
78
use Doctrine\Migrations\Metadata\AvailableMigration;
89
use Doctrine\Migrations\Metadata\AvailableMigrationsList;
910
use Doctrine\Migrations\Metadata\ExecutedMigration;
1011
use Doctrine\Migrations\Metadata\ExecutedMigrationsList;
12+
use ReflectionClass;
13+
14+
use function array_map;
1115

1216
class MigrationsFlattener
1317
{
18+
/**
19+
* @return array{
20+
* version: string,
21+
* is_new: true,
22+
* is_unavailable: bool,
23+
* description: string,
24+
* executed_at: null,
25+
* execution_time: null,
26+
* file: string|false,
27+
* }[]
28+
*/
1429
public function flattenAvailableMigrations(AvailableMigrationsList $migrationsList): array
1530
{
1631
return array_map(static function (AvailableMigration $migration) {
1732
return [
18-
'version' => (string)$migration->getVersion(),
33+
'version' => (string) $migration->getVersion(),
1934
'is_new' => true,
2035
'is_unavailable' => false,
2136
'description' => $migration->getMigration()->getDescription(),
2237
'executed_at' => null,
2338
'execution_time' => null,
24-
'file' => (new \ReflectionClass($migration->getMigration()))->getFileName(),
39+
'file' => (new ReflectionClass($migration->getMigration()))->getFileName(),
2540
];
2641
}, $migrationsList->getItems());
2742
}
2843

44+
/**
45+
* @return array{
46+
* version: string,
47+
* is_new: false,
48+
* is_unavailable: bool,
49+
* description: string|null,
50+
* executed_at: DateTimeImmutable|null,
51+
* execution_time: float|null,
52+
* file: string|false|null,
53+
* }[]
54+
*/
2955
public function flattenExecutedMigrations(ExecutedMigrationsList $migrationsList, AvailableMigrationsList $availableMigrations): array
3056
{
3157
return array_map(static function (ExecutedMigration $migration) use ($availableMigrations) {
32-
3358
$availableMigration = $availableMigrations->hasMigration($migration->getVersion())
3459
? $availableMigrations->getMigration($migration->getVersion())->getMigration()
3560
: null;
3661

3762
return [
38-
'version' => (string)$migration->getVersion(),
63+
'version' => (string) $migration->getVersion(),
3964
'is_new' => false,
40-
'is_unavailable' => !$availableMigration,
65+
'is_unavailable' => ! $availableMigration,
4166
'description' => $availableMigration ? $availableMigration->getDescription() : null,
4267
'executed_at' => $migration->getExecutedAt(),
4368
'execution_time' => $migration->getExecutionTime(),
44-
'file' => $availableMigration ? (new \ReflectionClass($availableMigration))->getFileName() : null,
69+
'file' => $availableMigration ? (new ReflectionClass($availableMigration))->getFileName() : null,
4570
];
4671
}, $migrationsList->getItems());
4772
}

DoctrineMigrationsBundle.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace Doctrine\Bundle\MigrationsBundle;
46

57
use Doctrine\Bundle\MigrationsBundle\DependencyInjection\CompilerPass\ConfigureDependencyFactoryPass;
@@ -8,15 +10,12 @@
810

911
/**
1012
* Bundle.
11-
*
12-
* @author Fabien Potencier <[email protected]>
13-
* @author Jonathan H. Wage <[email protected]>
1413
*/
1514
class DoctrineMigrationsBundle extends Bundle
1615
{
1716
/** @return void */
1817
public function build(ContainerBuilder $container)
1918
{
20-
$container->addCompilerPass(new ConfigureDependencyFactoryPass());
19+
$container->addCompilerPass(new ConfigureDependencyFactoryPass());
2120
}
2221
}

MigrationsFactory/ContainerAwareMigrationFactory.php

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,20 @@
99
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
1010
use Symfony\Component\DependencyInjection\ContainerInterface;
1111

12-
/**
13-
* @deprecated This class is not compatible with Symfony >= 7
14-
*/
12+
use function trigger_deprecation;
13+
14+
/** @deprecated This class is not compatible with Symfony >= 7 */
1515
class ContainerAwareMigrationFactory implements MigrationFactory
1616
{
17-
/**
18-
* @var ContainerInterface
19-
*/
17+
/** @var ContainerInterface */
2018
private $container;
2119

22-
/**
23-
* @var MigrationFactory
24-
*/
20+
/** @var MigrationFactory */
2521
private $migrationFactory;
2622

2723
public function __construct(MigrationFactory $migrationFactory, ContainerInterface $container)
2824
{
29-
$this->container = $container;
25+
$this->container = $container;
3026
$this->migrationFactory = $migrationFactory;
3127
}
3228

phpcs.xml.dist

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,19 @@
1111

1212
<config name="php_version" value="70200"/>
1313

14+
<file>Collector</file>
15+
<file>MigrationsFactory</file>
16+
<file>DoctrineMigrationsBundle.php</file>
1417
<file>DependencyInjection</file>
1518
<file>Tests</file>
1619

1720
<exclude-pattern>Tests/Fixtures/CustomEntityManager.php</exclude-pattern>
1821

19-
<rule ref="Doctrine"/>
22+
<rule ref="Doctrine">
23+
<exclude name="SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint" />
24+
<exclude name="SlevomatCodingStandard.TypeHints.ReturnTypeHint.MissingNativeTypeHint" />
25+
<exclude name="SlevomatCodingStandard.TypeHints.PropertyTypeHint.MissingNativeTypeHint" />
26+
</rule>
2027

2128
<!-- Disable the rules that will require PHP 7.4 -->
2229
<rule ref="SlevomatCodingStandard.TypeHints.PropertyTypeHint">

phpstan-baseline.neon

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
parameters:
2+
ignoreErrors:
3+
-
4+
message: "#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#"
5+
count: 1
6+
path: Collector/MigrationsCollector.php
7+
8+
-
9+
message: "#^Only booleans are allowed in a negated boolean, Doctrine\\\\Migrations\\\\AbstractMigration\\|null given\\.$#"
10+
count: 1
11+
path: Collector/MigrationsFlattener.php
12+
13+
-
14+
message: "#^Only booleans are allowed in a ternary operator condition, Doctrine\\\\Migrations\\\\AbstractMigration\\|null given\\.$#"
15+
count: 2
16+
path: Collector/MigrationsFlattener.php
17+
18+
-
19+
message: "#^Call to method setContainer\\(\\) on an unknown class Symfony\\\\Component\\\\DependencyInjection\\\\ContainerAwareInterface\\.$#"
20+
count: 1
21+
path: MigrationsFactory/ContainerAwareMigrationFactory.php
22+
23+
-
24+
message: "#^Class Symfony\\\\Component\\\\DependencyInjection\\\\ContainerAwareInterface not found\\.$#"
25+
count: 2
26+
path: MigrationsFactory/ContainerAwareMigrationFactory.php

phpstan.neon.dist

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ parameters:
22
level: 7
33
phpVersion: 80200
44
paths:
5+
- Collector
56
- DependencyInjection
7+
- DoctrineMigrationsBundle.php
8+
- MigrationsFactory
69
- Tests
710

811
excludePaths:
@@ -13,6 +16,7 @@ parameters:
1316
- '~Parameter \#1 \$configs.*DoctrineMigrationsExtension::load.*~'
1417

1518
includes:
19+
- phpstan-baseline.neon
1620
- vendor/phpstan/phpstan-strict-rules/rules.neon
1721
- vendor/phpstan/phpstan-phpunit/extension.neon
1822
- vendor/phpstan/phpstan-phpunit/rules.neon

psalm-baseline.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@
1010
<code><![CDATA[$configs]]></code>
1111
</MoreSpecificImplementedParamType>
1212
</file>
13+
<file src="MigrationsFactory/ContainerAwareMigrationFactory.php">
14+
<ContainerDependency>
15+
<code><![CDATA[ContainerInterface $container]]></code>
16+
</ContainerDependency>
17+
<UndefinedClass>
18+
<code><![CDATA[ContainerAwareInterface]]></code>
19+
</UndefinedClass>
20+
</file>
1321
<file src="Tests/Fixtures/Migrations/ContainerAwareMigration.php">
1422
<UndefinedClass>
1523
<code><![CDATA[ContainerAwareInterface]]></code>

psalm.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
errorBaseline="psalm-baseline.xml"
1111
>
1212
<projectFiles>
13+
<directory name="Collector" />
1314
<directory name="DependencyInjection" />
15+
<directory name="MigrationsFactory" />
1416
<directory name="Tests" />
1517
<file name="DoctrineMigrationsBundle.php" />
1618
<ignoreFiles>

0 commit comments

Comments
 (0)