Skip to content

Commit

Permalink
[Internal] Update php-cs rules, use more default rules from PhpCsFixe…
Browse files Browse the repository at this point in the history
…r, PhpCsFixer:risky
  • Loading branch information
mpoiriert committed Sep 29, 2024
1 parent e5b1871 commit 5ec4349
Show file tree
Hide file tree
Showing 477 changed files with 2,760 additions and 1,329 deletions.
39 changes: 14 additions & 25 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,38 +10,27 @@

$config = (new \PhpCsFixer\Config())
->setRules([
'@PHP74Migration' => true,
'@PHP74Migration:risky' => true,
'@PHP80Migration:risky' => true,
'@PHP82Migration' => true,
'@PhpCsFixer' => true,
'@PhpCsFixer:risky' => true,
'@Symfony' => true,
'@Symfony:risky' => true,
'@PHPUnit57Migration:risky' => true,
'@PHPUnit60Migration:risky' => true,
'@PHPUnit75Migration:risky' => true,
'@PHPUnit84Migration:risky' => true,
'array_indentation' => true,
'combine_consecutive_issets' => true,
'combine_consecutive_unsets' => true,
'method_argument_space' => ['on_multiline' => 'ensure_fully_multiline'],
'php_unit_test_case_static_method_calls' => true,
'phpdoc_order' => true,
'header_comment' => [
'header' => '',
],
'logical_operators' => true,
'no_useless_return' => true,
'global_namespace_import' => ['import_classes' => false, 'import_constants' => false, 'import_functions' => false],
'list_syntax' => ['syntax' => 'short'],
'multiline_whitespace_before_semicolons' => ['strategy' => 'no_multi_line'],
'no_extra_blank_lines' => true,
'no_superfluous_phpdoc_tags' => ['allow_unused_params' => true, 'allow_mixed' => true, 'remove_inheritdoc' => true],
'no_useless_else' => true,
'nullable_type_declaration_for_default_null_value' => ['use_nullable_type_declaration' => true],
'phpdoc_add_missing_param_annotation' => ['only_untyped' => true],
'single_line_throw' => false,
'@DoctrineAnnotation' => true,
// Disabled risky for now
'@PHPUnit91Migration:risky' => true,
'@PHPUnit100Migration:risky' => true,
'header_comment' => ['header' => '',], // Make sure we remove any header comments
'phpdoc_add_missing_param_annotation' => ['only_untyped' => true], // @PhpCsFixer use default 'true', we don't want php doc that are already typed
'method_chaining_indentation' => false, // @PhpCsFixer use default 'true' impact readability on symfony configuration and sonata admin
'phpdoc_no_empty_return' => false, // @PhpCsFixer use default 'true' draw/open-api require empty phpdoc for documentation
'final_internal_class' => false, // All test case are made internal, but we do not want them to be final
// Disabled for now
'strict_comparison' => false, // @PhpCsFixer:risky change this, we do need to loosely compare 2 object at some places, might find a way to fix this.
'php_unit_test_class_requires_covers' => false, // @PhpCsFixer use default 'true' putting covers nothing by default
'declare_strict_types' => false,
'phpdoc_separation' => false,
])
->setFinder($finder);
;
Expand Down
3 changes: 2 additions & 1 deletion app/src/Command/NullCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ protected function configure(): void
InputOption::VALUE_REQUIRED,
'The exit code to return.',
Command::SUCCESS
);
)
;
}

protected function execute(InputInterface $input, OutputInterface $output): int
Expand Down
5 changes: 3 additions & 2 deletions app/src/Controller/Admin/AddRolesAminAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function __invoke(
$request,
AddRolesForm::class,
null,
function (User $user, array $data) use ($objectActionExecutioner): void {
static function (User $user, array $data) use ($objectActionExecutioner): void {
$roles = $data['roles'];

$missingRoles = array_diff($roles, $user->getRoles());
Expand All @@ -34,6 +34,7 @@ function (User $user, array $data) use ($objectActionExecutioner): void {
$objectActionExecutioner->skip('all-roles-already-set');
}
}
);
)
;
}
}
9 changes: 5 additions & 4 deletions app/src/Controller/Admin/MakeAdminAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ public function __invoke(
return $objectActionExecutioner
->execute(
[
'execution' => function (User $user) use ($objectActionExecutioner): void {
'execution' => static function (User $user) use ($objectActionExecutioner): void {
$currentRoles = $user->getRoles();

if (\in_array('ROLE_ADMIN', $currentRoles)) {
if (\in_array('ROLE_ADMIN', $currentRoles, true)) {
$objectActionExecutioner->skip('already-admin');

return;
Expand All @@ -31,10 +31,11 @@ public function __invoke(

$objectActionExecutioner->getAdmin()->update($user);
},
'onExecutionError' => function (ExecutionErrorEvent $event): void {
'onExecutionError' => static function (ExecutionErrorEvent $event): void {
$event->setStopExecution(false);
},
]
);
)
;
}
}
42 changes: 28 additions & 14 deletions app/src/DataFixtures/AppFixtures.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ private function loadTags(): iterable
->getTranslatable()
->translate('fr')
->setLabel('Administrateur')
->getTranslatable();
->getTranslatable()
;

yield 'inactive' => (new Tag())
->setName('inactive')
Expand All @@ -73,7 +74,8 @@ private function loadTags(): iterable
->getTranslatable()
->translate('fr')
->setLabel('Inactif')
->getTranslatable();
->getTranslatable()
;

yield 'not-use' => (new Tag())
->setName('not-use')
Expand All @@ -82,7 +84,8 @@ private function loadTags(): iterable
->getTranslatable()
->translate('fr')
->setLabel('Non Utilisé')
->getTranslatable();
->getTranslatable()
;
}

private function loadUsers(): iterable
Expand All @@ -107,38 +110,44 @@ private function loadUsers(): iterable
(new Address())
->setStreet('201 Secondary Acme')
)
);
)
;

yield (new User())
->setEmail('[email protected]')
->setPlainPassword('2fa-admin')
->setLevel(User::LEVEL_ADMIN)
->setRoles(['ROLE_2FA_ADMIN']);
->setRoles(['ROLE_2FA_ADMIN'])
;

yield (new User())
->setEmail('[email protected]')
->setNeedChangePassword(true)
->setLevel(User::LEVEL_ADMIN)
->setRoles(['ROLE_ADMIN']);
->setRoles(['ROLE_ADMIN'])
;

yield (new User())
->setEmail('[email protected]')
->setPlainPassword('locked')
->setLevel(User::LEVEL_ADMIN)
->setRoles(['ROLE_ADMIN'])
->setManualLock(true);
->setManualLock(true)
;

$inactiveTag = $this->getObjectReference(Tag::class, 'inactive');

foreach (range(1, 4) as $number) {
$user = (new User())
->setEmail('user-'.str_pad((string) $number, 4, '0', \STR_PAD_LEFT).'@example.com')
->setPlainPassword('password');
->setPlainPassword('password')
;

if (1 === $number) {
$user
->setTags([$inactiveTag])
->setPreferredLocale('fr');
->setPreferredLocale('fr')
;
}

yield $user;
Expand All @@ -154,27 +163,32 @@ private function loadChildObject2(): iterable
$user
->setOnDeleteRestrict(
$objects[] = (new ChildObject2())->setAttribute2('on-delete-restrict')
);
)
;

$user
->setOnDeleteCascade(
$objects[] = (new ChildObject2())->setAttribute2('on-delete-cascade')
);
)
;

$user
->setOnDeleteSetNull(
$objects[] = (new ChildObject2())->setAttribute2('on-delete-set-null')
);
)
;

$user
->setOnDeleteCascadeConfigOverridden(
$objects[] = (new ChildObject2())->setAttribute2('on-delete-cascade-config-overridden')
);
)
;

$user
->setOnDeleteCascadeAttributeOverridden(
$objects[] = (new ChildObject2())->setAttribute2('on-delete-cascade-attribute-overridden')
);
)
;

yield from $objects;
}
Expand Down
2 changes: 1 addition & 1 deletion app/src/Entity/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ public function setRoles(array $roles): static
$this->roles = array_values(
array_filter(
$roles,
fn ($role) => \is_string($role) && '' !== $role && 'ROLE_USER' !== $role
static fn ($role) => \is_string($role) && '' !== $role && 'ROLE_USER' !== $role
)
);

Expand Down
13 changes: 8 additions & 5 deletions app/src/EntityMigration/UserSetCommentNullMigration.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ public static function getName(): string

public function __construct(private ManagerRegistry $managerRegistry)
{

}

public static function getTargetEntityClass(): string
Expand All @@ -46,7 +45,8 @@ public function findAllThatNeedMigration(): iterable
\assert($manager instanceof EntityManagerInterface);

$query = $manager
->createQuery('SELECT user.id FROM '.User::class.' user WHERE user.comment != :comment');
->createQuery('SELECT user.id FROM '.User::class.' user WHERE user.comment != :comment')
;

foreach ($query->toIterable(['comment' => ''], $query::HYDRATE_SCALAR) as $userId) {
yield $manager->getReference(User::class, $userId['id']);
Expand All @@ -61,7 +61,8 @@ public function countAllThatNeedMigration(): ?int
return (int) $manager
->createQuery('SELECT count(user) FROM '.User::class.' user WHERE user.comment != :comment')
->setParameter('comment', '')
->getSingleScalarResult();
->getSingleScalarResult()
;
}

public function migrationIsCompleted(): bool
Expand All @@ -75,7 +76,8 @@ public function migrationIsCompleted(): bool
->where('user.comment != ""')
->setMaxResults(1)
->getQuery()
->getOneOrNullResult();
->getOneOrNullResult()
;
}

public function createSelectIdQueryBuilder(): QueryBuilder
Expand All @@ -88,6 +90,7 @@ public function createSelectIdQueryBuilder(): QueryBuilder
->from(User::class, 'user')
->select('user.id as id')
->where('user.comment != :comment')
->setParameter('comment', '');
->setParameter('comment', '')
;
}
}
3 changes: 2 additions & 1 deletion app/src/Form/AddRolesForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
'submit',
SubmitType::class,
['label' => 'submit']
);
)
;
}
}
3 changes: 2 additions & 1 deletion app/src/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ public function process(ContainerBuilder $container): void
$container
->getDefinition('test.client')
->setClass(TestKernelBrowser::class)
->setAutowired(true);
->setAutowired(true)
;
}
}
}
17 changes: 11 additions & 6 deletions app/src/Maker/MakeDrawPackage.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ public function configureCommand(Command $command, InputConfiguration $inputConf
$command
->addArgument('type', InputArgument::REQUIRED, 'The type of the package:: (component|bundle)')
->addArgument('name', InputArgument::REQUIRED, 'The name of the package: Example: my-package')
->addArgument('description', InputArgument::REQUIRED, 'The description of the package');
->addArgument('description', InputArgument::REQUIRED, 'The description of the package')
;
}

public function configureDependencies(DependencyBuilder $dependencies): void
Expand All @@ -45,7 +46,7 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen
$type = $input->getArgument('type');
$packageName = $input->getArgument('name');

if (!\in_array($type, ['component', 'bundle'])) {
if (!\in_array($type, ['component', 'bundle'], true)) {
$io->error('Invalid package type');

return;
Expand Down Expand Up @@ -85,25 +86,29 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen
'type' => $type,
]
)
);
)
;

$generator
->dumpFile(
'packages/'.$packageName.'/phpunit.xml.dist',
file_get_contents(__DIR__.'/../Resources/skeleton/draw-package/phpunit.xml.dist')
);
)
;

$generator
->dumpFile(
$this->kernelProjectDir.'/composer.json',
$this->getNewComposerContents($packageName, $namespace)
);
)
;

$generator
->dumpFile(
$this->kernelProjectDir.'/.github/workflows/after_splitting_test.yaml',
$this->getNewGithubWorkflowsAfterSplittingTestContents($packageName)
);
)
;

$generator->writeChanges();
}
Expand Down
9 changes: 6 additions & 3 deletions app/src/Sonata/Admin/BaseObjectAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ protected function configureDatagridFilters(DatagridMapper $filter): void
filterOptions: [
'show_filter' => true,
]
);
)
;
}

protected function configureListFields(ListMapper $list): void
Expand All @@ -83,7 +84,8 @@ protected function configureListFields(ListMapper $list): void
]
)
->add('dateTimeImmutable')
->add('attribute2');
->add('attribute2')
;
}

protected function configureFormFields(FormMapper $form): void
Expand All @@ -97,6 +99,7 @@ protected function configureFormFields(FormMapper $form): void
->ifEnd()
->ifTrue($subject instanceof ChildObject2)
->add('attribute2')
->ifEnd();
->ifEnd()
;
}
}
Loading

0 comments on commit 5ec4349

Please sign in to comment.