Skip to content

Commit 66ee1ba

Browse files
authored
Merge pull request #2658 from teohhanhui/moar-php-cs-fixer-rules
Update php-cs-fixer to v2.14 and tighten CS
2 parents c1482be + 1f2aab6 commit 66ee1ba

File tree

40 files changed

+129
-98
lines changed

40 files changed

+129
-98
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ jobs:
108108
- *update-composer
109109
- run:
110110
name: Install PHP-CS-Fixer
111-
command: composer global require friendsofphp/php-cs-fixer:^2.13
111+
command: composer global require friendsofphp/php-cs-fixer:^2.14
112112
- *save-composer-cache-by-revision
113113
- *save-composer-cache-by-branch
114114
- run:

.php_cs.dist

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ HEADER;
1313

1414
$finder = PhpCsFixer\Finder::create()
1515
->in(__DIR__)
16-
->exclude('tests/Fixtures/app/var')
17-
;
16+
->exclude('tests/Fixtures/app/var');
1817

1918
return PhpCsFixer\Config::create()
2019
->setRiskyAllowed(true)
@@ -26,15 +25,13 @@ return PhpCsFixer\Config::create()
2625
'@Symfony' => true,
2726
'@Symfony:risky' => true,
2827
'align_multiline_comment' => [
29-
'comment_type' => 'phpdocs_only',
28+
'comment_type' => 'phpdocs_like',
3029
],
3130
'array_indentation' => true,
3231
'array_syntax' => [
3332
'syntax' => 'short',
3433
],
35-
'braces' => [
36-
'allow_single_line_closure' => true,
37-
],
34+
'comment_to_phpdoc' => true,
3835
'compact_nullable_typehint' => true,
3936
'doctrine_annotation_array_assignment' => [
4037
'operator' => '=',
@@ -43,10 +40,18 @@ return PhpCsFixer\Config::create()
4340
'after_array_assignments_equals' => false,
4441
'before_array_assignments_equals' => false,
4542
],
43+
'explicit_indirect_variable' => true,
44+
'fully_qualified_strict_types' => true,
4645
'header_comment' => [
4746
'header' => $header,
4847
'location' => 'after_open',
4948
],
49+
'logical_operators' => true,
50+
'multiline_comment_opening_closing' => true,
51+
'multiline_whitespace_before_semicolons' => [
52+
'strategy' => 'no_multi_line',
53+
],
54+
'no_alternative_syntax' => true,
5055
'no_extra_blank_lines' => [
5156
'tokens' => [
5257
'break',
@@ -60,22 +65,36 @@ return PhpCsFixer\Config::create()
6065
'use',
6166
],
6267
],
63-
'no_superfluous_phpdoc_tags' => true,
68+
'no_superfluous_elseif' => true,
69+
'no_superfluous_phpdoc_tags' => [
70+
'allow_mixed' => false,
71+
],
72+
'no_unset_cast' => true,
73+
'no_unset_on_property' => true,
6474
'no_useless_else' => true,
6575
'no_useless_return' => true,
6676
'ordered_imports' => [
67-
'importsOrder' => [
77+
'imports_order' => [
6878
'class',
6979
'function',
7080
'const',
7181
],
72-
'sortAlgorithm' => 'alpha',
82+
'sort_algorithm' => 'alpha',
7383
],
7484
'php_unit_method_casing' => [
7585
'case' => 'camel_case',
7686
],
87+
'php_unit_set_up_tear_down_visibility' => true,
88+
'php_unit_test_annotation' => [
89+
'style' => 'prefix',
90+
],
91+
'phpdoc_add_missing_param_annotation' => [
92+
'only_untyped' => true,
93+
],
7794
'phpdoc_order' => true,
7895
'phpdoc_trim_consecutive_blank_line_separation' => true,
96+
'phpdoc_var_annotation_correct_order' => true,
97+
'return_assignment' => true,
7998
'strict_comparison' => true,
8099
'strict_param' => true,
81100
'visibility_required' => [
@@ -87,5 +106,4 @@ return PhpCsFixer\Config::create()
87106
],
88107
'void_return' => false, // BC breaks; to be done in API Platform 3.0
89108
])
90-
->setFinder($finder)
91-
;
109+
->setFinder($finder);

features/bootstrap/DoctrineContext.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ public function thereAreDummyGroupObjects(int $nb)
209209
$dummyGroup = $this->buildDummyGroup();
210210

211211
foreach (['foo', 'bar', 'baz', 'qux'] as $property) {
212-
$dummyGroup->$property = ucfirst($property).' #'.$i;
212+
$dummyGroup->{$property} = ucfirst($property).' #'.$i;
213213
}
214214

215215
$this->manager->persist($dummyGroup);
@@ -228,7 +228,7 @@ public function thereAreDummyPropertyObjects(int $nb)
228228
$dummyGroup = $this->buildDummyGroup();
229229

230230
foreach (['foo', 'bar', 'baz'] as $property) {
231-
$dummyProperty->$property = $dummyGroup->$property = ucfirst($property).' #'.$i;
231+
$dummyProperty->{$property} = $dummyGroup->{$property} = ucfirst($property).' #'.$i;
232232
}
233233

234234
$dummyProperty->group = $dummyGroup;
@@ -247,15 +247,15 @@ public function thereAreDummyPropertyObjectsWithASharedGroup(int $nb)
247247
{
248248
$dummyGroup = $this->buildDummyGroup();
249249
foreach (['foo', 'bar', 'baz'] as $property) {
250-
$dummyGroup->$property = ucfirst($property).' #shared';
250+
$dummyGroup->{$property} = ucfirst($property).' #shared';
251251
}
252252
$this->manager->persist($dummyGroup);
253253

254254
for ($i = 1; $i <= $nb; ++$i) {
255255
$dummyProperty = $this->buildDummyProperty();
256256

257257
foreach (['foo', 'bar', 'baz'] as $property) {
258-
$dummyProperty->$property = ucfirst($property).' #'.$i;
258+
$dummyProperty->{$property} = ucfirst($property).' #'.$i;
259259
}
260260

261261
$dummyProperty->group = $dummyGroup;
@@ -275,7 +275,7 @@ public function thereAreDummyPropertyObjectsWithADifferentNumberRelatedGroups(in
275275
$dummyProperty = $this->buildDummyProperty();
276276

277277
foreach (['foo', 'bar', 'baz'] as $property) {
278-
$dummyProperty->$property = $dummyGroup->$property = ucfirst($property).' #'.$i;
278+
$dummyProperty->{$property} = $dummyGroup->{$property} = ucfirst($property).' #'.$i;
279279
}
280280

281281
$this->manager->persist($dummyGroup);
@@ -301,7 +301,7 @@ public function thereAreDummyPropertyObjectsWithGroups(int $nb, int $nb2)
301301
$dummyGroup = $this->buildDummyGroup();
302302

303303
foreach (['foo', 'bar', 'baz'] as $property) {
304-
$dummyProperty->$property = $dummyGroup->$property = ucfirst($property).' #'.$i;
304+
$dummyProperty->{$property} = $dummyGroup->{$property} = ucfirst($property).' #'.$i;
305305
}
306306

307307
$dummyProperty->group = $dummyGroup;
@@ -311,7 +311,7 @@ public function thereAreDummyPropertyObjectsWithGroups(int $nb, int $nb2)
311311
$dummyGroup = $this->buildDummyGroup();
312312

313313
foreach (['foo', 'bar', 'baz'] as $property) {
314-
$dummyGroup->$property = ucfirst($property).' #'.$i.$j;
314+
$dummyGroup->{$property} = ucfirst($property).' #'.$i.$j;
315315
}
316316

317317
$dummyProperty->groups[] = $dummyGroup;

features/bootstrap/HydraContext.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ public function assertPropertyIsNotRequired(string $propertyName, string $classN
222222
*
223223
* @throws \InvalidArgumentException
224224
*/
225-
private function getPropertyInfo(string $propertyName, string $className): \stdClass
225+
private function getPropertyInfo(string $propertyName, string $className): stdClass
226226
{
227227
foreach ($this->getProperties($className) as $property) {
228228
if ($property->{'hydra:title'} === $propertyName) {
@@ -238,7 +238,7 @@ private function getPropertyInfo(string $propertyName, string $className): \stdC
238238
*
239239
* @throws \InvalidArgumentException
240240
*/
241-
private function getOperation(string $method, string $className): \stdClass
241+
private function getOperation(string $method, string $className): stdClass
242242
{
243243
foreach ($this->getOperations($className) as $operation) {
244244
if ($operation->{'hydra:method'} === $method) {
@@ -270,7 +270,7 @@ private function getProperties(string $className): array
270270
*
271271
* @throws \InvalidArgumentException
272272
*/
273-
private function getClassInfo(string $className): \stdClass
273+
private function getClassInfo(string $className): stdClass
274274
{
275275
$json = $this->getLastJsonResponse();
276276

@@ -290,7 +290,7 @@ private function getClassInfo(string $className): \stdClass
290290
*
291291
* @throws \RuntimeException
292292
*/
293-
private function getLastJsonResponse(): \stdClass
293+
private function getLastJsonResponse(): stdClass
294294
{
295295
if (null === $decoded = json_decode($this->restContext->getMink()->getSession()->getDriver()->getContent())) {
296296
throw new \RuntimeException('JSON response seems to be invalid');

features/bootstrap/SwaggerContext.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ public function assertPropertyIsRequiredForOpenAPi(string $propertyName, string
149149
*
150150
* @throws \InvalidArgumentException
151151
*/
152-
private function getPropertyInfo(string $propertyName, string $className, int $specVersion = 2): \stdClass
152+
private function getPropertyInfo(string $propertyName, string $className, int $specVersion = 2): stdClass
153153
{
154154
foreach ($this->getProperties($className, $specVersion) as $classPropertyName => $property) {
155155
if ($classPropertyName === $propertyName) {
@@ -163,7 +163,7 @@ private function getPropertyInfo(string $propertyName, string $className, int $s
163163
/**
164164
* Gets all operations of a given class.
165165
*/
166-
private function getProperties(string $className, int $specVersion = 2): \stdClass
166+
private function getProperties(string $className, int $specVersion = 2): stdClass
167167
{
168168
return $this->getClassInfo($className, $specVersion)->{'properties'} ?? new \stdClass();
169169
}
@@ -173,7 +173,7 @@ private function getProperties(string $className, int $specVersion = 2): \stdCla
173173
*
174174
* @throws \InvalidArgumentException
175175
*/
176-
private function getClassInfo(string $className, int $specVersion = 2): \stdClass
176+
private function getClassInfo(string $className, int $specVersion = 2): stdClass
177177
{
178178
$nodes = 2 === $specVersion ? $this->getLastJsonResponse()->{'definitions'} : $this->getLastJsonResponse()->{'components'}->{'schemas'};
179179
foreach ($nodes as $classTitle => $classData) {
@@ -190,7 +190,7 @@ private function getClassInfo(string $className, int $specVersion = 2): \stdClas
190190
*
191191
* @throws \RuntimeException
192192
*/
193-
private function getLastJsonResponse(): \stdClass
193+
private function getLastJsonResponse(): stdClass
194194
{
195195
if (null === ($decoded = json_decode($this->restContext->getMink()->getSession()->getDriver()->getContent()))) {
196196
throw new \RuntimeException('JSON response seems to be invalid');

src/Annotation/ApiFilter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public function __construct($options = [])
6969
throw new InvalidArgumentException(sprintf('Property "%s" does not exist on the ApiFilter annotation.', $key));
7070
}
7171

72-
$this->$key = $value;
72+
$this->{$key} = $value;
7373
}
7474
}
7575
}

src/Annotation/AttributesHydratorTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ private function hydrateAttributes(array $values): void
5555
throw new InvalidArgumentException(sprintf('Unknown property "%s" on annotation "%s".', $key, self::class));
5656
}
5757

58-
(new \ReflectionProperty($this, $key))->isPublic() ? $this->$key = $value : $this->attributes += [Inflector::tableize($key) => $value];
58+
(new \ReflectionProperty($this, $key))->isPublic() ? $this->{$key} = $value : $this->attributes += [Inflector::tableize($key) => $value];
5959
}
6060
}
6161
}

src/Bridge/Doctrine/Common/Filter/SearchFilterTrait.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,8 @@ protected function normalizeValues(array $values, string $property): ?array
150150

151151
/**
152152
* When the field should be an integer, check that the given value is a valid one.
153+
*
154+
* @param mixed|null $type
153155
*/
154156
protected function hasValidValues(array $values, $type = null): bool
155157
{

src/Bridge/Doctrine/EventListener/PublishMercureUpdatesListener.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ private function storeEntityToPublish($entity, string $property): void
153153
return;
154154
}
155155

156-
$this->$property[$entity] = $value;
156+
$this->{$property}[$entity] = $value;
157157
}
158158

159159
/**

src/Bridge/Elasticsearch/DataProvider/Paginator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
use Symfony\Component\Serializer\Normalizer\AbstractNormalizer;
1919
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
2020

21-
/*
21+
/**
2222
* Paginator for Elasticsearch.
2323
*
2424
* @experimental

0 commit comments

Comments
 (0)