Skip to content

Commit f5c3db0

Browse files
committed
minor #234 Re-configure and run PHP-CS-Fixer (Kocal)
This PR was squashed before being merged into the 2.x branch. Discussion ---------- Re-configure and run PHP-CS-Fixer This PR synchronize our PHP-CS-Fixer configuration file with https://github.com/symfony/symfony/blob/7.2/.php-cs-fixer.dist.php, but with for some adaptation (for the header text). Commits ------- ed5f925 Re-configure and run PHP-CS-Fixer
2 parents 92a2a58 + ed5f925 commit f5c3db0

25 files changed

+103
-41
lines changed

.php-cs-fixer.dist.php

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,44 @@
11
<?php
22

3+
/*
4+
* This file is part of the Symfony WebpackEncoreBundle package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
312
if (!file_exists(__DIR__.'/src')) {
413
exit(0);
514
}
615

7-
$finder = (new PhpCsFixer\Finder())
8-
->in(__DIR__.'/src')
9-
->in(__DIR__.'/tests')
10-
;
16+
$fileHeaderComment = <<<'EOF'
17+
This file is part of the Symfony WebpackEncoreBundle package.
18+
19+
(c) Fabien Potencier <[email protected]>
20+
21+
For the full copyright and license information, please view the LICENSE
22+
file that was distributed with this source code.
23+
EOF;
1124

1225
return (new PhpCsFixer\Config())
13-
->setRules(array(
26+
// @see https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/pull/7777
27+
->setParallelConfig(PhpCsFixer\Runner\Parallel\ParallelConfigFactory::detect())
28+
->setRules([
29+
'@PHP71Migration' => true,
30+
'@PHPUnit75Migration:risky' => true,
1431
'@Symfony' => true,
1532
'@Symfony:risky' => true,
16-
'@PHPUnit75Migration:risky' => true,
1733
'protected_to_private' => false,
18-
'semicolon_after_instruction' => false,
19-
'header_comment' => [
20-
'header' => <<<EOF
21-
This file is part of the Symfony WebpackEncoreBundle package.
22-
(c) Fabien Potencier <[email protected]>
23-
For the full copyright and license information, please view the LICENSE
24-
file that was distributed with this source code.
25-
EOF
26-
]
27-
))
34+
'header_comment' => ['header' => $fileHeaderComment],
35+
'trailing_comma_in_multiline' => ['elements' => ['arrays', 'match', 'parameters']],
36+
])
2837
->setRiskyAllowed(true)
29-
->setFinder($finder)
38+
->setFinder(
39+
(new PhpCsFixer\Finder())
40+
->in([__DIR__.'/src', __DIR__.'/tests'])
41+
->append([__FILE__])
42+
)
43+
->setCacheFile('.php-cs-fixer.cache')
3044
;

src/Asset/EntrypointLookup.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
/*
44
* This file is part of the Symfony WebpackEncoreBundle package.
5+
*
56
* (c) Fabien Potencier <[email protected]>
7+
*
68
* For the full copyright and license information, please view the LICENSE
79
* file that was distributed with this source code.
810
*/
@@ -33,7 +35,7 @@ class EntrypointLookup implements EntrypointLookupInterface, IntegrityDataProvid
3335

3436
private $strictMode;
3537

36-
public function __construct(string $entrypointJsonPath, CacheItemPoolInterface $cache = null, string $cacheKey = null, bool $strictMode = true)
38+
public function __construct(string $entrypointJsonPath, ?CacheItemPoolInterface $cache = null, ?string $cacheKey = null, bool $strictMode = true)
3739
{
3840
$this->entrypointJsonPath = $entrypointJsonPath;
3941
$this->cache = $cache;
@@ -96,10 +98,10 @@ private function validateEntryName(string $entryName): void
9698
$withoutExtension = substr($entryName, 0, strrpos($entryName, '.'));
9799

98100
if (isset($entriesData['entrypoints'][$withoutExtension])) {
99-
throw new EntrypointNotFoundException(sprintf('Could not find the entry "%s". Try "%s" instead (without the extension).', $entryName, $withoutExtension));
101+
throw new EntrypointNotFoundException(\sprintf('Could not find the entry "%s". Try "%s" instead (without the extension).', $entryName, $withoutExtension));
100102
}
101103

102-
throw new EntrypointNotFoundException(sprintf('Could not find the entry "%s" in "%s". Found: %s.', $entryName, $this->entrypointJsonPath, implode(', ', array_keys($entriesData['entrypoints']))));
104+
throw new EntrypointNotFoundException(\sprintf('Could not find the entry "%s" in "%s". Found: %s.', $entryName, $this->entrypointJsonPath, implode(', ', array_keys($entriesData['entrypoints']))));
103105
}
104106
}
105107

@@ -121,17 +123,17 @@ private function getEntriesData(): array
121123
if (!$this->strictMode) {
122124
return [];
123125
}
124-
throw new \InvalidArgumentException(sprintf('Could not find the entrypoints file from Webpack: the file "%s" does not exist.', $this->entrypointJsonPath));
126+
throw new \InvalidArgumentException(\sprintf('Could not find the entrypoints file from Webpack: the file "%s" does not exist.', $this->entrypointJsonPath));
125127
}
126128

127129
$this->entriesData = json_decode(file_get_contents($this->entrypointJsonPath), true);
128130

129131
if (null === $this->entriesData) {
130-
throw new \InvalidArgumentException(sprintf('There was a problem JSON decoding the "%s" file', $this->entrypointJsonPath));
132+
throw new \InvalidArgumentException(\sprintf('There was a problem JSON decoding the "%s" file', $this->entrypointJsonPath));
131133
}
132134

133135
if (!isset($this->entriesData['entrypoints'])) {
134-
throw new \InvalidArgumentException(sprintf('Could not find an "entrypoints" key in the "%s" file', $this->entrypointJsonPath));
136+
throw new \InvalidArgumentException(\sprintf('Could not find an "entrypoints" key in the "%s" file', $this->entrypointJsonPath));
135137
}
136138

137139
if (isset($cached)) {

src/Asset/EntrypointLookupCollection.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
/*
44
* This file is part of the Symfony WebpackEncoreBundle package.
5+
*
56
* (c) Fabien Potencier <[email protected]>
7+
*
68
* For the full copyright and license information, please view the LICENSE
79
* file that was distributed with this source code.
810
*/
@@ -25,13 +27,13 @@ class EntrypointLookupCollection implements EntrypointLookupCollectionInterface
2527

2628
private $defaultBuildName;
2729

28-
public function __construct(ContainerInterface $buildEntrypoints, string $defaultBuildName = null)
30+
public function __construct(ContainerInterface $buildEntrypoints, ?string $defaultBuildName = null)
2931
{
3032
$this->buildEntrypoints = $buildEntrypoints;
3133
$this->defaultBuildName = $defaultBuildName;
3234
}
3335

34-
public function getEntrypointLookup(string $buildName = null): EntrypointLookupInterface
36+
public function getEntrypointLookup(?string $buildName = null): EntrypointLookupInterface
3537
{
3638
if (null === $buildName) {
3739
if (null === $this->defaultBuildName) {
@@ -42,7 +44,7 @@ public function getEntrypointLookup(string $buildName = null): EntrypointLookupI
4244
}
4345

4446
if (!$this->buildEntrypoints->has($buildName)) {
45-
throw new UndefinedBuildException(sprintf('The build "%s" is not configured', $buildName));
47+
throw new UndefinedBuildException(\sprintf('The build "%s" is not configured', $buildName));
4648
}
4749

4850
return $this->buildEntrypoints->get($buildName);

src/Asset/EntrypointLookupCollectionInterface.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
/*
44
* This file is part of the Symfony WebpackEncoreBundle package.
5+
*
56
* (c) Fabien Potencier <[email protected]>
7+
*
68
* For the full copyright and license information, please view the LICENSE
79
* file that was distributed with this source code.
810
*/
@@ -18,5 +20,5 @@ interface EntrypointLookupCollectionInterface
1820
*
1921
* @throws UndefinedBuildException if the build does not exist
2022
*/
21-
public function getEntrypointLookup(string $buildName = null): EntrypointLookupInterface;
23+
public function getEntrypointLookup(?string $buildName = null): EntrypointLookupInterface;
2224
}

src/Asset/EntrypointLookupInterface.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
/*
44
* This file is part of the Symfony WebpackEncoreBundle package.
5+
*
56
* (c) Fabien Potencier <[email protected]>
7+
*
68
* For the full copyright and license information, please view the LICENSE
79
* file that was distributed with this source code.
810
*/

src/Asset/IntegrityDataProviderInterface.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
/*
44
* This file is part of the Symfony WebpackEncoreBundle package.
5+
*
56
* (c) Fabien Potencier <[email protected]>
7+
*
68
* For the full copyright and license information, please view the LICENSE
79
* file that was distributed with this source code.
810
*/

src/Asset/TagRenderer.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
/*
44
* This file is part of the Symfony WebpackEncoreBundle package.
5+
*
56
* (c) Fabien Potencier <[email protected]>
7+
*
68
* For the full copyright and license information, please view the LICENSE
79
* file that was distributed with this source code.
810
*/
@@ -34,7 +36,7 @@ public function __construct(
3436
array $defaultAttributes = [],
3537
array $defaultScriptAttributes = [],
3638
array $defaultLinkAttributes = [],
37-
EventDispatcherInterface $eventDispatcher = null
39+
?EventDispatcherInterface $eventDispatcher = null,
3840
) {
3941
$this->entrypointLookupCollection = $entrypointLookupCollection;
4042
$this->packages = $packages;
@@ -46,7 +48,7 @@ public function __construct(
4648
$this->reset();
4749
}
4850

49-
public function renderWebpackScriptTags(string $entryName, string $packageName = null, string $entrypointName = null, array $extraAttributes = []): string
51+
public function renderWebpackScriptTags(string $entryName, ?string $packageName = null, ?string $entrypointName = null, array $extraAttributes = []): string
5052
{
5153
$entrypointName = $entrypointName ?: '_default';
5254
$scriptTags = [];
@@ -72,7 +74,7 @@ public function renderWebpackScriptTags(string $entryName, string $packageName =
7274
}
7375
$attributes = $event->getAttributes();
7476

75-
$scriptTags[] = sprintf(
77+
$scriptTags[] = \sprintf(
7678
'<script %s></script>',
7779
$this->convertArrayToAttributes($attributes)
7880
);
@@ -83,7 +85,7 @@ public function renderWebpackScriptTags(string $entryName, string $packageName =
8385
return implode('', $scriptTags);
8486
}
8587

86-
public function renderWebpackLinkTags(string $entryName, string $packageName = null, string $entrypointName = null, array $extraAttributes = []): string
88+
public function renderWebpackLinkTags(string $entryName, ?string $packageName = null, ?string $entrypointName = null, array $extraAttributes = []): string
8789
{
8890
$entrypointName = $entrypointName ?: '_default';
8991
$scriptTags = [];
@@ -110,7 +112,7 @@ public function renderWebpackLinkTags(string $entryName, string $packageName = n
110112
}
111113
$attributes = $event->getAttributes();
112114

113-
$scriptTags[] = sprintf(
115+
$scriptTags[] = \sprintf(
114116
'<link %s>',
115117
$this->convertArrayToAttributes($attributes)
116118
);
@@ -144,7 +146,7 @@ public function reset(): void
144146
];
145147
}
146148

147-
private function getAssetPath(string $assetPath, string $packageName = null): string
149+
private function getAssetPath(string $assetPath, ?string $packageName = null): string
148150
{
149151
if (null === $this->packages) {
150152
throw new \Exception('To render the script or link tags, run "composer require symfony/asset".');
@@ -175,7 +177,7 @@ static function ($key, $value) {
175177
return $key;
176178
}
177179

178-
return sprintf('%s="%s"', $key, htmlentities($value));
180+
return \sprintf('%s="%s"', $key, htmlentities($value));
179181
},
180182
array_keys($attributesMap),
181183
$attributesMap

src/CacheWarmer/EntrypointCacheWarmer.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
/*
44
* This file is part of the Symfony WebpackEncoreBundle package.
5+
*
56
* (c) Fabien Potencier <[email protected]>
7+
*
68
* For the full copyright and license information, please view the LICENSE
79
* file that was distributed with this source code.
810
*/
@@ -24,7 +26,7 @@ public function __construct(array $cacheKeys, string $phpArrayFile)
2426
parent::__construct($phpArrayFile);
2527
}
2628

27-
protected function doWarmUp(string $cacheDir, ArrayAdapter $arrayAdapter, string $buildDir = null): bool
29+
protected function doWarmUp(string $cacheDir, ArrayAdapter $arrayAdapter, ?string $buildDir = null): bool
2830
{
2931
foreach ($this->cacheKeys as $cacheKey => $path) {
3032
// If the file does not exist then just skip past this entry point.

src/DependencyInjection/Configuration.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
/*
44
* This file is part of the Symfony WebpackEncoreBundle package.
5+
*
56
* (c) Fabien Potencier <[email protected]>
7+
*
68
* For the full copyright and license information, please view the LICENSE
79
* file that was distributed with this source code.
810
*/

src/DependencyInjection/WebpackEncoreExtension.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
/*
44
* This file is part of the Symfony WebpackEncoreBundle package.
5+
*
56
* (c) Fabien Potencier <[email protected]>
7+
*
68
* For the full copyright and license information, please view the LICENSE
79
* file that was distributed with this source code.
810
*/
@@ -103,6 +105,6 @@ private function entrypointFactory(ContainerBuilder $container, string $name, st
103105

104106
private function getEntrypointServiceId(string $name): string
105107
{
106-
return sprintf('webpack_encore.entrypoint_lookup[%s]', $name);
108+
return \sprintf('webpack_encore.entrypoint_lookup[%s]', $name);
107109
}
108110
}

0 commit comments

Comments
 (0)