Skip to content

Commit bb77a39

Browse files
committed
MM-4941: [EQP][Sniffs Consolidation] Create new GitHub repo and move MEQP2 sniffs
- Removed severity from PHP code and added to the ruleset
1 parent 8b81307 commit bb77a39

21 files changed

+104
-206
lines changed

Magento/Sniffs/Classes/ObjectInstantiationSniff.php

+1-9
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,6 @@
1313
*/
1414
class ObjectInstantiationSniff implements Sniff
1515
{
16-
/**
17-
* Violation severity.
18-
*
19-
* @var int
20-
*/
21-
protected $severity = 8;
22-
2316
/**
2417
* String representation of warning.
2518
*
@@ -84,8 +77,7 @@ public function process(File $phpcsFile, $stackPtr)
8477
$this->warningMessage,
8578
$classNameStart,
8679
$this->warningCode,
87-
[$className],
88-
$this->severity
80+
[$className]
8981
);
9082
}
9183
}

Magento/Sniffs/Exceptions/DirectThrowSniff.php

+1-9
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,6 @@
1313
*/
1414
class DirectThrowSniff implements Sniff
1515
{
16-
/**
17-
* Violation severity.
18-
*
19-
* @var int
20-
*/
21-
protected $severity = 8;
22-
2316
/**
2417
* String representation of warning.
2518
*/
@@ -54,8 +47,7 @@ public function process(File $phpcsFile, $stackPtr)
5447
$this->warningMessage,
5548
$stackPtr,
5649
$this->warningCode,
57-
$posOfException,
58-
$this->severity
50+
$posOfException
5951
);
6052
}
6153
}

Magento/Sniffs/Exceptions/NamespaceSniff.php

+1-9
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,6 @@
1313
*/
1414
class NamespaceSniff implements Sniff
1515
{
16-
/**
17-
* Violation severity.
18-
*
19-
* @var int
20-
*/
21-
protected $severity = 10;
22-
2316
/**
2417
* String representation of error.
2518
*
@@ -63,8 +56,7 @@ public function process(File $phpcsFile, $stackPtr)
6356
$this->errorMessage,
6457
$stackPtr,
6558
$this->errorCode,
66-
$exceptionClassName,
67-
$this->severity
59+
$exceptionClassName
6860
);
6961
}
7062
}

Magento/Sniffs/Legacy/MageEntitySniff.php

+7-17
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,11 @@
1313
*/
1414
class MageEntitySniff implements Sniff
1515
{
16-
/**
17-
* Violation severity.
18-
*
19-
* @var int
20-
*/
21-
protected $severity = 10;
22-
23-
/**
24-
* String representation of error.
25-
*
26-
* @var string
27-
*/
16+
/**
17+
* String representation of error.
18+
*
19+
* @var string
20+
*/
2821
protected $errorMessage = 'Possible Magento 2 design violation. Detected typical Magento 1.x construction "%s".';
2922

3023
/**
@@ -94,15 +87,12 @@ public function process(File $phpcsFile, $stackPtr)
9487
$entityName = $tokens[$stackPtr]['content'];
9588
$error = [$tokens[$oldPosition]['content'] . ' ' . $entityName];
9689
}
97-
if ($entityName === $this->legacyEntity ||
98-
$this->isPrefixLegacy($entityName)
99-
) {
90+
if ($entityName === $this->legacyEntity || $this->isPrefixLegacy($entityName)) {
10091
$phpcsFile->addError(
10192
$this->errorMessage,
10293
$stackPtr,
10394
$this->errorCode,
104-
$error,
105-
$this->severity
95+
$error
10696
);
10797
}
10898
}

Magento/Sniffs/NamingConvention/InterfaceNameSniff.php

+1-8
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,6 @@
1313
*/
1414
class InterfaceNameSniff implements Sniff
1515
{
16-
/**
17-
* Violation severity.
18-
*
19-
* @var int
20-
*/
21-
protected $severity = 6;
22-
2316
/**
2417
* String representation of warning.
2518
*
@@ -61,7 +54,7 @@ public function process(File $sourceFile, $stackPtr)
6154
while ($tokens[$stackPtr]['line'] === $declarationLine) {
6255
if ($tokens[$stackPtr]['type'] === 'T_STRING') {
6356
if (substr($tokens[$stackPtr]['content'], 0 - $suffixLength) !== $this->interfaceSuffix) {
64-
$sourceFile->addWarning($this->warningMessage, $stackPtr, $this->warningCode, [], $this->severity);
57+
$sourceFile->addWarning($this->warningMessage, $stackPtr, $this->warningCode);
6558
}
6659
break;
6760
}

Magento/Sniffs/PHP/DateTimeSniff.php

+1-8
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,6 @@
1313
*/
1414
class DateTimeSniff implements Sniff
1515
{
16-
/**
17-
* Violation severity.
18-
*
19-
* @var int
20-
*/
21-
protected $severity = 6;
22-
2316
/**
2417
* String representation of warning.
2518
*
@@ -63,7 +56,7 @@ public function process(File $phpcsFile, $stackPtr)
6356
$posOfClassName = $phpcsFile->findNext(T_STRING, $stackPtr);
6457
$posOfNsSeparator = $phpcsFile->findNext(T_NS_SEPARATOR, $stackPtr, $posOfClassName);
6558
if ($posOfNsSeparator !== false && in_array($tokens[$posOfClassName]['content'], $this->dateTimeClasses)) {
66-
$phpcsFile->addWarning($this->warningMessage, $stackPtr, $this->warningCode, [], $this->severity);
59+
$phpcsFile->addWarning($this->warningMessage, $stackPtr, $this->warningCode);
6760
}
6861
}
6962
}

Magento/Sniffs/PHP/DiscouragedFunctionSniff.php

+1-8
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,6 @@
1313
*/
1414
class DiscouragedFunctionSniff extends ForbiddenFunctionsSniff
1515
{
16-
/**
17-
* Violation severity.
18-
*
19-
* @var int
20-
*/
21-
protected $severity = 8;
22-
2316
/**
2417
* Pattern flag.
2518
*
@@ -254,6 +247,6 @@ protected function addError($phpcsFile, $stackPtr, $function, $pattern = null)
254247
$data[] = $this->forbiddenFunctions[$pattern];
255248
$warningMessage .= '; use %s instead.';
256249
}
257-
$phpcsFile->addWarning($warningMessage, $stackPtr, $warningCode, $data, $this->severity);
250+
$phpcsFile->addWarning($warningMessage, $stackPtr, $warningCode, $data);
258251
}
259252
}

Magento/Sniffs/PHP/GotoSniff.php

+1-8
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,6 @@
1313
*/
1414
class GotoSniff implements Sniff
1515
{
16-
/**
17-
* Violation severity.
18-
*
19-
* @var int
20-
*/
21-
protected $severity = 10;
22-
2316
/**
2417
* String representation of warning.
2518
*
@@ -47,6 +40,6 @@ public function register()
4740
*/
4841
public function process(File $phpcsFile, $stackPtr)
4942
{
50-
$phpcsFile->addError($this->errorMessage, $stackPtr, $this->errorCode, [], $this->severity);
43+
$phpcsFile->addError($this->errorMessage, $stackPtr, $this->errorCode);
5144
}
5245
}

Magento/Sniffs/PHP/ReturnValueCheckSniff.php

+2-8
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Copyright © Magento. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
67
namespace Magento\Sniffs\PHP;
78

89
use PHP_CodeSniffer\Sniffs\Sniff;
@@ -13,13 +14,6 @@
1314
*/
1415
class ReturnValueCheckSniff implements Sniff
1516
{
16-
/**
17-
* Violation severity.
18-
*
19-
* @var int
20-
*/
21-
protected $severity = 10;
22-
2317
/**
2418
* String representation of error.
2519
*
@@ -131,7 +125,7 @@ public function process(File $phpcsFile, $stackPtr)
131125
&& (!$this->findIdentical($i - 1, $this->findFunctionParenthesisCloser($i) + 1))
132126
) {
133127
$foundFunctionName = $this->tokens[$i]['content'];
134-
$phpcsFile->addError($this->errorMessage, $i, $this->errorCode, [$foundFunctionName], $this->severity);
128+
$phpcsFile->addError($this->errorMessage, $i, $this->errorCode, [$foundFunctionName]);
135129
}
136130
}
137131
}

Magento/Sniffs/PHP/VarSniff.php

+1-8
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,6 @@
1313
*/
1414
class VarSniff implements Sniff
1515
{
16-
/**
17-
* Violation severity.
18-
*
19-
* @var int
20-
*/
21-
protected $severity = 8;
22-
2316
/**
2417
* String representation of warning.
2518
*
@@ -47,6 +40,6 @@ public function register()
4740
*/
4841
public function process(File $phpcsFile, $stackPtr)
4942
{
50-
$phpcsFile->addWarning($this->warningMessage, $stackPtr, $this->warningCode, [], $this->severity);
43+
$phpcsFile->addWarning($this->warningMessage, $stackPtr, $this->warningCode);
5144
}
5245
}

Magento/Sniffs/Performance/EmptyCheckSniff.php

+2-9
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,6 @@
1313
*/
1414
class EmptyCheckSniff implements Sniff
1515
{
16-
/**
17-
* Violation severity.
18-
*
19-
* @var int
20-
*/
21-
protected $severity = 8;
22-
2316
/**
2417
* Mapping for function's code and message.
2518
*
@@ -118,12 +111,12 @@ public function process(File $phpcsFile, $stackPtr)
118111
$message = $this->map[$this->tokens[$functionPosition]['content']]['message'];
119112
if ($operatorPosition !== false) {
120113
if ($phpcsFile->findNext(T_LNUMBER, $operatorPosition, $endOfStatementPosition, false, '0') !== false) {
121-
$phpcsFile->addWarning($message, $stackPtr, $code, [], $this->severity);
114+
$phpcsFile->addWarning($message, $stackPtr, $code);
122115
}
123116
} else {
124117
// phpcs:ignore Generic.Files.LineLength.TooLong
125118
if ($phpcsFile->findNext($this->otherComparisonOperators, $functionPosition, $endOfStatementPosition) === false) {
126-
$phpcsFile->addWarning($message, $stackPtr, $code, [], $this->severity);
119+
$phpcsFile->addWarning($message, $stackPtr, $code);
127120
}
128121
}
129122
}

Magento/Sniffs/Security/IncludeFileSniff.php

+6-14
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,11 @@
1414
*/
1515
class IncludeFileSniff implements Sniff
1616
{
17-
/**
18-
* Violation severity.
19-
*
20-
* @var int
21-
*/
22-
protected $severity = 8;
23-
24-
/**
25-
* Warning violation code.
26-
*
27-
* @var string
28-
*/
17+
/**
18+
* Warning violation code.
19+
*
20+
* @var string
21+
*/
2922
protected $warningCode = 'FoundIncludeFile';
3023

3124
/**
@@ -102,8 +95,7 @@ public function process(File $phpcsFile, $stackPtr)
10295
$message,
10396
$stackPtr,
10497
$this->warningCode,
105-
[$tokens[$stackPtr]['content']],
106-
$this->severity
98+
[$tokens[$stackPtr]['content']]
10799
);
108100
}
109101
}

Magento/Sniffs/Security/LanguageConstructSniff.php

+2-9
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,6 @@
1313
*/
1414
class LanguageConstructSniff implements Sniff
1515
{
16-
/**
17-
* Violation severity.
18-
*
19-
* @var int
20-
*/
21-
protected $severity = 10;
22-
2316
/**
2417
* String representation of error.
2518
*
@@ -79,14 +72,14 @@ public function process(File $phpcsFile, $stackPtr)
7972
if ($phpcsFile->findNext(T_BACKTICK, $stackPtr + 1)) {
8073
return;
8174
}
82-
$phpcsFile->addError($this->errorMessageBacktick, $stackPtr, $this->backtickCode, [], $this->severity);
75+
$phpcsFile->addError($this->errorMessageBacktick, $stackPtr, $this->backtickCode);
8376
return;
8477
}
8578
if ($tokens[$stackPtr]['code'] === T_EXIT) {
8679
$code = $this->exitUsage;
8780
} else {
8881
$code = $this->directOutput;
8982
}
90-
$phpcsFile->addError($this->errorMessage, $stackPtr, $code, [$tokens[$stackPtr]['content']], $this->severity);
83+
$phpcsFile->addError($this->errorMessage, $stackPtr, $code, [$tokens[$stackPtr]['content']]);
9184
}
9285
}

Magento/Sniffs/Security/SuperglobalSniff.php

+2-18
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,6 @@
1313
*/
1414
class SuperglobalSniff implements Sniff
1515
{
16-
/**
17-
* Violation severity for error.
18-
*
19-
* @var int
20-
*/
21-
protected $errorSeverity = 10;
22-
23-
/**
24-
* Violation severity for warning.
25-
*
26-
* @var int
27-
*/
28-
protected $warningSeverity = 6;
29-
3016
/**
3117
* String representation of warning.
3218
*
@@ -96,16 +82,14 @@ public function process(File $phpcsFile, $stackPtr)
9682
$this->errorMessage,
9783
$stackPtr,
9884
$this->errorCode,
99-
[$var],
100-
$this->errorSeverity
85+
[$var]
10186
);
10287
} elseif (in_array($var, $this->superGlobalWarning)) {
10388
$phpcsFile->addWarning(
10489
$this->warningMessage,
10590
$stackPtr,
10691
$this->warningCode,
107-
[$var],
108-
$this->warningSeverity
92+
[$var]
10993
);
11094
}
11195
}

0 commit comments

Comments
 (0)