Skip to content

Commit 551fd7a

Browse files
committed
Merge branch 'develop' of github.com:magento/magento-coding-standard into AC-1059_move-phpcompatibility-rules-from-magento-tests
2 parents 168882e + 6c6c082 commit 551fd7a

10 files changed

+99
-41
lines changed

Magento2/Sniffs/Classes/DiscouragedDependenciesSniff.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616
class DiscouragedDependenciesSniff implements Sniff
1717
{
18-
const CONSTRUCT_METHOD_NAME = '__construct';
18+
private const CONSTRUCT_METHOD_NAME = '__construct';
1919

2020
/**
2121
* String representation of warning.

Magento2/Sniffs/Html/HtmlDirectiveSniff.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@
1616
*/
1717
class HtmlDirectiveSniff implements Sniff
1818
{
19-
const CONSTRUCTION_DEPEND_PATTERN = '/{{depend\s*(.*?)}}(.*?){{\\/depend\s*}}/si';
20-
const CONSTRUCTION_IF_PATTERN = '/{{if\s*(.*?)}}(.*?)({{else}}(.*?))?{{\\/if\s*}}/si';
21-
const LOOP_PATTERN = '/{{for(?P<loopItem>.*? )(in)(?P<loopData>.*?)}}(?P<loopBody>.*?){{\/for}}/si';
22-
const CONSTRUCTION_PATTERN = '/{{([a-z]{0,10})(.*?)}}(?:(.*?)(?:{{\/(?:\\1)}}))?/si';
19+
private const CONSTRUCTION_DEPEND_PATTERN = '/{{depend\s*(.*?)}}(.*?){{\\/depend\s*}}/si';
20+
private const CONSTRUCTION_IF_PATTERN = '/{{if\s*(.*?)}}(.*?)({{else}}(.*?))?{{\\/if\s*}}/si';
21+
private const LOOP_PATTERN = '/{{for(?P<loopItem>.*? )(in)(?P<loopData>.*?)}}(?P<loopBody>.*?){{\/for}}/si';
22+
private const CONSTRUCTION_PATTERN = '/{{([a-z]{0,10})(.*?)}}(?:(.*?)(?:{{\/(?:\\1)}}))?/si';
2323

2424
/**
2525
* @var array

Magento2/Sniffs/Less/CommentLevelsSniff.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@
1919
*/
2020
class CommentLevelsSniff implements Sniff
2121
{
22-
const COMMENT_STRING = '//';
22+
private const COMMENT_STRING = '//';
2323

24-
const FIRST_LEVEL_COMMENT = '_____________________________________________';
24+
private const FIRST_LEVEL_COMMENT = '_____________________________________________';
2525

26-
const SECOND_LEVEL_COMMENT = '--';
26+
private const SECOND_LEVEL_COMMENT = '--';
2727

2828
/**
2929
* @var array

Magento2/Sniffs/Less/TokenizerSymbolsInterface.php

+9-9
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,18 @@
1010
*/
1111
interface TokenizerSymbolsInterface
1212
{
13-
const TOKENIZER_CSS = 'CSS';
13+
public const TOKENIZER_CSS = 'CSS';
1414

1515
/**#@+
1616
* Symbols for usage into Sniffers
1717
*/
18-
const BITWISE_AND = '&';
19-
const COLON = ';';
20-
const OPEN_PARENTHESIS = '(';
21-
const CLOSE_PARENTHESIS = ')';
22-
const NEW_LINE = "\n";
23-
const WHITESPACE = ' ';
24-
const DOUBLE_WHITESPACE = ' ';
25-
const INDENT_SPACES = ' ';
18+
public const BITWISE_AND = '&';
19+
public const COLON = ';';
20+
public const OPEN_PARENTHESIS = '(';
21+
public const CLOSE_PARENTHESIS = ')';
22+
public const NEW_LINE = "\n";
23+
public const WHITESPACE = ' ';
24+
public const DOUBLE_WHITESPACE = ' ';
25+
public const INDENT_SPACES = ' ';
2626
/**#@-*/
2727
}

Magento2/Sniffs/Less/ZeroUnitsSniff.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919
*/
2020
class ZeroUnitsSniff implements Sniff
2121
{
22-
const CSS_PROPERTY_UNIT_PX = 'px';
23-
const CSS_PROPERTY_UNIT_EM = 'em';
24-
const CSS_PROPERTY_UNIT_REM = 'rem';
22+
private const CSS_PROPERTY_UNIT_PX = 'px';
23+
private const CSS_PROPERTY_UNIT_EM = 'em';
24+
private const CSS_PROPERTY_UNIT_REM = 'rem';
2525

2626
/**
2727
* @var array

Magento2/Sniffs/Methods/DeprecatedModelMethodSniff.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
*/
1414
class DeprecatedModelMethodSniff implements Sniff
1515
{
16-
const RESOURCE_METHOD = "getResource";
16+
private const RESOURCE_METHOD = "getResource";
1717

1818
/**
1919
* String representation of warning.

Magento2/Sniffs/PHP/ArrayAutovivificationSniff.php

+29-17
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ class ArrayAutovivificationSniff implements Sniff
2020
*
2121
* @var string
2222
*/
23-
private $warningMessage = 'Deprecated: Automatic conversion of false to array is deprecated.';
23+
private const WARNING_MESSAGE = 'Deprecated: Automatic conversion of false to array is deprecated.';
2424

2525
/**
26-
* Warning violation code.
26+
* Error violation code.
2727
*
2828
* @var string
2929
*/
30-
private $warningCode = 'Autovivification';
30+
private const WARNING_CODE = 'Autovivification';
3131

3232
/**
3333
* @inheritdoc
@@ -44,25 +44,37 @@ public function register(): array
4444
*/
4545
public function process(File $phpcsFile, $stackPtr): void
4646
{
47-
$positionSquareBracket = $phpcsFile->findNext(T_OPEN_SQUARE_BRACKET, $stackPtr, $stackPtr + 2);
47+
$openSquareBracketKey = $phpcsFile->findNext(T_OPEN_SQUARE_BRACKET, $stackPtr, $stackPtr + 2);
4848

49-
if ($positionSquareBracket) {
50-
$tokens = $phpcsFile->getTokens();
51-
$positionFunction = $phpcsFile->findPrevious(T_FUNCTION, $positionSquareBracket) ?: 0;
52-
$sliceLength = $stackPtr - $positionFunction;
53-
$sliceToken = array_slice(array_column($tokens, 'content'), $positionFunction, $sliceLength, true);
54-
$propertyTokenKey = array_keys($sliceToken, $tokens[$stackPtr]['content']);
49+
if (!$openSquareBracketKey) {
50+
return;
51+
}
52+
53+
$closeSquareBracketKey = $phpcsFile->findNext(T_CLOSE_SQUARE_BRACKET, $openSquareBracketKey);
54+
$hasEqualKey = $phpcsFile->findNext(T_EQUAL, $closeSquareBracketKey, $closeSquareBracketKey + 3);
55+
56+
if (!$hasEqualKey) {
57+
return;
58+
}
5559

56-
arsort($propertyTokenKey);
60+
$tokens = $phpcsFile->getTokens();
61+
$functionKey = $phpcsFile->findPrevious(T_FUNCTION, $openSquareBracketKey) ?: 0;
62+
$sliceToken = array_slice(array_column($tokens, 'content'), $functionKey, $stackPtr - $functionKey, true);
63+
$propertyTokenKey = array_keys($sliceToken, $tokens[$stackPtr]['content']);
5764

58-
foreach ($propertyTokenKey as $tokenKey) {
59-
if ($tokens[$tokenKey + 2]['content'] === '=') {
60-
if ($tokens[$tokenKey + 4]['content'] != 'false') {
61-
return;
62-
}
65+
arsort($propertyTokenKey);
6366

64-
$phpcsFile->addWarning($this->warningMessage, $positionSquareBracket, $this->warningCode);
67+
foreach ($propertyTokenKey as $propertyKey) {
68+
$positionEqualKey = $phpcsFile->findNext(T_EQUAL, $propertyKey, $propertyKey + 3);
69+
70+
if ($positionEqualKey) {
71+
$falseKey = $phpcsFile->findNext(T_FALSE, $positionEqualKey, $positionEqualKey + 3);
72+
73+
if (!($falseKey && $phpcsFile->findNext(T_SEMICOLON, $falseKey, $falseKey + 2))) {
74+
return;
6575
}
76+
77+
$phpcsFile->addWarning(self::WARNING_MESSAGE, $openSquareBracketKey, self::WARNING_CODE);
6678
}
6779
}
6880
}

Magento2/Tests/PHP/ArrayAutovivificationUnitTest.inc

+40
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,44 @@ class Avtovivification
5757

5858
return $productIds;
5959
}
60+
61+
/**
62+
* @return array
63+
*/
64+
public function testAvtovivification($testData)
65+
{
66+
$productIds = false !== $testData ? $testData : null;
67+
68+
$productIds[] = 'test_array_value';
69+
70+
return $productIds;
71+
}
72+
73+
/**
74+
* @param array $productIds
75+
*
76+
* @return array
77+
*/
78+
public function testWithParameterArray($productIds)
79+
{
80+
if (!empty($productIds['test_array_key'])) {
81+
$productIds['test_array_key'] = 'test_array_value';
82+
}
83+
84+
return $productIds;
85+
}
86+
87+
/**
88+
* @param false|array $productIds
89+
*
90+
* @return false|array
91+
*/
92+
public function testWithParameterFalse($productIds = false)
93+
{
94+
if ($productIds !== false) {
95+
$productIds[] = 'test_array_value';
96+
}
97+
98+
return $productIds;
99+
}
60100
}

Magento2/ruleset.xml

+4
Original file line numberDiff line numberDiff line change
@@ -701,6 +701,10 @@
701701
<rule ref="Squiz.WhiteSpace.SuperfluousWhitespace.EmptyLines">
702702
<severity>0</severity>
703703
</rule>
704+
<rule ref="PSR12.Properties.ConstantVisibility">
705+
<severity>6</severity>
706+
<type>warning</type>
707+
</rule>
704708

705709
<!-- Severity 5 warnings: PHPDoc formatting and commenting issues. -->
706710
<rule ref="Magento2.Commenting.ClassAndInterfacePHPDocFormatting">

Magento2Framework/Tests/Header/CopyrightGraphQLUnitTest.php

+5-3
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,15 @@ public function getErrorList(): array
2222
*/
2323
public function getWarningList($testFile = ''): array
2424
{
25-
if ($testFile === 'CopyrightGraphQLUnitTest.1.inc' || $testFile === 'CopyrightGraphQLUnitTest.2.inc') {
25+
if ($testFile === 'CopyrightGraphQLUnitTest.1.graphqls' ||
26+
$testFile === 'CopyrightGraphQLUnitTest.2.graphqls') {
2627
return [];
2728
}
2829

29-
if ($testFile === 'CopyrightGraphQLUnitTest.3.inc' || $testFile === 'CopyrightGraphQLUnitTest.4.inc') {
30+
if ($testFile === 'CopyrightGraphQLUnitTest.3.graphqls' ||
31+
$testFile === 'CopyrightGraphQLUnitTest.4.graphqls') {
3032
return [
31-
1 => 1
33+
null => 1
3234
];
3335
}
3436

0 commit comments

Comments
 (0)