Skip to content

Commit b5c1496

Browse files
Merge branch 'develop' of https://github.com/magento/magento-coding-standard into parameters-defined-needs-no-docblock-except-complex
2 parents 17e120f + f5cf74f commit b5c1496

File tree

128 files changed

+1356
-584
lines changed

Some content is hidden

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

128 files changed

+1356
-584
lines changed

.github/workflows/php.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ jobs:
1515
php-version:
1616
- "8.1"
1717
- "8.2"
18+
- "8.3"
1819
dependencies:
1920
- "lowest"
2021
- "highest"
@@ -89,4 +90,4 @@ jobs:
8990
run: composer install
9091

9192
- name: Run rector
92-
run: vendor/bin/rector process Magento2 Magento2Framework PHP_CodeSniffer --dry-run --autoload-file vendor/squizlabs/php_codesniffer/autoload.php --autoload-file vendor/phpcompatibility/php-compatibility/PHPCSAliases.php
93+
run: vendor/bin/rector process Magento2 Magento2Framework PHP_CodeSniffer --dry-run --autoload-file vendor/squizlabs/php_codesniffer/autoload.php --autoload-file vendor/magento/php-compatibility-fork/PHPCSAliases.php

Magento2/Helpers/Assert.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2023 Adobe
4+
* All Rights Reserved.
55
*/
66
declare(strict_types=1);
77

Magento2/Helpers/Commenting/PHPDocFormattingValidator.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?php
22

33
/**
4-
* Copyright © Magento, Inc. All rights reserved.
5-
* See COPYING.txt for license details.
4+
* Copyright 2019 Adobe
5+
* All Rights Reserved.
66
*/
77
namespace Magento2\Helpers\Commenting;
88

Magento2/Helpers/Tokenizer/AbstractTokenizer.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2021 Adobe
4+
* All Rights Reserved.
55
*/
66
namespace Magento2\Helpers\Tokenizer;
77

Magento2/Helpers/Tokenizer/Parameter.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2021 Adobe
4+
* All Rights Reserved.
55
*/
66
namespace Magento2\Helpers\Tokenizer;
77

Magento2/Helpers/Tokenizer/Variable.php

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2021 Adobe
4+
* All Rights Reserved.
55
*/
6-
76
namespace Magento2\Helpers\Tokenizer;
87

98
/**

Magento2/Rector/Src/AddArrayAccessInterfaceReturnTypes.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
use PhpParser\Node;
1111
use PhpParser\Node\Stmt\Class_;
12-
use Rector\Core\Rector\AbstractRector;
12+
use Rector\Rector\AbstractRector;
1313
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
1414
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
1515

Magento2/Rector/Src/ReplaceMbStrposNullLimit.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
use PhpParser\Node;
1111
use PhpParser\Node\Expr\FuncCall;
1212
use PhpParser\Node\Scalar\LNumber;
13-
use Rector\Core\Rector\AbstractRector;
13+
use Rector\Rector\AbstractRector;
1414
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
1515
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
1616

Magento2/Rector/Src/ReplaceNewDateTimeNull.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
use PhpParser\Node;
1111
use PhpParser\Node\Expr\New_;
1212
use PhpParser\Node\Scalar\String_;
13-
use Rector\Core\Rector\AbstractRector;
13+
use Rector\Rector\AbstractRector;
1414
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
1515
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
1616

Magento2/Rector/Src/ReplacePregSplitNullLimit.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
use PhpParser\Node;
1111
use PhpParser\Node\Expr\ConstFetch;
1212
use PhpParser\Node\Expr\FuncCall;
13-
use Rector\Core\Rector\AbstractRector;
13+
use Rector\Rector\AbstractRector;
1414
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
1515
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
1616

Magento2/Sniffs/Annotation/AnnotationFormatValidator.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2021 Adobe
4+
* All Rights Reserved.
55
*/
66
declare(strict_types=1);
77

Magento2/Sniffs/Annotation/MethodAnnotationStructureSniff.php

+26-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2021 Adobe
4+
* All Rights Reserved.
55
*/
66
declare(strict_types=1);
77

@@ -51,13 +51,33 @@ public function register()
5151
public function process(File $phpcsFile, $stackPtr)
5252
{
5353
$tokens = $phpcsFile->getTokens();
54-
$commentStartPtr = $phpcsFile->findPrevious(T_DOC_COMMENT_OPEN_TAG, ($stackPtr), 0);
55-
$commentEndPtr = $phpcsFile->findPrevious(T_DOC_COMMENT_CLOSE_TAG, ($stackPtr), 0);
56-
if (!$commentStartPtr) {
57-
$phpcsFile->addError('Comment block is missing', $stackPtr, 'MethodArguments');
54+
$commentEndPtr = $stackPtr;
55+
$tokensToFind = [
56+
\T_SEMICOLON,
57+
\T_OPEN_CURLY_BRACKET,
58+
\T_CLOSE_CURLY_BRACKET,
59+
\T_ATTRIBUTE_END,
60+
\T_DOC_COMMENT_CLOSE_TAG
61+
];
62+
63+
do {
64+
$commentEndPtr = $phpcsFile->findPrevious($tokensToFind, $commentEndPtr - 1);
65+
if ($commentEndPtr !== false
66+
&& $tokens[$commentEndPtr]['code'] === \T_ATTRIBUTE_END
67+
&& isset($tokens[$commentEndPtr]['attribute_opener'])
68+
) {
69+
$commentEndPtr = $tokens[$commentEndPtr]['attribute_opener'];
70+
}
71+
} while ($commentEndPtr !== false && !in_array($tokens[$commentEndPtr]['code'], $tokensToFind, true));
72+
73+
if ($commentEndPtr === false || $tokens[$commentEndPtr]['code'] !== \T_DOC_COMMENT_CLOSE_TAG) {
74+
$phpcsFile->addError('Comment block is missing', $stackPtr, 'NoCommentBlock');
5875
return;
5976
}
6077

78+
$commentStartPtr = $tokens[$commentEndPtr]['comment_opener']
79+
?? $phpcsFile->findPrevious(T_DOC_COMMENT_OPEN_TAG, $commentEndPtr - 1);
80+
6181
if ($this->PHPDocFormattingValidator->hasDeprecatedWellFormatted($commentStartPtr, $tokens) !== true) {
6282
$phpcsFile->addWarning(
6383
'Motivation behind the added @deprecated tag MUST be explained. '

Magento2/Sniffs/Annotation/MethodArgumentsSniff.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2021 Adobe
4+
* All Rights Reserved.
55
*/
66
declare(strict_types=1);
77

Magento2/Sniffs/Classes/AbstractApiSniff.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2019 Adobe
4+
* All Rights Reserved.
55
*/
66
namespace Magento2\Sniffs\Classes;
77

Magento2/Sniffs/Classes/DiscouragedDependenciesSniff.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2019 Adobe
4+
* All Rights Reserved.
55
*/
66
namespace Magento2\Sniffs\Classes;
77

Magento2/Sniffs/CodeAnalysis/EmptyBlockSniff.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2018 Adobe
4+
* All Rights Reserved.
55
*/
66
namespace Magento2\Sniffs\CodeAnalysis;
77

Magento2/Sniffs/Commenting/ClassAndInterfacePHPDocFormattingSniff.php

+42-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?php
22

33
/**
4-
* Copyright © Magento, Inc. All rights reserved.
5-
* See COPYING.txt for license details.
4+
* Copyright 2019 Adobe
5+
* All Rights Reserved.
66
*/
77
namespace Magento2\Sniffs\Commenting;
88

@@ -63,15 +63,29 @@ public function process(File $phpcsFile, $stackPtr)
6363
return;
6464
}
6565

66+
$commentCloserPtr = $tokens[$commentStartPtr]['comment_closer'];
67+
6668
if ($this->PHPDocFormattingValidator->providesMeaning($namePtr, $commentStartPtr, $tokens) !== true) {
67-
$phpcsFile->addWarning(
69+
$fix = $phpcsFile->addFixableWarning(
6870
sprintf(
6971
'%s description must contain meaningful information beyond what its name provides or be removed.',
7072
ucfirst($tokens[$stackPtr]['content'])
7173
),
7274
$stackPtr,
7375
'InvalidDescription'
7476
);
77+
78+
if ($fix) {
79+
for ($i = $commentStartPtr; $i <= $commentCloserPtr; $i++) {
80+
$phpcsFile->fixer->replaceToken($i, '');
81+
}
82+
83+
if ($tokens[$commentStartPtr - 1]['code'] === T_WHITESPACE
84+
&& $tokens[$commentCloserPtr + 1]['code'] === T_WHITESPACE
85+
) {
86+
$phpcsFile->fixer->replaceToken($commentCloserPtr + 1, '');
87+
}
88+
}
7589
}
7690

7791
if ($this->PHPDocFormattingValidator->hasDeprecatedWellFormatted($commentStartPtr, $tokens) !== true) {
@@ -105,11 +119,35 @@ private function validateTags(File $phpcsFile, $commentStartPtr, $tokens)
105119
}
106120

107121
if (in_array($tokens[$i]['content'], $this->forbiddenTags) === true) {
108-
$phpcsFile->addWarning(
122+
$fix = $phpcsFile->addFixableWarning(
109123
sprintf('Tag %s MUST NOT be used.', $tokens[$i]['content']),
110124
$i,
111125
'ForbiddenTags'
112126
);
127+
128+
if ($fix) {
129+
for ($j = $i - 1; $j > $commentStartPtr; $j--) {
130+
if (!in_array($tokens[$j]['code'], [T_DOC_COMMENT_STAR, T_DOC_COMMENT_WHITESPACE], true)) {
131+
break;
132+
}
133+
134+
if ($tokens[$j]['code'] === T_DOC_COMMENT_WHITESPACE && $tokens[$j]['content'] === "\n") {
135+
break;
136+
}
137+
138+
$phpcsFile->fixer->replaceToken($j, '');
139+
}
140+
141+
$phpcsFile->fixer->replaceToken($i, '');
142+
143+
for ($j = $i + 1; $j < $commentCloserPtr; $j++) {
144+
$phpcsFile->fixer->replaceToken($j, '');
145+
146+
if ($tokens[$j]['code'] === T_DOC_COMMENT_WHITESPACE && $tokens[$j]['content'] === "\n") {
147+
break;
148+
}
149+
}
150+
}
113151
}
114152
}
115153

Magento2/Sniffs/Commenting/ClassPropertyPHPDocFormattingSniff.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2019 Adobe
4+
* All Rights Reserved.
55
*/
66
declare(strict_types=1);
77

@@ -32,6 +32,7 @@ class ClassPropertyPHPDocFormattingSniff extends AbstractVariableSniff
3232
T_NULLABLE,
3333
T_BITWISE_AND,
3434
T_TYPE_UNION,
35+
T_READONLY,
3536
];
3637

3738
/**

Magento2/Sniffs/Commenting/ConstantsPHPDocFormattingSniff.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2019 Adobe
4+
* All Rights Reserved.
55
*/
66
namespace Magento2\Sniffs\Commenting;
77

Magento2/Sniffs/Exceptions/DirectThrowSniff.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2018 Adobe
4+
* All Rights Reserved.
55
*/
66
namespace Magento2\Sniffs\Exceptions;
77

Magento2/Sniffs/Exceptions/ThrowCatchSniff.php

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2019 Adobe
4+
* All Rights Reserved.
55
*/
6-
76
namespace Magento2\Sniffs\Exceptions;
87

98
use function array_slice;

Magento2/Sniffs/Exceptions/TryProcessSystemResourcesSniff.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2019 Adobe
4+
* All Rights Reserved.
55
*/
66
namespace Magento2\Sniffs\Exceptions;
77

Magento2/Sniffs/Functions/DiscouragedFunctionSniff.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2018 Adobe
4+
* All Rights Reserved.
55
*/
66
namespace Magento2\Sniffs\Functions;
77

@@ -104,6 +104,7 @@ class DiscouragedFunctionSniff extends ForbiddenFunctionsSniff
104104
'^parsekit_compile_string$' => null,
105105
'^pathinfo$' => 'Magento\Framework\Filesystem\Io\File::getPathInfo',
106106
'^pcntl_.*$' => null,
107+
'^posix_isatty$' => 'stream_isatty',
107108
'^posix_.*$' => null,
108109
'^pfpro_.*$' => null,
109110
'^pfsockopen$' => null,

Magento2/Sniffs/Functions/FunctionsDeprecatedWithoutArgumentSniff.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2021 Adobe
4+
* All Rights Reserved.
55
*/
66
declare(strict_types=1);
77

Magento2/Sniffs/Functions/StaticFunctionSniff.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2019 Adobe
4+
* All Rights Reserved.
55
*/
66
namespace Magento2\Sniffs\Functions;
77

Magento2/Sniffs/GraphQL/AbstractGraphQLSniff.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2019 Adobe
4+
* All Rights Reserved.
55
*/
66
namespace Magento2\Sniffs\GraphQL;
77

Magento2/Sniffs/GraphQL/ValidArgumentNameSniff.php

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2019 Adobe
4+
* All Rights Reserved.
55
*/
6-
76
namespace Magento2\Sniffs\GraphQL;
87

98
use GraphQL\Error\SyntaxError;

0 commit comments

Comments
 (0)