Skip to content

Commit 0ed5233

Browse files
committed
Merge branch 'main' into use_FCT_constants
2 parents 1875334 + 636bbba commit 0ed5233

15 files changed

+207
-92
lines changed

.dev-tools/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
"phpcbf || exit 0"
5555
],
5656
"infection": [
57-
"infection run --min-msi=100 --logger-github --no-progress --threads=16"
57+
"infection run"
5858
]
5959
}
6060
}

.dev-tools/composer.lock

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.dev-tools/infection.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
]
77
},
88
"timeout": 10,
9+
"threads": "max",
910
"logs": {
1011
"text": "php://stdout",
1112
"github": true,
@@ -194,5 +195,6 @@
194195
"While_": true,
195196
"YieldValue": true,
196197
"Yield_": true
197-
}
198+
},
199+
"minMsi": 100
198200
}

.dev-tools/src/InfectionConfigBuilder.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public function build(): array
4343
'$schema' => './vendor/infection/infection/resources/schema.json',
4444
'source' => ['directories' => ['../src']],
4545
'timeout' => 10,
46+
'threads' => 'max',
4647
'logs' => [
4748
'text' => 'php://stdout',
4849
'github' => true,
@@ -53,6 +54,7 @@ public function build(): array
5354
'customPath' => '../vendor/phpunit/phpunit/phpunit',
5455
],
5556
'mutators' => [],
57+
'minMsi' => 100,
5658
];
5759

5860
$mutators = \array_keys(ProfileList::ALL_MUTATORS);

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# CHANGELOG for PHP CS Fixer: custom fixers
22

3+
## v3.30.0
4+
- Update minimum PHP CS Fixer version to 3.82.0
5+
36
## v3.29.0
47
- Update minimum PHP CS Fixer version to 3.77.0
58

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
[![Latest stable version](https://img.shields.io/packagist/v/kubawerlos/php-cs-fixer-custom-fixers.svg?label=current%20version)](https://packagist.org/packages/kubawerlos/php-cs-fixer-custom-fixers)
66
[![PHP version](https://img.shields.io/packagist/php-v/kubawerlos/php-cs-fixer-custom-fixers.svg)](https://php.net)
77
[![License](https://img.shields.io/github/license/kubawerlos/php-cs-fixer-custom-fixers.svg)](LICENSE)
8-
![Tests](https://img.shields.io/badge/tests-3798-brightgreen.svg)
8+
![Tests](https://img.shields.io/badge/tests-3802-brightgreen.svg)
99
[![Downloads](https://img.shields.io/packagist/dt/kubawerlos/php-cs-fixer-custom-fixers.svg)](https://packagist.org/packages/kubawerlos/php-cs-fixer-custom-fixers)
1010

1111
[![CI status](https://github.com/kubawerlos/php-cs-fixer-custom-fixers/actions/workflows/ci.yaml/badge.svg)](https://github.com/kubawerlos/php-cs-fixer-custom-fixers/actions/workflows/ci.yaml)

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"php": "^7.4 || ^8.0",
1414
"ext-filter": "*",
1515
"ext-tokenizer": "*",
16-
"friendsofphp/php-cs-fixer": "^3.77"
16+
"friendsofphp/php-cs-fixer": "^3.82"
1717
},
1818
"require-dev": {
1919
"phpunit/phpunit": "^9.6.22 || 10.5.45 || ^11.5.7"

src/Fixer/PhpdocNoIncorrectVarAnnotationFixer.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public function fix(\SplFileInfo $file, Tokens $tokens): void
6767
// remove ones not having type at the beginning
6868
self::removeVarAnnotationNotMatchingPattern($tokens, $index, '/@var\\s+[\\?\\\\a-zA-Z_\\x7f-\\xff]/');
6969

70-
$nextIndex = $tokens->getNextMeaningfulToken($index);
70+
$nextIndex = self::getIndexAfterPhpDoc($tokens, $index);
7171

7272
if ($nextIndex === null) {
7373
self::removeVarAnnotationNotMatchingPattern($tokens, $index, null);
@@ -93,6 +93,18 @@ public function fix(\SplFileInfo $file, Tokens $tokens): void
9393
}
9494
}
9595

96+
private static function getIndexAfterPhpDoc(Tokens $tokens, int $index): ?int
97+
{
98+
$nextIndex = $tokens->getNextMeaningfulToken($index);
99+
100+
while ($nextIndex !== null && \defined('T_ATTRIBUTE') && $tokens[$nextIndex]->isGivenKind(\T_ATTRIBUTE)) {
101+
$nextIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_ATTRIBUTE, $nextIndex);
102+
$nextIndex = $tokens->getNextMeaningfulToken($nextIndex);
103+
}
104+
105+
return $nextIndex;
106+
}
107+
96108
private static function removeForClassElement(Tokens $tokens, int $index, int $propertyStartIndex): void
97109
{
98110
$variableIndex = $tokens->getTokenNotOfKindsSibling($propertyStartIndex, 1, [\T_NS_SEPARATOR, \T_STATIC, \T_STRING, \T_WHITESPACE, CT::T_ARRAY_TYPEHINT, CT::T_NULLABLE_TYPE, CT::T_TYPE_ALTERNATION, CT::T_TYPE_INTERSECTION, FCT::T_READONLY]);

src/Fixer/PhpdocNoSuperfluousParamFixer.php

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
use PhpCsFixer\FixerDefinition\CodeSample;
1616
use PhpCsFixer\FixerDefinition\FixerDefinition;
1717
use PhpCsFixer\FixerDefinition\FixerDefinitionInterface;
18-
use PhpCsFixer\Preg;
1918
use PhpCsFixer\Tokenizer\Token;
2019
use PhpCsFixer\Tokenizer\Tokens;
2120

@@ -122,7 +121,7 @@ private static function getFilteredDocComment(string $comment, array $paramNames
122121

123122
$foundParamNames = [];
124123
foreach ($doc->getAnnotationsOfType('param') as $annotation) {
125-
$paramName = self::getParamName($annotation->getContent());
124+
$paramName = $annotation->getVariableName();
126125

127126
if (\in_array($paramName, $paramNames, true) && !\in_array($paramName, $foundParamNames, true)) {
128127
$foundParamNames[] = $paramName;
@@ -134,18 +133,4 @@ private static function getFilteredDocComment(string $comment, array $paramNames
134133

135134
return $doc->getContent();
136135
}
137-
138-
private static function getParamName(string $annotation): ?string
139-
{
140-
Preg::match('/@param\\s+(?:[^\\$]+)?\\s*(\\$[a-zA-Z_\\x80-\\xff][a-zA-Z0-9_\\x80-\\xff]*)\\b/', $annotation, $matches);
141-
142-
if (!\array_key_exists(1, $matches)) {
143-
return null;
144-
}
145-
146-
// @phpstan-ignore function.alreadyNarrowedType
147-
\assert(\is_string($matches[1]));
148-
149-
return $matches[1];
150-
}
151136
}

src/Fixer/PromotedConstructorPropertyFixer.php

Lines changed: 41 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -167,15 +167,16 @@ private function promoteProperties(Tokens $tokens, int $classIndex, ConstructorA
167167
continue;
168168
}
169169

170-
$tokensToInsert = self::removePropertyAndReturnTokensToInsert($tokens, $propertyIndex);
170+
[$tokensToInsertBefore, $tokensToInsertAfter] = self::removePropertyAndReturnTokensToInsert($tokens, $propertyIndex);
171171

172172
self::renameVariable($tokens, $constructorAnalysis->getConstructorIndex(), $oldParameterName, $newParameterName);
173173

174174
self::removeAssignment($tokens, $constructorPromotableAssignments[$constructorParameterName]);
175175
$this->updateParameterSignature(
176176
$tokens,
177177
$constructorParameterIndex,
178-
$tokensToInsert,
178+
$tokensToInsertBefore,
179+
$tokensToInsertAfter,
179180
\substr($propertyType, 0, 1) === '?',
180181
);
181182
}
@@ -316,12 +317,12 @@ private static function getClassProperties(Tokens $tokens, int $classIndex): arr
316317
}
317318

318319
/**
319-
* @return list<Token>
320+
* @return array{list<Token>, list<Token>}
320321
*/
321322
private static function removePropertyAndReturnTokensToInsert(Tokens $tokens, ?int $propertyIndex): array
322323
{
323324
if ($propertyIndex === null) {
324-
return [new Token([\T_PUBLIC, 'public'])];
325+
return [[new Token([\T_PUBLIC, 'public'])], []];
325326
}
326327

327328
$visibilityIndex = $tokens->getPrevTokenOfKind($propertyIndex, [[\T_PRIVATE], [\T_PROTECTED], [\T_PUBLIC], [\T_VAR]]);
@@ -342,21 +343,28 @@ private static function removePropertyAndReturnTokensToInsert(Tokens $tokens, ?i
342343
$removeFrom++;
343344
}
344345

345-
$tokensToInsert = [];
346+
$tokensToInsertBefore = [];
346347
for ($index = $removeFrom; $index <= $visibilityIndex - 1; $index++) {
347-
$tokensToInsert[] = $tokens[$index];
348+
$tokensToInsertBefore[] = $tokens[$index];
348349
}
349350

350351
$visibilityToken = $tokens[$visibilityIndex];
351352
if ($tokens[$visibilityIndex]->isGivenKind(\T_VAR)) {
352353
$visibilityToken = new Token([\T_PUBLIC, 'public']);
353354
}
354-
$tokensToInsert[] = $visibilityToken;
355+
$tokensToInsertBefore[] = $visibilityToken;
356+
357+
$tokensToInsertAfter = [];
358+
if ($tokens[$removeTo]->isGivenKind(CT::T_PROPERTY_HOOK_BRACE_CLOSE)) {
359+
for ($index = $propertyIndex + 1; $index <= $removeTo; $index++) {
360+
$tokensToInsertAfter[] = $tokens[$index];
361+
}
362+
}
355363

356364
$tokens->clearRange($removeFrom + 1, $removeTo);
357365
TokenRemover::removeWithLinesIfPossible($tokens, $removeFrom);
358366

359-
return $tokensToInsert;
367+
return [$tokensToInsertBefore, $tokensToInsertAfter];
360368
}
361369

362370
/**
@@ -377,6 +385,10 @@ private static function getTokenOfKindSibling(Tokens $tokens, int $direction, in
377385
}
378386
}
379387

388+
if ($tokens[$index]->isGivenKind(CT::T_PROPERTY_HOOK_BRACE_CLOSE)) {
389+
break;
390+
}
391+
380392
$index += $direction;
381393
}
382394

@@ -412,31 +424,42 @@ private static function removeAssignment(Tokens $tokens, int $variableAssignment
412424
}
413425

414426
/**
415-
* @param list<Token> $tokensToInsert
427+
* @param list<Token> $tokensToInsertBefore
428+
* @param list<Token> $tokensToInsertAfter
416429
*/
417-
private function updateParameterSignature(Tokens $tokens, int $constructorParameterIndex, array $tokensToInsert, bool $makeTypeNullable): void
418-
{
430+
private function updateParameterSignature(
431+
Tokens $tokens,
432+
int $constructorParameterIndex,
433+
array $tokensToInsertBefore,
434+
array $tokensToInsertAfter,
435+
bool $makeTypeNullable
436+
): void {
419437
$prevElementIndex = $tokens->getPrevTokenOfKind($constructorParameterIndex, ['(', ',', [CT::T_ATTRIBUTE_CLOSE]]);
420438
\assert(\is_int($prevElementIndex));
421439

422440
$propertyStartIndex = $tokens->getNextMeaningfulToken($prevElementIndex);
423441
\assert(\is_int($propertyStartIndex));
424442

425-
foreach ($tokensToInsert as $index => $token) {
443+
foreach ($tokensToInsertBefore as $index => $token) {
426444
if ($token->isGivenKind(\T_PUBLIC)) {
427-
$tokensToInsert[$index] = new Token([CT::T_CONSTRUCTOR_PROPERTY_PROMOTION_PUBLIC, $token->getContent()]);
445+
$tokensToInsertBefore[$index] = new Token([CT::T_CONSTRUCTOR_PROPERTY_PROMOTION_PUBLIC, $token->getContent()]);
428446
} elseif ($token->isGivenKind(\T_PROTECTED)) {
429-
$tokensToInsert[$index] = new Token([CT::T_CONSTRUCTOR_PROPERTY_PROMOTION_PROTECTED, $token->getContent()]);
447+
$tokensToInsertBefore[$index] = new Token([CT::T_CONSTRUCTOR_PROPERTY_PROMOTION_PROTECTED, $token->getContent()]);
430448
} elseif ($token->isGivenKind(\T_PRIVATE)) {
431-
$tokensToInsert[$index] = new Token([CT::T_CONSTRUCTOR_PROPERTY_PROMOTION_PRIVATE, $token->getContent()]);
449+
$tokensToInsertBefore[$index] = new Token([CT::T_CONSTRUCTOR_PROPERTY_PROMOTION_PRIVATE, $token->getContent()]);
432450
}
433451
}
434-
$tokensToInsert[] = new Token([\T_WHITESPACE, ' ']);
452+
$tokensToInsertBefore[] = new Token([\T_WHITESPACE, ' ']);
435453

436454
if ($makeTypeNullable && !$tokens[$propertyStartIndex]->isGivenKind(CT::T_NULLABLE_TYPE)) {
437-
$tokensToInsert[] = new Token([CT::T_NULLABLE_TYPE, '?']);
455+
$tokensToInsertBefore[] = new Token([CT::T_NULLABLE_TYPE, '?']);
438456
}
439457

440-
$this->tokensToInsert[$propertyStartIndex] = $tokensToInsert;
458+
$this->tokensToInsert[$propertyStartIndex] = $tokensToInsertBefore;
459+
460+
$nextPropertyStartIndex = $tokens->getNextMeaningfulToken($propertyStartIndex);
461+
\assert(\is_int($nextPropertyStartIndex));
462+
463+
$this->tokensToInsert[$nextPropertyStartIndex + 1] = $tokensToInsertAfter;
441464
}
442465
}

0 commit comments

Comments
 (0)