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

Modernize code #577

Merged
merged 1 commit into from
Jan 13, 2025
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Argh, looks like I forgot to remove this:

<!-- Disable the rules that will require PHP 7.4 -->
<rule ref="SlevomatCodingStandard.TypeHints.PropertyTypeHint">
<properties>
<property name="enableNativeTypeHint" value="false"/>
</properties>
</rule>


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 @@ -206,12 +206,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