Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit e1621af

Browse files
committedJan 16, 2023
Update codebase for new ruleset with phpcbf
1 parent bdc663c commit e1621af

38 files changed

+187
-96
lines changed
 

‎Magento2/Helpers/Commenting/PHPDocFormattingValidator.php

+6-4
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,12 @@ public function hasDeprecatedWellFormatted($commentStartPtr, $tokens)
123123
}
124124
$seePtr = $this->getTagPosition('@see', $commentStartPtr, $tokens);
125125
if ($seePtr === -1) {
126-
if (preg_match(
127-
"/This [a-zA-Z]* will be removed in version \d.\d.\d without replacement/",
128-
$tokens[$deprecatedPtr + 2]['content']
129-
)) {
126+
if (
127+
preg_match(
128+
"/This [a-zA-Z]* will be removed in version \d.\d.\d without replacement/",
129+
$tokens[$deprecatedPtr + 2]['content']
130+
)
131+
) {
130132
return true;
131133
}
132134
return false;

‎Magento2/Helpers/PHPCSUtils/TestUtils/UtilityMethodTestCase.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,8 @@ public static function resetTestFile()
331331
public static function usesPhp8NameTokens()
332332
{
333333
$version = Helper::getVersion();
334-
if ((\version_compare(\PHP_VERSION_ID, '80000', '>=') === true
334+
if (
335+
(\version_compare(\PHP_VERSION_ID, '80000', '>=') === true
335336
&& \version_compare($version, '3.5.7', '<') === true)
336337
|| \version_compare($version, '4.0.0', '>=') === true
337338
) {

‎Magento2/Helpers/PHPCSUtils/Utils/Conditions.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ public static function getCondition(File $phpcsFile, $stackPtr, $types = [], $fi
8686
}
8787

8888
foreach ($conditions as $ptr => $type) {
89-
if (isset($tokens[$ptr]) === true
89+
if (
90+
isset($tokens[$ptr]) === true
9091
&& \in_array($type, $types, true) === true
9192
) {
9293
// We found a token with the required type.

‎Magento2/Helpers/PHPCSUtils/Utils/FunctionDeclarations.php

+24-12
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ public static function getProperties(File $phpcsFile, $stackPtr)
8181
$tokens = $phpcsFile->getTokens();
8282
$arrowOpenClose = self::getArrowFunctionOpenClose($phpcsFile, $stackPtr);
8383

84-
if (isset($tokens[$stackPtr]) === false
84+
if (
85+
isset($tokens[$stackPtr]) === false
8586
|| ($tokens[$stackPtr]['code'] !== \T_FUNCTION
8687
&& $tokens[$stackPtr]['code'] !== \T_CLOSURE
8788
&& $arrowOpenClose === false)
@@ -169,7 +170,8 @@ public static function getProperties(File $phpcsFile, $stackPtr)
169170
break;
170171
}
171172

172-
if ($tokens[$i]['type'] === 'T_NULLABLE'
173+
if (
174+
$tokens[$i]['type'] === 'T_NULLABLE'
173175
// Handle nullable tokens in PHPCS < 2.8.0.
174176
|| (\defined('T_NULLABLE') === false && $tokens[$i]['code'] === \T_INLINE_THEN)
175177
// Handle nullable tokens with arrow functions in PHPCS 2.8.0 - 2.9.0.
@@ -242,14 +244,16 @@ public static function getArrowFunctionOpenClose(File $phpcsFile, $stackPtr)
242244
{
243245
$tokens = $phpcsFile->getTokens();
244246

245-
if (isset($tokens[$stackPtr]) === false
247+
if (
248+
isset($tokens[$stackPtr]) === false
246249
|| isset(Collections::arrowFunctionTokensBC()[$tokens[$stackPtr]['code']]) === false
247250
|| \strtolower($tokens[$stackPtr]['content']) !== 'fn'
248251
) {
249252
return false;
250253
}
251254

252-
if ($tokens[$stackPtr]['type'] === 'T_FN'
255+
if (
256+
$tokens[$stackPtr]['type'] === 'T_FN'
253257
&& isset($tokens[$stackPtr]['scope_closer']) === true
254258
&& \version_compare(Helper::getVersion(), '3.5.4', '>') === true
255259
) {
@@ -304,7 +308,8 @@ public static function getArrowFunctionOpenClose(File $phpcsFile, $stackPtr)
304308
true
305309
);
306310

307-
if ($arrow === false
311+
if (
312+
$arrow === false
308313
|| ($tokens[$arrow]['code'] !== \T_DOUBLE_ARROW && $tokens[$arrow]['type'] !== 'T_FN_ARROW')
309314
) {
310315
return false;
@@ -315,11 +320,13 @@ public static function getArrowFunctionOpenClose(File $phpcsFile, $stackPtr)
315320
$lastEndToken = null;
316321

317322
for ($scopeCloser = ($arrow + 1); $scopeCloser < $phpcsFile->numTokens; $scopeCloser++) {
318-
if (isset(self::$arrowFunctionEndTokens[$tokens[$scopeCloser]['code']]) === true
323+
if (
324+
isset(self::$arrowFunctionEndTokens[$tokens[$scopeCloser]['code']]) === true
319325
// BC for misidentified ternary else in some PHPCS versions.
320326
&& ($tokens[$scopeCloser]['code'] !== \T_COLON || $inTernary === false)
321327
) {
322-
if ($lastEndToken !== null
328+
if (
329+
$lastEndToken !== null
323330
&& $tokens[$scopeCloser]['code'] === \T_CLOSE_PARENTHESIS
324331
&& $tokens[$scopeCloser]['parenthesis_opener'] < $arrow
325332
) {
@@ -338,7 +345,8 @@ public static function getArrowFunctionOpenClose(File $phpcsFile, $stackPtr)
338345
}
339346
}
340347

341-
if (isset($tokens[$scopeCloser]['scope_closer']) === true
348+
if (
349+
isset($tokens[$scopeCloser]['scope_closer']) === true
342350
&& $tokens[$scopeCloser]['code'] !== \T_INLINE_ELSE
343351
&& $tokens[$scopeCloser]['code'] !== \T_END_HEREDOC
344352
&& $tokens[$scopeCloser]['code'] !== \T_END_NOWDOC
@@ -488,7 +496,8 @@ public static function getParameters(File $phpcsFile, $stackPtr)
488496
$tokens = $phpcsFile->getTokens();
489497
$arrowOpenClose = self::getArrowFunctionOpenClose($phpcsFile, $stackPtr);
490498

491-
if (isset($tokens[$stackPtr]) === false
499+
if (
500+
isset($tokens[$stackPtr]) === false
492501
|| ($tokens[$stackPtr]['code'] !== \T_FUNCTION
493502
&& $tokens[$stackPtr]['code'] !== \T_CLOSURE
494503
&& $tokens[$stackPtr]['code'] !== \T_USE
@@ -500,7 +509,8 @@ public static function getParameters(File $phpcsFile, $stackPtr)
500509
if ($tokens[$stackPtr]['code'] === \T_USE) {
501510
// This will work PHPCS 3.x/4.x cross-version without much overhead.
502511
$opener = $phpcsFile->findNext(Tokens::$emptyTokens, ($stackPtr + 1), null, true);
503-
if ($opener === false
512+
if (
513+
$opener === false
504514
|| $tokens[$opener]['code'] !== \T_OPEN_PARENTHESIS
505515
|| UseStatements::isClosureUse($phpcsFile, $stackPtr) === false
506516
) {
@@ -732,13 +742,15 @@ public static function isArrowFunction(File $phpcsFile, $stackPtr)
732742
return false;
733743
}
734744

735-
if ($tokens[$stackPtr]['type'] === 'T_FN'
745+
if (
746+
$tokens[$stackPtr]['type'] === 'T_FN'
736747
&& isset($tokens[$stackPtr]['scope_closer']) === true
737748
) {
738749
return true;
739750
}
740751

741-
if (isset(Collections::arrowFunctionTokensBC()[$tokens[$stackPtr]['code']]) === false
752+
if (
753+
isset(Collections::arrowFunctionTokensBC()[$tokens[$stackPtr]['code']]) === false
742754
|| \strtolower($tokens[$stackPtr]['content']) !== 'fn'
743755
) {
744756
return false;

‎Magento2/Helpers/PHPCSUtils/Utils/ObjectDeclarations.php

+10-5
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ public static function getName(File $phpcsFile, $stackPtr)
6868
{
6969
$tokens = $phpcsFile->getTokens();
7070

71-
if (isset($tokens[$stackPtr]) === false
71+
if (
72+
isset($tokens[$stackPtr]) === false
7273
|| ($tokens[$stackPtr]['code'] === \T_ANON_CLASS || $tokens[$stackPtr]['code'] === \T_CLOSURE)
7374
) {
7475
return null;
@@ -79,15 +80,17 @@ public static function getName(File $phpcsFile, $stackPtr)
7980
/*
8081
* BC: Work-around JS ES6 classes not being tokenized as T_CLASS in PHPCS < 3.0.0.
8182
*/
82-
if (isset($phpcsFile->tokenizerType)
83+
if (
84+
isset($phpcsFile->tokenizerType)
8385
&& $phpcsFile->tokenizerType === 'JS'
8486
&& $tokenCode === \T_STRING
8587
&& $tokens[$stackPtr]['content'] === 'class'
8688
) {
8789
$tokenCode = \T_CLASS;
8890
}
8991

90-
if ($tokenCode !== \T_FUNCTION
92+
if (
93+
$tokenCode !== \T_FUNCTION
9194
&& $tokenCode !== \T_CLASS
9295
&& $tokenCode !== \T_INTERFACE
9396
&& $tokenCode !== \T_TRAIT
@@ -97,7 +100,8 @@ public static function getName(File $phpcsFile, $stackPtr)
97100
);
98101
}
99102

100-
if ($tokenCode === \T_FUNCTION
103+
if (
104+
$tokenCode === \T_FUNCTION
101105
&& \strtolower($tokens[$stackPtr]['content']) !== 'function'
102106
) {
103107
// This is a function declared without the "function" keyword.
@@ -323,7 +327,8 @@ private static function findNames(File $phpcsFile, $stackPtr, $keyword, $allowed
323327
{
324328
$tokens = $phpcsFile->getTokens();
325329

326-
if (isset($tokens[$stackPtr]) === false
330+
if (
331+
isset($tokens[$stackPtr]) === false
327332
|| isset($allowedFor[$tokens[$stackPtr]['code']]) === false
328333
|| isset($tokens[$stackPtr]['scope_opener']) === false
329334
) {

‎Magento2/Helpers/PHPCSUtils/Utils/Parentheses.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ public static function getOwner(File $phpcsFile, $stackPtr)
8282
* {@internal As the 'parenthesis_owner' index is only set on parentheses, we didn't need to do any
8383
* input validation before, but now we do.}
8484
*/
85-
if (isset($tokens[$stackPtr]) === false
85+
if (
86+
isset($tokens[$stackPtr]) === false
8687
|| ($tokens[$stackPtr]['code'] !== \T_OPEN_PARENTHESIS
8788
&& $tokens[$stackPtr]['code'] !== \T_CLOSE_PARENTHESIS)
8889
) {
@@ -97,7 +98,8 @@ public static function getOwner(File $phpcsFile, $stackPtr)
9798
$skip[\T_BITWISE_AND] = \T_BITWISE_AND;
9899

99100
$prevNonEmpty = $phpcsFile->findPrevious($skip, ($stackPtr - 1), null, true);
100-
if ($prevNonEmpty !== false
101+
if (
102+
$prevNonEmpty !== false
101103
&& (isset(self::$extraParenthesesOwners[$tokens[$prevNonEmpty]['code']])
102104
// Possibly an arrow function.
103105
|| FunctionDeclarations::isArrowFunction($phpcsFile, $prevNonEmpty) === true)

‎Magento2/Helpers/PHPCSUtils/Utils/TextStrings.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ public static function getCompleteTextString(File $phpcsFile, $stackPtr, $stripQ
6262
);
6363
}
6464

65-
if ($tokens[$stackPtr]['code'] === \T_CONSTANT_ENCAPSED_STRING
65+
if (
66+
$tokens[$stackPtr]['code'] === \T_CONSTANT_ENCAPSED_STRING
6667
|| $tokens[$stackPtr]['code'] === \T_DOUBLE_QUOTED_STRING
6768
) {
6869
$prev = $phpcsFile->findPrevious(\T_WHITESPACE, ($stackPtr - 1), null, true);

‎Magento2/Helpers/PHPCSUtils/Utils/UseStatements.php

+6-3
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ public static function getType(File $phpcsFile, $stackPtr)
4646
{
4747
$tokens = $phpcsFile->getTokens();
4848

49-
if (isset($tokens[$stackPtr]) === false
49+
if (
50+
isset($tokens[$stackPtr]) === false
5051
|| $tokens[$stackPtr]['code'] !== \T_USE
5152
) {
5253
throw new RuntimeException('$stackPtr must be of type T_USE');
@@ -59,7 +60,8 @@ public static function getType(File $phpcsFile, $stackPtr)
5960
}
6061

6162
$prev = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($stackPtr - 1), null, true);
62-
if ($prev !== false && $tokens[$prev]['code'] === \T_CLOSE_PARENTHESIS
63+
if (
64+
$prev !== false && $tokens[$prev]['code'] === \T_CLOSE_PARENTHESIS
6365
&& Parentheses::isOwnerIn($phpcsFile, $prev, \T_CLOSURE) === true
6466
) {
6567
return 'closure';
@@ -245,7 +247,8 @@ public static function splitImportUseStatement(File $phpcsFile, $stackPtr)
245247
// Only when either at the start of the statement or at the start of a new sub within a group.
246248
if ($start === true && $fixedType === false) {
247249
$content = \strtolower($tokens[$i]['content']);
248-
if ($content === 'function'
250+
if (
251+
$content === 'function'
249252
|| $content === 'const'
250253
) {
251254
$type = $content;

‎Magento2/Sniffs/Annotation/AnnotationFormatValidator.php

+18-9
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ private function validateMultiLinesInShortDescription(
5757
$commentEndPtr
5858
);
5959
$shortPtrEndContent = $tokens[$shortPtrEnd]['content'];
60-
if (preg_match('/^[a-z]/', $shortPtrEndContent)
60+
if (
61+
preg_match('/^[a-z]/', $shortPtrEndContent)
6162
&& $shortPtrEnd != $shortPtr
6263
&& !preg_match('/\bSee\b/', $shortPtrEndContent)
6364
&& $tokens[$shortPtr]['line'] + 1 === $tokens[$shortPtrEnd]['line']
@@ -89,7 +90,8 @@ private function validateSpacingBetweenShortAndLongDescriptions(
8990
$commentEndPtr
9091
);
9192
$shortPtrEndContent = $tokens[$shortPtrEnd]['content'];
92-
if (preg_match('/^[A-Z]/', $shortPtrEndContent)
93+
if (
94+
preg_match('/^[A-Z]/', $shortPtrEndContent)
9395
&& !preg_match('/\bSee\b/', $shortPtrEndContent)
9496
&& $tokens[$shortPtr]['line'] + 1 === $tokens[$shortPtrEnd]['line']
9597
&& $tokens[$shortPtrEnd]['code'] !== T_DOC_COMMENT_TAG
@@ -199,7 +201,8 @@ public function validateTagsSpacingFormat(File $phpcsFile, int $commentStartPtr,
199201
$firstTagPtr = $tokens[$commentStartPtr]['comment_tags'][0];
200202
$commentTagPtrContent = $tokens[$firstTagPtr]['content'];
201203
$prevPtr = $phpcsFile->findPrevious($emptyTypeTokens, $firstTagPtr - 1, $commentStartPtr, true);
202-
if ($tokens[$firstTagPtr]['line'] !== $tokens[$prevPtr]['line'] + 2
204+
if (
205+
$tokens[$firstTagPtr]['line'] !== $tokens[$prevPtr]['line'] + 2
203206
&& strtolower($commentTagPtrContent) !== '@inheritdoc'
204207
) {
205208
$error = 'There must be exactly one blank line before tags';
@@ -237,8 +240,10 @@ public function validateTagGroupingFormat(File $phpcsFile, int $commentStartPtr)
237240
}
238241

239242
if (strtolower($tokens[$tag]['content']) === '@param') {
240-
if ($paramGroupId !== null
241-
&& $paramGroupId !== $groupId) {
243+
if (
244+
$paramGroupId !== null
245+
&& $paramGroupId !== $groupId
246+
) {
242247
$error = 'Parameter tags must be grouped together';
243248
$phpcsFile->addError($error, $tag, 'MethodAnnotation');
244249
}
@@ -271,8 +276,10 @@ public function validateTagAligningFormat(File $phpcsFile, int $commentStartPtr)
271276
}
272277
}
273278

274-
if (!$this->allTagsAligned($actualPositions)
275-
&& !$this->noneTagsAligned($actualPositions, $noAlignmentPositions)) {
279+
if (
280+
!$this->allTagsAligned($actualPositions)
281+
&& !$this->noneTagsAligned($actualPositions, $noAlignmentPositions)
282+
) {
276283
$phpcsFile->addError(
277284
'Tags visual alignment must be consistent',
278285
$stackPtr,
@@ -343,11 +350,13 @@ public function validateDescriptionFormatStructure(
343350
array $emptyTypeTokens
344351
): void {
345352
$tokens = $phpcsFile->getTokens();
346-
if (isset($tokens[$commentStartPtr]['comment_tags'][0])
353+
if (
354+
isset($tokens[$commentStartPtr]['comment_tags'][0])
347355
) {
348356
$commentTagPtr = $tokens[$commentStartPtr]['comment_tags'][0];
349357
$commentTagPtrContent = $tokens[$commentTagPtr]['content'];
350-
if ($tokens[$shortPtr]['code'] !== T_DOC_COMMENT_STRING
358+
if (
359+
$tokens[$shortPtr]['code'] !== T_DOC_COMMENT_STRING
351360
&& strtolower($commentTagPtrContent) !== '@inheritdoc'
352361
) {
353362
$error = 'Missing short description';

‎Magento2/Sniffs/Annotation/MethodArgumentsSniff.php

+14-7
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,8 @@ private function validateParameterAnnotationForArgumentExists(
246246
$stackPtr,
247247
'InheritDoc'
248248
);
249-
} elseif ($this->validateCommentBlockExists($phpcsFile, $previousCommentClosePtr, $stackPtr)
249+
} elseif (
250+
$this->validateCommentBlockExists($phpcsFile, $previousCommentClosePtr, $stackPtr)
250251
&& !$inheritdocAnnotationWithoutBracesExists
251252
) {
252253
$phpcsFile->addError(
@@ -352,7 +353,8 @@ private function validateParameterOrderIsCorrect(
352353
$parameterNames = $this->getMethodParameters($paramDefinitions);
353354
$paramDefinitionsCount = count($paramDefinitions);
354355
for ($ptr = 0; $ptr < $paramDefinitionsCount; $ptr++) {
355-
if (isset($methodArguments[$ptr]) && isset($parameterNames[$ptr])
356+
if (
357+
isset($methodArguments[$ptr]) && isset($parameterNames[$ptr])
356358
&& in_array($methodArguments[$ptr], $parameterNames)
357359
) {
358360
if ($methodArguments[$ptr] != $parameterNames[$ptr]) {
@@ -390,7 +392,8 @@ private function validateDuplicateAnnotationDoesnotExists(
390392
if (isset($paramDefinition['paramName'])) {
391393
$parameterContent = $paramDefinition['paramName'];
392394
foreach (array_slice($paramDefinitions, $i + 1) as $nextParamDefinition) {
393-
if (isset($nextParamDefinition['paramName'])
395+
if (
396+
isset($nextParamDefinition['paramName'])
394397
&& $parameterContent === $nextParamDefinition['paramName']
395398
) {
396399
$duplicateParameters[] = $parameterContent;
@@ -647,8 +650,10 @@ private function validateFormattingConsistency(
647650
? strrpos($paramContent, $paramDefinition['comment']) : null;
648651
}
649652
}
650-
if (!$this->allParamsAligned($argumentPositions, $commentPositions)
651-
&& !$this->noneParamsAligned($argumentPositions, $commentPositions, $paramDefinitions)) {
653+
if (
654+
!$this->allParamsAligned($argumentPositions, $commentPositions)
655+
&& !$this->noneParamsAligned($argumentPositions, $commentPositions, $paramDefinitions)
656+
) {
652657
$phpcsFile->addError(
653658
'Method arguments visual alignment must be consistent',
654659
$paramPointers[0],
@@ -688,8 +693,10 @@ private function noneParamsAligned(array $argumentPositions, array $commentPosit
688693
continue;
689694
}
690695
$paramName = $paramDefinitions[$index]['paramName'];
691-
if (($argumentPosition !== strlen($type) + 1) ||
692-
(isset($commentPosition) && ($commentPosition !== $argumentPosition + strlen($paramName) + 1))) {
696+
if (
697+
($argumentPosition !== strlen($type) + 1) ||
698+
(isset($commentPosition) && ($commentPosition !== $argumentPosition + strlen($paramName) + 1))
699+
) {
693700
$flag = false;
694701
break;
695702
}

0 commit comments

Comments
 (0)
Please sign in to comment.