Skip to content

update php-cs-fixer ruleset for php8 #1127

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

Merged
merged 1 commit into from
May 23, 2022
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
9 changes: 8 additions & 1 deletion .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@

return (new PhpCsFixer\Config())
->setRules(array(
'@PHPUnit75Migration:risky' => true,
'@PHP80Migration' => true,
'@PHPUnit84Migration:risky' => true,
'@Symfony' => true,
'@Symfony:risky' => true,
'header_comment' => [
Expand All @@ -30,6 +31,12 @@
],
'protected_to_private' => false,
'semicolon_after_instruction' => false,
'trailing_comma_in_multiline' => [
'elements' => [
'arrays',
'parameters'
],
]
))
->setRiskyAllowed(true)
->setFinder($finder)
Expand Down
2 changes: 1 addition & 1 deletion src/Doctrine/EntityDetails.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
final class EntityDetails
{
public function __construct(
private ClassMetadata|LegacyClassMetadata $metadata
private ClassMetadata|LegacyClassMetadata $metadata,
) {
}

Expand Down
4 changes: 2 additions & 2 deletions src/Doctrine/EntityRegenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function __construct(
private FileManager $fileManager,
private Generator $generator,
private EntityClassGenerator $entityClassGenerator,
private bool $overwrite
private bool $overwrite,
) {
}

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

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

Expand Down
2 changes: 1 addition & 1 deletion src/Doctrine/EntityRelation.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ final class EntityRelation
public function __construct(
private string $type,
private string $owningClass,
private string $inverseClass
private string $inverseClass,
) {
if (!\in_array($type, self::getValidRelationTypes())) {
throw new \Exception(sprintf('Invalid relation type "%s"', $type));
Expand Down
2 changes: 1 addition & 1 deletion src/FileManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function __construct(
AutoloaderUtil $autoloaderUtil,
MakerFileLinkFormatter $makerFileLinkFormatter,
string $rootDirectory,
string $twigDefaultPath = null
string $twigDefaultPath = null,
) {
// move FileManagerTest stuff
// update EntityRegeneratorTest to mock the autoloader
Expand Down
12 changes: 6 additions & 6 deletions src/GeneratorTwigHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,19 +68,19 @@ public function getHeadPrintCode($title): string
{
if ($this->fileManager->fileExists($this->fileManager->getPathForTemplate('base.html.twig'))) {
return <<<TWIG
{% extends 'base.html.twig' %}
{% extends 'base.html.twig' %}

{% block title %}$title{% endblock %}
{% block title %}$title{% endblock %}

TWIG;
TWIG;
}

return <<<HTML
<!DOCTYPE html>
<!DOCTYPE html>

<title>$title</title>
<title>$title</title>

HTML;
HTML;
}

public function getFileLink($path, $text = null, $line = 0): string
Expand Down
2 changes: 1 addition & 1 deletion src/Maker/MakeAuthenticator.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function __construct(
private SecurityConfigUpdater $configUpdater,
private Generator $generator,
private DoctrineHelper $doctrineHelper,
private SecurityControllerBuilder $securityControllerBuilder
private SecurityControllerBuilder $securityControllerBuilder,
) {
}

Expand Down
2 changes: 1 addition & 1 deletion src/Maker/MakeEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function __construct(
string $projectDirectory = null,
Generator $generator = null,
EntityClassGenerator $entityClassGenerator = null,
PhpCompatUtil $phpCompatUtil = null
PhpCompatUtil $phpCompatUtil = null,
) {
if (null !== $projectDirectory) {
@trigger_error('The $projectDirectory constructor argument is no longer used since 1.41.0', \E_USER_DEPRECATED);
Expand Down
48 changes: 24 additions & 24 deletions src/Maker/MakeRegistrationForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public function __construct(
private FileManager $fileManager,
private FormTypeRenderer $formTypeRenderer,
private RouterInterface $router,
private DoctrineHelper $doctrineHelper
private DoctrineHelper $doctrineHelper,
) {
}

Expand Down Expand Up @@ -537,33 +537,33 @@ private function generateFormClass(ClassNameDetails $userClassDetails, Generator
'agreeTerms' => [
'type' => CheckboxType::class,
'options_code' => <<<EOF
'mapped' => false,
'constraints' => [
new IsTrue([
'message' => 'You should agree to our terms.',
]),
],
EOF
'mapped' => false,
'constraints' => [
new IsTrue([
'message' => 'You should agree to our terms.',
]),
],
EOF
],
'plainPassword' => [
'type' => PasswordType::class,
'options_code' => <<<EOF
// instead of being set onto the object directly,
// this is read and encoded in the controller
'mapped' => false,
'attr' => ['autocomplete' => 'new-password'],
'constraints' => [
new NotBlank([
'message' => 'Please enter a password',
]),
new Length([
'min' => 6,
'minMessage' => 'Your password should be at least {{ limit }} characters',
// max length allowed by Symfony for security reasons
'max' => 4096,
]),
],
EOF
// instead of being set onto the object directly,
// this is read and encoded in the controller
'mapped' => false,
'attr' => ['autocomplete' => 'new-password'],
'constraints' => [
new NotBlank([
'message' => 'Please enter a password',
]),
new Length([
'min' => 6,
'minMessage' => 'Your password should be at least {{ limit }} characters',
// max length allowed by Symfony for security reasons
'max' => 4096,
]),
],
EOF
],
];

Expand Down
16 changes: 8 additions & 8 deletions src/Maker/MakeResetPassword.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class MakeResetPassword extends AbstractMaker
public function __construct(
private FileManager $fileManager,
private DoctrineHelper $doctrineHelper,
private EntityClassGenerator $entityClassGenerator
private EntityClassGenerator $entityClassGenerator,
) {
}

Expand Down Expand Up @@ -421,10 +421,10 @@ private function generateRequestEntity(Generator $generator, ClassNameDetails $r
(new Param('selector'))->setType('string')->getNode(),
(new Param('hashedToken'))->setType('string')->getNode(),
], <<<'CODE'
<?php
$this->user = $user;
$this->initialize($expiresAt, $selector, $hashedToken);
CODE
<?php
$this->user = $user;
$this->initialize($expiresAt, $selector, $hashedToken);
CODE
);

$manipulator->addManyToOneRelation((new RelationManyToOne())
Expand Down Expand Up @@ -466,9 +466,9 @@ private function generateRequestEntity(Generator $generator, ClassNameDetails $r
(new Param('selector'))->setType('string')->getNode(),
(new Param('hashedToken'))->setType('string')->getNode(),
], <<<'CODE'
<?php
return new ResetPasswordRequest($user, $expiresAt, $selector, $hashedToken);
CODE
<?php
return new ResetPasswordRequest($user, $expiresAt, $selector, $hashedToken);
CODE
);

$this->fileManager->dumpFile($pathRequestRepository, $manipulator->getSourceCode());
Expand Down
2 changes: 1 addition & 1 deletion src/Maker/MakeUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function __construct(
private UserClassBuilder $userClassBuilder,
private SecurityConfigUpdater $configUpdater,
private EntityClassGenerator $entityClassGenerator,
private DoctrineHelper $doctrineHelper
private DoctrineHelper $doctrineHelper,
) {
}

Expand Down
2 changes: 1 addition & 1 deletion src/Renderer/FormTypeRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function render(ClassNameDetails $formClassDetails, array $formFields, Cl
$fieldTypeUseStatements = [];
$fields = [];
foreach ($formFields as $name => $fieldTypeOptions) {
$fieldTypeOptions = $fieldTypeOptions ?? ['type' => null, 'options_code' => null];
$fieldTypeOptions ??= ['type' => null, 'options_code' => null];

if (isset($fieldTypeOptions['type'])) {
$fieldTypeUseStatements[] = $fieldTypeOptions['type'];
Expand Down
2 changes: 1 addition & 1 deletion src/Security/SecurityConfigUpdater.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ final class SecurityConfigUpdater
private ?YamlSourceManipulator $manipulator;

public function __construct(
private ?Logger $ysmLogger = null
private ?Logger $ysmLogger = null,
) {
}

Expand Down
48 changes: 24 additions & 24 deletions src/Security/SecurityControllerBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
final class SecurityControllerBuilder
{
public function __construct(
private PhpCompatUtil $phpCompatUtil
private PhpCompatUtil $phpCompatUtil,
) {
}

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

$manipulator->addMethodBody($loginMethodBuilder, <<<'CODE'
<?php
// if ($this->getUser()) {
// return $this->redirectToRoute('target_path');
// }
CODE
<?php
// if ($this->getUser()) {
// return $this->redirectToRoute('target_path');
// }
CODE
);
$loginMethodBuilder->addStmt($manipulator->createMethodLevelBlankLine());
$manipulator->addMethodBody($loginMethodBuilder, <<<'CODE'
<?php
// get the login error if there is one
$error = $authenticationUtils->getLastAuthenticationError();
// last username entered by the user
$lastUsername = $authenticationUtils->getLastUsername();
CODE
<?php
// get the login error if there is one
$error = $authenticationUtils->getLastAuthenticationError();
// last username entered by the user
$lastUsername = $authenticationUtils->getLastUsername();
CODE
);
$loginMethodBuilder->addStmt($manipulator->createMethodLevelBlankLine());
$manipulator->addMethodBody($loginMethodBuilder, <<<'CODE'
<?php
return $this->render(
'security/login.html.twig',
[
'last_username' => $lastUsername,
'error' => $error,
]
);
CODE
<?php
return $this->render(
'security/login.html.twig',
[
'last_username' => $lastUsername,
'error' => $error,
]
);
CODE
);
$manipulator->addMethodBuilder($loginMethodBuilder);
}
Expand All @@ -80,9 +80,9 @@ public function addLogoutMethod(ClassSourceManipulator $manipulator): void

$manipulator->addUseStatementIfNecessary(Route::class);
$manipulator->addMethodBody($logoutMethodBuilder, <<<'CODE'
<?php
throw new \LogicException('This method can be blank - it will be intercepted by the logout key on your firewall.');
CODE
<?php
throw new \LogicException('This method can be blank - it will be intercepted by the logout key on your firewall.');
CODE
);
$manipulator->addMethodBuilder($logoutMethodBuilder);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Test/MakerTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ private function getMakerInstance(string $makerClass): MakerInterface
}

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

return $this->kernel->getContainer()->get($serviceId);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Util/AutoloaderUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
class AutoloaderUtil
{
public function __construct(
private ComposerAutoloaderFinder $autoloaderFinder
private ComposerAutoloaderFinder $autoloaderFinder,
) {
}

Expand Down
2 changes: 1 addition & 1 deletion src/Util/ClassDetails.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
final class ClassDetails
{
public function __construct(
private string $fullClassName
private string $fullClassName,
) {
}

Expand Down
2 changes: 1 addition & 1 deletion src/Util/ClassNameDetails.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ final class ClassNameDetails
public function __construct(
private string $fullClassName,
private string $namespacePrefix,
private ?string $suffix = null
private ?string $suffix = null,
) {
$this->namespacePrefix = trim($namespacePrefix, '\\');
}
Expand Down
2 changes: 1 addition & 1 deletion src/Util/ClassNameValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ final class ClassNameValue
{
public function __construct(
private string $typeHint,
private string $fullClassName
private string $fullClassName,
) {
}

Expand Down
2 changes: 1 addition & 1 deletion src/Util/UseStatementGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ final class UseStatementGenerator implements \Stringable
* @param string[]|array<string, string> $classesToBeImported
*/
public function __construct(
private array $classesToBeImported
private array $classesToBeImported,
) {
}

Expand Down
4 changes: 2 additions & 2 deletions src/Util/YamlSourceManipulator.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class YamlSourceManipulator
private $arrayTypeForDepths = [];

public function __construct(
private string $contents
private string $contents,
) {
$this->currentData = Yaml::parse($contents);

Expand Down Expand Up @@ -966,7 +966,7 @@ private function log(string $message, $includeContent = false)
}

$context = [
'key' => isset($this->currentPath[$this->depth]) ? $this->currentPath[$this->depth] : 'n/a',
'key' => $this->currentPath[$this->depth] ?? 'n/a',
'depth' => $this->depth,
'position' => $this->currentPosition,
'indentation' => $this->indentationForDepths[$this->depth],
Expand Down
Loading