Skip to content

Commit 580fed5

Browse files
committed
minor #1127 update php-cs-fixer ruleset for php8 (jrushlow)
This PR was squashed before being merged into the 1.0-dev branch. Discussion ---------- update php-cs-fixer ruleset for php8 - adds the PHP 8 && PHPUnit 8.4 migration rulesets - forces trailing commas in multiline parameter lists to improve diff readability. e.g. ```php public function __construct( private int $number, private string $word, ) ``` I also added trailing line commas in multiline _argument_ lists and then reverted the commit. See commit 352f951 If this we _should_ keep multiline trailing commas for args - I'll drop the commit that reverts it. Thoughts `@weaverryan` `@OskarStark` `@wouterj` ? Commits ------- 697071d update php-cs-fixer ruleset for php8
2 parents 7362329 + 697071d commit 580fed5

27 files changed

+242
-235
lines changed

.php-cs-fixer.dist.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515

1616
return (new PhpCsFixer\Config())
1717
->setRules(array(
18-
'@PHPUnit75Migration:risky' => true,
18+
'@PHP80Migration' => true,
19+
'@PHPUnit84Migration:risky' => true,
1920
'@Symfony' => true,
2021
'@Symfony:risky' => true,
2122
'header_comment' => [
@@ -30,6 +31,12 @@
3031
],
3132
'protected_to_private' => false,
3233
'semicolon_after_instruction' => false,
34+
'trailing_comma_in_multiline' => [
35+
'elements' => [
36+
'arrays',
37+
'parameters'
38+
],
39+
]
3340
))
3441
->setRiskyAllowed(true)
3542
->setFinder($finder)

src/Doctrine/EntityDetails.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
final class EntityDetails
2323
{
2424
public function __construct(
25-
private ClassMetadata|LegacyClassMetadata $metadata
25+
private ClassMetadata|LegacyClassMetadata $metadata,
2626
) {
2727
}
2828

src/Doctrine/EntityRegenerator.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function __construct(
3030
private FileManager $fileManager,
3131
private Generator $generator,
3232
private EntityClassGenerator $entityClassGenerator,
33-
private bool $overwrite
33+
private bool $overwrite,
3434
) {
3535
}
3636

@@ -92,7 +92,7 @@ public function regenerateEntities(string $classOrNamespace): void
9292
foreach ($classMetadata->fieldMappings as $fieldName => $mapping) {
9393
// skip embedded fields
9494
if (false !== strpos($fieldName, '.')) {
95-
list($fieldName, $embeddedFiledName) = explode('.', $fieldName);
95+
[$fieldName, $embeddedFiledName] = explode('.', $fieldName);
9696

9797
$operations[$embeddedClasses[$fieldName]]->addEntityField($embeddedFiledName, $mapping);
9898

src/Doctrine/EntityRelation.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ final class EntityRelation
3131
public function __construct(
3232
private string $type,
3333
private string $owningClass,
34-
private string $inverseClass
34+
private string $inverseClass,
3535
) {
3636
if (!\in_array($type, self::getValidRelationTypes())) {
3737
throw new \Exception(sprintf('Invalid relation type "%s"', $type));

src/FileManager.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public function __construct(
3838
AutoloaderUtil $autoloaderUtil,
3939
MakerFileLinkFormatter $makerFileLinkFormatter,
4040
string $rootDirectory,
41-
string $twigDefaultPath = null
41+
string $twigDefaultPath = null,
4242
) {
4343
// move FileManagerTest stuff
4444
// update EntityRegeneratorTest to mock the autoloader

src/GeneratorTwigHelper.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,19 +68,19 @@ public function getHeadPrintCode($title): string
6868
{
6969
if ($this->fileManager->fileExists($this->fileManager->getPathForTemplate('base.html.twig'))) {
7070
return <<<TWIG
71-
{% extends 'base.html.twig' %}
71+
{% extends 'base.html.twig' %}
7272
73-
{% block title %}$title{% endblock %}
73+
{% block title %}$title{% endblock %}
7474
75-
TWIG;
75+
TWIG;
7676
}
7777

7878
return <<<HTML
79-
<!DOCTYPE html>
79+
<!DOCTYPE html>
8080
81-
<title>$title</title>
81+
<title>$title</title>
8282
83-
HTML;
83+
HTML;
8484
}
8585

8686
public function getFileLink($path, $text = null, $line = 0): string

src/Maker/MakeAuthenticator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public function __construct(
7070
private SecurityConfigUpdater $configUpdater,
7171
private Generator $generator,
7272
private DoctrineHelper $doctrineHelper,
73-
private SecurityControllerBuilder $securityControllerBuilder
73+
private SecurityControllerBuilder $securityControllerBuilder,
7474
) {
7575
}
7676

src/Maker/MakeEntity.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public function __construct(
5555
string $projectDirectory = null,
5656
Generator $generator = null,
5757
EntityClassGenerator $entityClassGenerator = null,
58-
PhpCompatUtil $phpCompatUtil = null
58+
PhpCompatUtil $phpCompatUtil = null,
5959
) {
6060
if (null !== $projectDirectory) {
6161
@trigger_error('The $projectDirectory constructor argument is no longer used since 1.41.0', \E_USER_DEPRECATED);

src/Maker/MakeRegistrationForm.php

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public function __construct(
8686
private FileManager $fileManager,
8787
private FormTypeRenderer $formTypeRenderer,
8888
private RouterInterface $router,
89-
private DoctrineHelper $doctrineHelper
89+
private DoctrineHelper $doctrineHelper,
9090
) {
9191
}
9292

@@ -537,33 +537,33 @@ private function generateFormClass(ClassNameDetails $userClassDetails, Generator
537537
'agreeTerms' => [
538538
'type' => CheckboxType::class,
539539
'options_code' => <<<EOF
540-
'mapped' => false,
541-
'constraints' => [
542-
new IsTrue([
543-
'message' => 'You should agree to our terms.',
544-
]),
545-
],
546-
EOF
540+
'mapped' => false,
541+
'constraints' => [
542+
new IsTrue([
543+
'message' => 'You should agree to our terms.',
544+
]),
545+
],
546+
EOF
547547
],
548548
'plainPassword' => [
549549
'type' => PasswordType::class,
550550
'options_code' => <<<EOF
551-
// instead of being set onto the object directly,
552-
// this is read and encoded in the controller
553-
'mapped' => false,
554-
'attr' => ['autocomplete' => 'new-password'],
555-
'constraints' => [
556-
new NotBlank([
557-
'message' => 'Please enter a password',
558-
]),
559-
new Length([
560-
'min' => 6,
561-
'minMessage' => 'Your password should be at least {{ limit }} characters',
562-
// max length allowed by Symfony for security reasons
563-
'max' => 4096,
564-
]),
565-
],
566-
EOF
551+
// instead of being set onto the object directly,
552+
// this is read and encoded in the controller
553+
'mapped' => false,
554+
'attr' => ['autocomplete' => 'new-password'],
555+
'constraints' => [
556+
new NotBlank([
557+
'message' => 'Please enter a password',
558+
]),
559+
new Length([
560+
'min' => 6,
561+
'minMessage' => 'Your password should be at least {{ limit }} characters',
562+
// max length allowed by Symfony for security reasons
563+
'max' => 4096,
564+
]),
565+
],
566+
EOF
567567
],
568568
];
569569

src/Maker/MakeResetPassword.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ class MakeResetPassword extends AbstractMaker
8888
public function __construct(
8989
private FileManager $fileManager,
9090
private DoctrineHelper $doctrineHelper,
91-
private EntityClassGenerator $entityClassGenerator
91+
private EntityClassGenerator $entityClassGenerator,
9292
) {
9393
}
9494

@@ -421,10 +421,10 @@ private function generateRequestEntity(Generator $generator, ClassNameDetails $r
421421
(new Param('selector'))->setType('string')->getNode(),
422422
(new Param('hashedToken'))->setType('string')->getNode(),
423423
], <<<'CODE'
424-
<?php
425-
$this->user = $user;
426-
$this->initialize($expiresAt, $selector, $hashedToken);
427-
CODE
424+
<?php
425+
$this->user = $user;
426+
$this->initialize($expiresAt, $selector, $hashedToken);
427+
CODE
428428
);
429429

430430
$manipulator->addManyToOneRelation((new RelationManyToOne())
@@ -466,9 +466,9 @@ private function generateRequestEntity(Generator $generator, ClassNameDetails $r
466466
(new Param('selector'))->setType('string')->getNode(),
467467
(new Param('hashedToken'))->setType('string')->getNode(),
468468
], <<<'CODE'
469-
<?php
470-
return new ResetPasswordRequest($user, $expiresAt, $selector, $hashedToken);
471-
CODE
469+
<?php
470+
return new ResetPasswordRequest($user, $expiresAt, $selector, $hashedToken);
471+
CODE
472472
);
473473

474474
$this->fileManager->dumpFile($pathRequestRepository, $manipulator->getSourceCode());

src/Maker/MakeUser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function __construct(
5353
private UserClassBuilder $userClassBuilder,
5454
private SecurityConfigUpdater $configUpdater,
5555
private EntityClassGenerator $entityClassGenerator,
56-
private DoctrineHelper $doctrineHelper
56+
private DoctrineHelper $doctrineHelper,
5757
) {
5858
}
5959

src/Renderer/FormTypeRenderer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function render(ClassNameDetails $formClassDetails, array $formFields, Cl
3636
$fieldTypeUseStatements = [];
3737
$fields = [];
3838
foreach ($formFields as $name => $fieldTypeOptions) {
39-
$fieldTypeOptions = $fieldTypeOptions ?? ['type' => null, 'options_code' => null];
39+
$fieldTypeOptions ??= ['type' => null, 'options_code' => null];
4040

4141
if (isset($fieldTypeOptions['type'])) {
4242
$fieldTypeUseStatements[] = $fieldTypeOptions['type'];

src/Security/SecurityConfigUpdater.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ final class SecurityConfigUpdater
2626
private ?YamlSourceManipulator $manipulator;
2727

2828
public function __construct(
29-
private ?Logger $ysmLogger = null
29+
private ?Logger $ysmLogger = null,
3030
) {
3131
}
3232

src/Security/SecurityControllerBuilder.php

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
final class SecurityControllerBuilder
2424
{
2525
public function __construct(
26-
private PhpCompatUtil $phpCompatUtil
26+
private PhpCompatUtil $phpCompatUtil,
2727
) {
2828
}
2929

@@ -42,32 +42,32 @@ public function addLoginMethod(ClassSourceManipulator $manipulator): void
4242
);
4343

4444
$manipulator->addMethodBody($loginMethodBuilder, <<<'CODE'
45-
<?php
46-
// if ($this->getUser()) {
47-
// return $this->redirectToRoute('target_path');
48-
// }
49-
CODE
45+
<?php
46+
// if ($this->getUser()) {
47+
// return $this->redirectToRoute('target_path');
48+
// }
49+
CODE
5050
);
5151
$loginMethodBuilder->addStmt($manipulator->createMethodLevelBlankLine());
5252
$manipulator->addMethodBody($loginMethodBuilder, <<<'CODE'
53-
<?php
54-
// get the login error if there is one
55-
$error = $authenticationUtils->getLastAuthenticationError();
56-
// last username entered by the user
57-
$lastUsername = $authenticationUtils->getLastUsername();
58-
CODE
53+
<?php
54+
// get the login error if there is one
55+
$error = $authenticationUtils->getLastAuthenticationError();
56+
// last username entered by the user
57+
$lastUsername = $authenticationUtils->getLastUsername();
58+
CODE
5959
);
6060
$loginMethodBuilder->addStmt($manipulator->createMethodLevelBlankLine());
6161
$manipulator->addMethodBody($loginMethodBuilder, <<<'CODE'
62-
<?php
63-
return $this->render(
64-
'security/login.html.twig',
65-
[
66-
'last_username' => $lastUsername,
67-
'error' => $error,
68-
]
69-
);
70-
CODE
62+
<?php
63+
return $this->render(
64+
'security/login.html.twig',
65+
[
66+
'last_username' => $lastUsername,
67+
'error' => $error,
68+
]
69+
);
70+
CODE
7171
);
7272
$manipulator->addMethodBuilder($loginMethodBuilder);
7373
}
@@ -80,9 +80,9 @@ public function addLogoutMethod(ClassSourceManipulator $manipulator): void
8080

8181
$manipulator->addUseStatementIfNecessary(Route::class);
8282
$manipulator->addMethodBody($logoutMethodBuilder, <<<'CODE'
83-
<?php
84-
throw new \LogicException('This method can be blank - it will be intercepted by the logout key on your firewall.');
85-
CODE
83+
<?php
84+
throw new \LogicException('This method can be blank - it will be intercepted by the logout key on your firewall.');
85+
CODE
8686
);
8787
$manipulator->addMethodBuilder($logoutMethodBuilder);
8888
}

src/Test/MakerTestCase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ private function getMakerInstance(string $makerClass): MakerInterface
106106
}
107107

108108
// a cheap way to guess the service id
109-
$serviceId = $serviceId ?? sprintf('maker.maker.%s', Str::asSnakeCase((new \ReflectionClass($makerClass))->getShortName()));
109+
$serviceId ??= sprintf('maker.maker.%s', Str::asSnakeCase((new \ReflectionClass($makerClass))->getShortName()));
110110

111111
return $this->kernel->getContainer()->get($serviceId);
112112
}

src/Util/AutoloaderUtil.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
class AutoloaderUtil
2222
{
2323
public function __construct(
24-
private ComposerAutoloaderFinder $autoloaderFinder
24+
private ComposerAutoloaderFinder $autoloaderFinder,
2525
) {
2626
}
2727

src/Util/ClassDetails.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
final class ClassDetails
1818
{
1919
public function __construct(
20-
private string $fullClassName
20+
private string $fullClassName,
2121
) {
2222
}
2323

src/Util/ClassNameDetails.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ final class ClassNameDetails
1818
public function __construct(
1919
private string $fullClassName,
2020
private string $namespacePrefix,
21-
private ?string $suffix = null
21+
private ?string $suffix = null,
2222
) {
2323
$this->namespacePrefix = trim($namespacePrefix, '\\');
2424
}

src/Util/ClassNameValue.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ final class ClassNameValue
2020
{
2121
public function __construct(
2222
private string $typeHint,
23-
private string $fullClassName
23+
private string $fullClassName,
2424
) {
2525
}
2626

src/Util/UseStatementGenerator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ final class UseStatementGenerator implements \Stringable
2929
* @param string[]|array<string, string> $classesToBeImported
3030
*/
3131
public function __construct(
32-
private array $classesToBeImported
32+
private array $classesToBeImported,
3333
) {
3434
}
3535

src/Util/YamlSourceManipulator.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class YamlSourceManipulator
4949
private $arrayTypeForDepths = [];
5050

5151
public function __construct(
52-
private string $contents
52+
private string $contents,
5353
) {
5454
$this->currentData = Yaml::parse($contents);
5555

@@ -966,7 +966,7 @@ private function log(string $message, $includeContent = false)
966966
}
967967

968968
$context = [
969-
'key' => isset($this->currentPath[$this->depth]) ? $this->currentPath[$this->depth] : 'n/a',
969+
'key' => $this->currentPath[$this->depth] ?? 'n/a',
970970
'depth' => $this->depth,
971971
'position' => $this->currentPosition,
972972
'indentation' => $this->indentationForDepths[$this->depth],

0 commit comments

Comments
 (0)