Skip to content

Commit

Permalink
Merge pull request #577 from derrabus/chore/php-8
Browse files Browse the repository at this point in the history
Modernize code
  • Loading branch information
greg0ire authored Jan 13, 2025
2 parents b9d29ea + d3bf45d commit 9b12705
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 38 deletions.
4 changes: 2 additions & 2 deletions src/Collector/MigrationsCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
class MigrationsCollector extends DataCollector
{
public function __construct(
private DependencyFactory $dependencyFactory,
private MigrationsFlattener $flattener,
private readonly DependencyFactory $dependencyFactory,
private readonly MigrationsFlattener $flattener,
) {
}

Expand Down
20 changes: 9 additions & 11 deletions src/Collector/MigrationsFlattener.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,15 @@ class MigrationsFlattener
*/
public function flattenAvailableMigrations(AvailableMigrationsList $migrationsList): array
{
return array_map(static function (AvailableMigration $migration) {
return [
'version' => (string) $migration->getVersion(),
'is_new' => true,
'is_unavailable' => false,
'description' => $migration->getMigration()->getDescription(),
'executed_at' => null,
'execution_time' => null,
'file' => (new ReflectionClass($migration->getMigration()))->getFileName(),
];
}, $migrationsList->getItems());
return array_map(static fn (AvailableMigration $migration) => [
'version' => (string) $migration->getVersion(),
'is_new' => true,
'is_unavailable' => false,
'description' => $migration->getMigration()->getDescription(),
'executed_at' => null,
'execution_time' => null,
'file' => (new ReflectionClass($migration->getMigration()))->getFileName(),
], $migrationsList->getItems());
}

/**
Expand Down
26 changes: 11 additions & 15 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
use function count;
use function in_array;
use function is_string;
use function str_starts_with;
use function strlen;
use function strpos;
use function strtoupper;
use function substr;

Expand Down Expand Up @@ -45,11 +45,10 @@ public function getConfigTreeBuilder(): TreeBuilder
->useAttributeAsKey('service')
->defaultValue([])
->validate()
->ifTrue(static function (array $v): bool {
return count(array_filter(array_keys($v), static function (string $doctrineService): bool {
return strpos($doctrineService, 'Doctrine\Migrations\\') !== 0;
})) !== 0;
})
->ifTrue(static fn (array $v): bool => count(array_filter(
array_keys($v),
static fn (string $doctrineService): bool => ! str_starts_with($doctrineService, 'Doctrine\Migrations\\'),
)) !== 0)
->thenInvalid('Valid services for the DoctrineMigrationsBundle must be in the "Doctrine\Migrations" namespace.')
->end()
->prototype('scalar')->end()
Expand All @@ -60,11 +59,10 @@ public function getConfigTreeBuilder(): TreeBuilder
->useAttributeAsKey('factory')
->defaultValue([])
->validate()
->ifTrue(static function (array $v): bool {
return count(array_filter(array_keys($v), static function (string $doctrineService): bool {
return strpos($doctrineService, 'Doctrine\Migrations\\') !== 0;
})) !== 0;
})
->ifTrue(static fn (array $v): bool => count(array_filter(
array_keys($v),
static fn (string $doctrineService): bool => ! str_starts_with($doctrineService, 'Doctrine\Migrations\\'),
)) !== 0)
->thenInvalid('Valid callables for the DoctrineMigrationsBundle must be in the "Doctrine\Migrations" namespace.')
->end()
->prototype('scalar')->end()
Expand Down Expand Up @@ -128,9 +126,7 @@ public function getConfigTreeBuilder(): TreeBuilder
->end()
->validate()
->ifString()
->then(static function ($v) {
return constant('Doctrine\Migrations\Configuration\Configuration::VERSIONS_ORGANIZATION_' . strtoupper($v));
})
->then(static fn (string $v): string => constant('Doctrine\Migrations\Configuration\Configuration::VERSIONS_ORGANIZATION_' . strtoupper($v)))
->end()
->end()
->booleanNode('enable_profiler')
Expand Down Expand Up @@ -160,7 +156,7 @@ private function getOrganizeMigrationsModes(): array
$namesArray = [];

foreach ($constsArray as $constant) {
if (strpos($constant, $constPrefix) !== 0) {
if (! str_starts_with($constant, $constPrefix)) {
continue;
}

Expand Down
3 changes: 1 addition & 2 deletions tests/Collector/MigrationsFlattenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@

class MigrationsFlattenerTest extends TestCase
{
/** @var MigrationsFlattener */
private $flattener;
private MigrationsFlattener $flattener;

protected function setUp(): void
{
Expand Down
3 changes: 1 addition & 2 deletions tests/DependencyInjection/DoctrineCommandsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ public static function getCommands(): array
];
}

/** @return KernelInterface&MockObject */
private function getKernel(ContainerBuilder $container): KernelInterface
private function getKernel(ContainerBuilder $container): KernelInterface&MockObject
{
$kernel = $this->createMock(KernelInterface::class);

Expand Down
9 changes: 3 additions & 6 deletions tests/DependencyInjection/DoctrineMigrationsExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,12 +202,9 @@ public function testServiceFactory(): void
$container = $this->getContainer($config);

$sorterFactory = new class ($mockComparator) {
/** @var Comparator */
private $comparator;

public function __construct(Comparator $comparator)
{
$this->comparator = $comparator;
public function __construct(
private readonly Comparator $comparator,
) {
}

public function __invoke(DependencyFactory $di): Comparator
Expand Down

0 comments on commit 9b12705

Please sign in to comment.