Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 9dd071e

Browse filesBrowse files
authored
Merge pull request #129 from magento-commerce/develop
Develop to Master Version 16
2 parents ca25070 + 9cc2425 commit 9dd071e
Copy full SHA for 9dd071e
Expand file treeCollapse file tree

26 files changed

+635
-86
lines changed

‎.github/workflows/php.yml

Copy file name to clipboardExpand all lines: .github/workflows/php.yml
+17Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,20 @@ jobs:
7575

7676
- name: Run ESLint
7777
run: npm run eslint -- eslint/rules
78+
rector:
79+
runs-on: ubuntu-latest
80+
name: Rector tests
81+
82+
steps:
83+
- name: Setup node
84+
uses: actions/setup-node@v2
85+
with:
86+
node-version: '16'
87+
88+
- uses: actions/checkout@v2
89+
90+
- name: Install dependencies
91+
run: composer install
92+
93+
- name: Run rector
94+
run: vendor/bin/rector process Magento2 Magento2Framework PHP_CodeSniffer --dry-run --autoload-file vendor/squizlabs/php_codesniffer/autoload.php

‎Magento2/Sniffs/Annotation/MethodArgumentsSniff.php

Copy file name to clipboardExpand all lines: Magento2/Sniffs/Annotation/MethodArgumentsSniff.php
+31-15Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,23 @@ private function isTokenBeforeClosingCommentTagValid(string $type): bool
7070
private function validateCommentBlockExists(File $phpcsFile, int $previousCommentClosePtr, int $stackPtr): bool
7171
{
7272
$tokens = $phpcsFile->getTokens();
73+
$attributeFlag = false;
7374
for ($tempPtr = $previousCommentClosePtr + 1; $tempPtr < $stackPtr; $tempPtr++) {
75+
$tokenCode = $tokens[$tempPtr]['code'];
76+
77+
// Ignore attributes e.g. #[\ReturnTypeWillChange]
78+
if ($tokenCode === T_ATTRIBUTE_END) {
79+
$attributeFlag = false;
80+
continue;
81+
}
82+
if ($attributeFlag) {
83+
continue;
84+
}
85+
if ($tokenCode === T_ATTRIBUTE) {
86+
$attributeFlag = true;
87+
continue;
88+
}
89+
7490
if (!$this->isTokenBeforeClosingCommentTagValid($tokens[$tempPtr]['type'])) {
7591
return false;
7692
}
@@ -228,15 +244,15 @@ private function validateParameterAnnotationForArgumentExists(
228244
$phpcsFile->addError(
229245
'{@inheritdoc} does not import parameter annotation',
230246
$stackPtr,
231-
'MethodArguments'
247+
'InheritDoc'
232248
);
233249
} elseif ($this->validateCommentBlockExists($phpcsFile, $previousCommentClosePtr, $stackPtr)
234250
&& !$inheritdocAnnotationWithoutBracesExists
235251
) {
236252
$phpcsFile->addError(
237253
'Missing @param for argument in method annotation',
238254
$stackPtr,
239-
'MethodArguments'
255+
'ParamMissing'
240256
);
241257
}
242258
}
@@ -260,13 +276,13 @@ private function validateCommentBlockDoesnotHaveExtraParameterAnnotation(
260276
$phpcsFile->addError(
261277
'Extra @param found in method annotation',
262278
$stackPtr,
263-
'MethodArguments'
279+
'ExtraParam'
264280
);
265281
} elseif ($argumentsCount > 0 && $argumentsCount != $parametersCount && $parametersCount != 0) {
266282
$phpcsFile->addError(
267283
'@param is not found for one or more params in method annotation',
268284
$stackPtr,
269-
'MethodArguments'
285+
'ParamMissing'
270286
);
271287
}
272288
}
@@ -290,7 +306,7 @@ private function validateArgumentNameInParameterAnnotationExists(
290306
$parameterNames = $this->getMethodParameters($paramDefinitions);
291307
if (!in_array($methodArguments[$ptr], $parameterNames)) {
292308
$error = $methodArguments[$ptr] . ' parameter is missing in method annotation';
293-
$phpcsFile->addError($error, $stackPtr, 'MethodArguments');
309+
$phpcsFile->addError($error, $stackPtr, 'ArgumentMissing');
294310
}
295311
}
296312

@@ -314,7 +330,7 @@ private function validateParameterPresentInMethodSignature(
314330
$phpcsFile->addError(
315331
$paramDefinitionsArguments . ' parameter is missing in method arguments signature',
316332
$paramPointers[$ptr],
317-
'MethodArguments'
333+
'ArgumentMissing'
318334
);
319335
}
320336
}
@@ -343,7 +359,7 @@ private function validateParameterOrderIsCorrect(
343359
$phpcsFile->addError(
344360
$methodArguments[$ptr] . ' parameter is not in order',
345361
$paramPointers[$ptr],
346-
'MethodArguments'
362+
'ParamOrder'
347363
);
348364
}
349365
}
@@ -386,7 +402,7 @@ private function validateDuplicateAnnotationDoesnotExists(
386402
$phpcsFile->addError(
387403
$value . ' duplicate found in method annotation',
388404
$stackPtr,
389-
'MethodArguments'
405+
'DuplicateParam'
390406
);
391407
}
392408
}
@@ -413,15 +429,15 @@ private function validateParameterAnnotationFormatIsCorrect(
413429
$phpcsFile->addError(
414430
'Missing both type and parameter',
415431
$paramPointers[$ptr],
416-
'MethodArguments'
432+
'Malformed'
417433
);
418434
break;
419435
case 1:
420436
if (preg_match('/^\$.*/', $paramDefinitions[0])) {
421437
$phpcsFile->addError(
422438
'Type is not specified',
423439
$paramPointers[$ptr],
424-
'MethodArguments'
440+
'NoTypeSpecified'
425441
);
426442
}
427443
break;
@@ -430,7 +446,7 @@ private function validateParameterAnnotationFormatIsCorrect(
430446
$phpcsFile->addError(
431447
$paramDefinitions[0] . ' is not a valid PHP type',
432448
$paramPointers[$ptr],
433-
'MethodArguments'
449+
'NotValidType'
434450
);
435451
}
436452
$this->validateParameterPresentInMethodSignature(
@@ -446,13 +462,13 @@ private function validateParameterAnnotationFormatIsCorrect(
446462
$phpcsFile->addError(
447463
'Type is not specified',
448464
$paramPointers[$ptr],
449-
'MethodArguments'
465+
'NoTypeSpecified'
450466
);
451467
if ($this->isInvalidType($paramDefinitions[0])) {
452468
$phpcsFile->addError(
453469
$paramDefinitions[0] . ' is not a valid PHP type',
454470
$paramPointers[$ptr],
455-
'MethodArguments'
471+
'NotValidType'
456472
);
457473
}
458474
}
@@ -552,7 +568,7 @@ public function process(File $phpcsFile, $stackPtr)
552568
$previousCommentClosePtr = $phpcsFile->findPrevious(T_DOC_COMMENT_CLOSE_TAG, $stackPtr - 1, 0);
553569
if ($previousCommentClosePtr && $previousCommentOpenPtr) {
554570
if (!$this->validateCommentBlockExists($phpcsFile, $previousCommentClosePtr, $stackPtr)) {
555-
$phpcsFile->addError('Comment block is missing', $stackPtr, 'MethodArguments');
571+
$phpcsFile->addError('Comment block is missing', $stackPtr, 'NoCommentBlock');
556572
return;
557573
}
558574
} else {
@@ -636,7 +652,7 @@ private function validateFormattingConsistency(
636652
$phpcsFile->addError(
637653
'Method arguments visual alignment must be consistent',
638654
$paramPointers[0],
639-
'MethodArguments'
655+
'VisualAlignment'
640656
);
641657
}
642658
}

‎Magento2/Sniffs/Classes/DiscouragedDependenciesSniff.php

Copy file name to clipboardExpand all lines: Magento2/Sniffs/Classes/DiscouragedDependenciesSniff.php
+1-1Lines changed: 1 addition & 1 deletion
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/Functions/DiscouragedFunctionSniff.php

Copy file name to clipboardExpand all lines: Magento2/Sniffs/Functions/DiscouragedFunctionSniff.php
+7Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,5 +238,12 @@ class DiscouragedFunctionSniff extends ForbiddenFunctionsSniff
238238
'^fseek$' => 'Magento\Framework\Filesystem\DriverInterface::fileSeek()',
239239
'^feof$' => 'Magento\Framework\Filesystem\DriverInterface::endOfFile()',
240240
'^flock$' => 'Magento\Framework\Filesystem\DriverInterface::fileLock()',
241+
'^date_sunrise$' => 'date_sun_info',
242+
'^date_sunset$' => 'date_sun_info',
243+
'^strptime$' => 'date_parse_from_format',
244+
'^strftime$' => 'IntlDateFormatter::format',
245+
'^gmstrftime$' => 'IntlDateFormatter::format',
246+
'^(mhash|mhash_.*)$' => 'hash_*',
247+
'^odbc_result_all$' => null
241248
];
242249
}
+73Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento2\Sniffs\Functions;
9+
10+
use PHP_CodeSniffer\Files\File;
11+
use PHP_CodeSniffer\Sniffs\Sniff;
12+
13+
/**
14+
* Sniff to validate PHP functions usage of which without passing arguments is deprecated.
15+
*/
16+
class FunctionsDeprecatedWithoutArgumentSniff implements Sniff
17+
{
18+
/**
19+
* String representation of warning.
20+
*
21+
* @var string
22+
*/
23+
private const WARNING_MESSAGE = 'Calling function %s() without argument is deprecated in PHP 8.1. '
24+
. 'Please pass the input to validate as the first argument of the function.';
25+
26+
/**
27+
* Warning violation code.
28+
*
29+
* @var string
30+
*/
31+
private const WARNING_CODE = 'FunctionsDeprecatedWithoutArgument';
32+
33+
/**
34+
* Deprecated functions without argument.
35+
*
36+
* @var array
37+
*/
38+
private const FUNCTIONS_LIST = [
39+
'mb_check_encoding',
40+
'get_class',
41+
'get_parent_class',
42+
'get_called_class'
43+
];
44+
45+
/**
46+
* @inheritdoc
47+
*/
48+
public function register(): array
49+
{
50+
return [
51+
T_OPEN_PARENTHESIS
52+
];
53+
}
54+
55+
/**
56+
* @inheritdoc
57+
*/
58+
public function process(File $phpcsFile, $stackPtr): void
59+
{
60+
$closeParenthesisPtr = $phpcsFile->findNext(T_CLOSE_PARENTHESIS, $stackPtr);
61+
$arguments = trim($phpcsFile->getTokensAsString($stackPtr + 1, $closeParenthesisPtr - $stackPtr - 1));
62+
63+
if ($arguments) {
64+
return;
65+
}
66+
67+
$functionName = $phpcsFile->getTokensAsString($phpcsFile->findPrevious(T_STRING, $stackPtr), 1);
68+
69+
if (in_array($functionName, self::FUNCTIONS_LIST)) {
70+
$phpcsFile->addWarning(sprintf(self::WARNING_MESSAGE, $functionName), $stackPtr, self::WARNING_CODE);
71+
}
72+
}
73+
}

‎Magento2/Sniffs/Html/HtmlDirectiveSniff.php

Copy file name to clipboardExpand all lines: Magento2/Sniffs/Html/HtmlDirectiveSniff.php
+4-4Lines changed: 4 additions & 4 deletions
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

Copy file name to clipboardExpand all lines: Magento2/Sniffs/Less/CommentLevelsSniff.php
+3-3Lines changed: 3 additions & 3 deletions
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

Copy file name to clipboardExpand all lines: Magento2/Sniffs/Less/TokenizerSymbolsInterface.php
+9-9Lines changed: 9 additions & 9 deletions
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

Copy file name to clipboardExpand all lines: Magento2/Sniffs/Less/ZeroUnitsSniff.php
+3-3Lines changed: 3 additions & 3 deletions
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

Copy file name to clipboardExpand all lines: Magento2/Sniffs/Methods/DeprecatedModelMethodSniff.php
+1-1Lines changed: 1 addition & 1 deletion
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.

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.