Skip to content

Commit 671e915

Browse files
⬆️ Update symplify easy coding standard (#3568)
* ⬆️ update ECS to version 12 * ⬆️ apply ECS configuration * ⬆️ enable tests on branch * fix mixed return type * ➕ Add PHP 8.4 polyfill and use it * disable branch CI * configure space betweeb class element * apply configuration * clean commented code * revert return type for union type * Add missing break statement * Resolve PR comments * Remove slevomat/coding-standard library * Remove no longer needed error_reporting config * Revert ClassAttributesSeparationFixer property spacing --------- Co-authored-by: Bob van de Vijver <[email protected]>
1 parent 26ec6be commit 671e915

File tree

92 files changed

+275
-418
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

92 files changed

+275
-418
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,3 @@ compose.override.yaml
8484
/.phpunit.result.cache
8585
/.phpunit.cache
8686
###< phpunit/phpunit ###
87-

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
"symfony/monolog-bundle": "^3.7",
6363
"symfony/password-hasher": "^5.4",
6464
"symfony/polyfill-php72": "^1.23",
65+
"symfony/polyfill-php84": "^1.31",
6566
"symfony/security-bundle": "^5.4",
6667
"symfony/security-csrf": "^5.4",
6768
"symfony/serializer": "^5.4",
@@ -112,7 +113,7 @@
112113
"se/selenium-server-standalone": "^3.141",
113114
"symfony/browser-kit": "^5.4",
114115
"symfony/css-selector": "^5.4",
115-
"symplify/easy-coding-standard": "^10.0"
116+
"symplify/easy-coding-standard": "^12.5"
116117
},
117118
"config": {
118119
"preferred-install": {
@@ -123,8 +124,7 @@
123124
"composer/package-versions-deprecated": true,
124125
"drupol/composer-packages": true,
125126
"symfony/flex": true,
126-
"php-http/discovery": true,
127-
"dealerdirect/phpcodesniffer-composer-installer": false
127+
"php-http/discovery": true
128128
}
129129
},
130130
"extra": {

ecs.php

Lines changed: 63 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,9 @@
88
use PhpCsFixer\Fixer\ArrayNotation\NoWhitespaceBeforeCommaInArrayFixer;
99
use PhpCsFixer\Fixer\ArrayNotation\WhitespaceAfterCommaInArrayFixer;
1010
use PhpCsFixer\Fixer\Basic\BracesFixer;
11-
use PhpCsFixer\Fixer\Basic\Psr0Fixer;
12-
use PhpCsFixer\Fixer\Basic\Psr4Fixer;
1311
use PhpCsFixer\Fixer\CastNotation\LowercaseCastFixer;
1412
use PhpCsFixer\Fixer\CastNotation\ShortScalarCastFixer;
13+
use PhpCsFixer\Fixer\ClassNotation\ClassAttributesSeparationFixer;
1514
use PhpCsFixer\Fixer\ClassNotation\FinalInternalClassFixer;
1615
use PhpCsFixer\Fixer\ClassNotation\NoBlankLinesAfterClassOpeningFixer;
1716
use PhpCsFixer\Fixer\ClassNotation\OrderedClassElementsFixer;
@@ -39,32 +38,21 @@
3938
use PhpCsFixer\Fixer\PhpUnit\PhpUnitMethodCasingFixer;
4039
use PhpCsFixer\Fixer\Semicolon\NoSinglelineWhitespaceBeforeSemicolonsFixer;
4140
use PhpCsFixer\Fixer\Whitespace\NoTrailingWhitespaceFixer;
42-
use SlevomatCodingStandard\Sniffs\ControlStructures\DisallowYodaComparisonSniff;
4341
use Symplify\CodingStandard\Fixer\ArrayNotation\ArrayListItemNewlineFixer;
4442
use Symplify\CodingStandard\Fixer\ArrayNotation\ArrayOpenerAndCloserNewlineFixer;
4543
use Symplify\CodingStandard\Fixer\ArrayNotation\StandaloneLineInMultilineArrayFixer;
46-
use Symplify\CodingStandard\Fixer\Commenting\RemoveSuperfluousDocBlockWhitespaceFixer;
44+
use Symplify\CodingStandard\Fixer\Commenting\RemoveUselessDefaultCommentFixer;
4745
use Symplify\CodingStandard\Fixer\Strict\BlankLineAfterStrictTypesFixer;
4846
use Symplify\EasyCodingStandard\Config\ECSConfig;
4947

50-
// Suppress `Notice:`s in ECS 8.x This is probably fixed in the 9.x versions,
51-
// but we can't update to that version, because it's PHP > 7.3 only.
52-
// See: https://github.com/bolt/core/issues/2519
53-
error_reporting(error_reporting() & ~E_NOTICE);
54-
55-
return static function (ECSConfig $ecsConfig): void {
56-
$parameters = $ecsConfig->parameters();
57-
58-
$parameters->set('sets', ['clean-code', 'common', 'php70', 'php71', 'psr12', 'symfony', 'symfony-risky']);
59-
60-
$parameters->set('paths', [
48+
return ECSConfig::configure()
49+
->withPaths([
6150
__DIR__ . '/src',
6251
__DIR__ . '/ecs.php',
63-
]);
64-
65-
$parameters->set('cache_directory', 'var/cache/ecs');
66-
67-
$parameters->set('skip', [
52+
])
53+
->withCache('var/cache/ecs')
54+
->withPreparedSets(psr12: true, common: true, cleanCode: true)
55+
->withSkip([
6856
OrderedClassElementsFixer::class => null,
6957
YodaStyleFixer::class => null,
7058
IncrementStyleFixer::class => null,
@@ -76,82 +64,64 @@
7664
UnaryOperatorSpacesFixer::class => null,
7765
ArrayOpenerAndCloserNewlineFixer::class => null,
7866
ArrayListItemNewlineFixer::class => null,
79-
]);
80-
81-
$services = $ecsConfig->services();
82-
83-
$services->set(StandaloneLineInMultilineArrayFixer::class);
84-
85-
$services->set(BlankLineAfterStrictTypesFixer::class);
86-
87-
$services->set(ConcatSpaceFixer::class)
88-
->call('configure', [['spacing' => 'one']]);
89-
90-
$services->set(RemoveSuperfluousDocBlockWhitespaceFixer::class);
91-
92-
$services->set(PhpUnitMethodCasingFixer::class);
93-
94-
$services->set(FinalInternalClassFixer::class);
95-
96-
$services->set(MbStrFunctionsFixer::class);
97-
98-
$services->set(Psr0Fixer::class);
99-
100-
$services->set(Psr4Fixer::class);
101-
102-
$services->set(LowercaseCastFixer::class);
103-
104-
$services->set(ShortScalarCastFixer::class);
105-
106-
$services->set(BlankLineAfterOpeningTagFixer::class);
107-
108-
$services->set(NoLeadingImportSlashFixer::class);
109-
110-
$services->set(OrderedImportsFixer::class)
111-
->call('configure', [[
67+
])
68+
->withRules([
69+
StandaloneLineInMultilineArrayFixer::class,
70+
BlankLineAfterStrictTypesFixer::class,
71+
RemoveUselessDefaultCommentFixer::class,
72+
PhpUnitMethodCasingFixer::class,
73+
FinalInternalClassFixer::class,
74+
MbStrFunctionsFixer::class,
75+
LowercaseCastFixer::class,
76+
ShortScalarCastFixer::class,
77+
BlankLineAfterOpeningTagFixer::class,
78+
NoLeadingImportSlashFixer::class,
79+
NewWithBracesFixer::class,
80+
NoBlankLinesAfterClassOpeningFixer::class,
81+
TernaryOperatorSpacesFixer::class,
82+
ReturnTypeDeclarationFixer::class,
83+
NoTrailingWhitespaceFixer::class,
84+
NoSinglelineWhitespaceBeforeSemicolonsFixer::class,
85+
NoWhitespaceBeforeCommaInArrayFixer::class,
86+
WhitespaceAfterCommaInArrayFixer::class,
87+
FullyQualifiedStrictTypesFixer::class,
88+
])
89+
->withConfiguredRule(PhpdocToReturnTypeFixer::class, ['union_types' => false])
90+
->withConfiguredRule(NoSuperfluousPhpdocTagsFixer::class, ['remove_inheritdoc' => false])
91+
->withConfiguredRule(
92+
ConcatSpaceFixer::class,
93+
['spacing' => 'one']
94+
)
95+
->withConfiguredRule(
96+
OrderedImportsFixer::class,
97+
[
11298
'imports_order' => ['class', 'const', 'function'],
113-
]]);
114-
115-
$services->set(DeclareEqualNormalizeFixer::class)
116-
->call('configure', [['space' => 'none']]);
117-
118-
$services->set(NewWithBracesFixer::class);
119-
120-
$services->set(BracesFixer::class)
121-
->call('configure', [[
99+
]
100+
)
101+
->withConfiguredRule(
102+
DeclareEqualNormalizeFixer::class,
103+
['space' => 'none']
104+
)
105+
->withConfiguredRule(
106+
BracesFixer::class,
107+
[
122108
'allow_single_line_closure' => false,
123109
'position_after_functions_and_oop_constructs' => 'next',
124110
'position_after_control_structures' => 'same',
125111
'position_after_anonymous_constructs' => 'same',
126-
]]);
127-
128-
$services->set(NoBlankLinesAfterClassOpeningFixer::class);
129-
130-
$services->set(VisibilityRequiredFixer::class)
131-
->call('configure', [[
112+
]
113+
)
114+
->withConfiguredRule(
115+
VisibilityRequiredFixer::class,
116+
[
132117
'elements' => ['const', 'method', 'property'],
133-
]]);
134-
135-
$services->set(TernaryOperatorSpacesFixer::class);
136-
137-
$services->set(ReturnTypeDeclarationFixer::class);
138-
139-
$services->set(NoTrailingWhitespaceFixer::class);
140-
141-
$services->set(NoSinglelineWhitespaceBeforeSemicolonsFixer::class);
142-
143-
$services->set(NoWhitespaceBeforeCommaInArrayFixer::class);
144-
145-
$services->set(WhitespaceAfterCommaInArrayFixer::class);
146-
147-
$services->set(PhpdocToReturnTypeFixer::class);
148-
149-
$services->set(FullyQualifiedStrictTypesFixer::class);
150-
151-
$services->set(NoSuperfluousPhpdocTagsFixer::class);
152-
153-
$services->set(PhpdocLineSpanFixer::class)
154-
->call('configure', [['property' => 'single']]);
155-
156-
$services->set(DisallowYodaComparisonSniff::class);
157-
};
118+
]
119+
)
120+
->withConfiguredRule(
121+
PhpdocLineSpanFixer::class,
122+
['property' => 'single']
123+
)
124+
->withConfiguredRule(
125+
ClassAttributesSeparationFixer::class,
126+
['elements' => ['property' => 'none', 'method' => 'one', 'const' => 'none']]
127+
);

src/Api/Extensions/ContentExtension.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
use Bolt\Entity\Content;
1212
use Bolt\Entity\Field;
1313
use Bolt\Enum\Statuses;
14-
use Doctrine\ORM\Query\Expr\Join;
1514
use Doctrine\ORM\QueryBuilder;
1615
use Tightenco\Collect\Support\Collection;
1716

src/Cache/CachingTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ private function getTags(string $contentTypeSlug): array
106106
{
107107
$tags = explode(',', $contentTypeSlug);
108108

109-
$tags = array_map(function($t) {
109+
$tags = array_map(function ($t) {
110110
return preg_replace('/[^\pL\d,]+/u', '', $t);
111111
}, $tags);
112112

src/Cache/ContentToArrayCacher.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ protected function contentToArray(Content $content, string $locale = ''): array
1818

1919
return $this->execute([parent::class, __FUNCTION__], [$content, $locale]);
2020
}
21-
}
21+
}

src/Canonical.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ public function getScheme(): string
147147
*/
148148
public function setScheme(string $scheme): void
149149
{
150-
$this->scheme = trim($scheme, ':/');
150+
$this->scheme = mb_trim($scheme, ':/');
151151
}
152152

153153
public function getPort(): ?int

src/Collection/DeepCollection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function isKeyEmpty($key): bool
2828
return $this->has($key) && (
2929
($this->get($key) instanceof Collection && $this->get($key)->isEmpty())
3030
|| empty($this->get($key))
31-
);
31+
);
3232
}
3333

3434
public function isKeyNotEmpty($key): bool

src/Command/ExtensionsConfigureCommand.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,11 +173,13 @@ private function getExtensionServicesPath(string $path = '*'): string
173173

174174
private function getExtensionConfigPath(string $namespace, string $name): string
175175
{
176-
return sprintf('%s/config/extensions/%s%s%s.yaml',
176+
return sprintf(
177+
'%s/config/extensions/%s%s%s.yaml',
177178
$this->projectDir,
178179
$namespace,
179180
(! empty($name) ? '-' : ''),
180-
$name);
181+
$name
182+
);
181183
}
182184

183185
private function getPackagePath(BaseExtension $package): string

src/Command/ResetPasswordCommand.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,12 @@ class ResetPasswordCommand extends Command
3838
/** @var UserRepository */
3939
private $userRepository;
4040

41-
public function __construct(EntityManagerInterface $em, UserPasswordHasherInterface $passwordHasher,
42-
UserRepository $userRepository, ValidatorInterface $validator)
43-
{
41+
public function __construct(
42+
EntityManagerInterface $em,
43+
UserPasswordHasherInterface $passwordHasher,
44+
UserRepository $userRepository,
45+
ValidatorInterface $validator
46+
) {
4447
parent::__construct();
4548

4649
$this->entityManager = $em;
@@ -62,7 +65,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
6265
$io = new SymfonyStyle($input, $output);
6366
$username = $input->getArgument('username');
6467

65-
/** @var User|null */
68+
/** @var User|null $user */
6669
$user = $this->userRepository->findOneBy(['username' => $username]);
6770

6871
if ($user === null) {

0 commit comments

Comments
 (0)