Skip to content

Commit c9a10aa

Browse files
authored
Merge pull request #13 from magento/follow-magento-standard
MM-5069: [EQP][Sniffs Consolidation] Follow Magento coding standard
2 parents fbece95 + d07b5f3 commit c9a10aa

15 files changed

+32
-24
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ php:
66
install: composer install --no-interaction --prefer-source
77
script:
88
- bin/phpunit
9-
- bin/phpcs --standard=PSR2 Magento/ --extensions=php
9+
- bin/phpcs --standard=Magento Magento/ --extensions=php

Magento/Sniffs/Annotation/ClassAnnotationStructureSniff.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public function register()
3333
*/
3434
public function __construct()
3535
{
36+
// phpcs:ignore Magento.Classes.ObjectInstantiation.FoundDirectInstantiation
3637
$this->annotationFormatValidator = new AnnotationFormatValidator();
3738
}
3839

Magento/Sniffs/Annotation/MethodAnnotationStructureSniff.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class MethodAnnotationStructureSniff implements Sniff
2323
*/
2424
public function __construct()
2525
{
26+
// phpcs:ignore Magento.Classes.ObjectInstantiation.FoundDirectInstantiation
2627
$this->annotationFormatValidator = new AnnotationFormatValidator();
2728
}
2829

Magento/Sniffs/Annotation/MethodArgumentsSniff.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,8 @@ private function getMethodArguments(File $phpcsFile, $openParenthesisPtr, $close
121121
private function getMethodParameters(array $paramDefinitions)
122122
{
123123
$paramName = [];
124-
for ($i = 0; $i < count($paramDefinitions); $i++) {
124+
$countParams = count($paramDefinitions);
125+
for ($i = 0; $i < $countParams; $i++) {
125126
if (isset($paramDefinitions[$i]['paramName'])) {
126127
$paramName[] = $paramDefinitions[$i]['paramName'];
127128
}
@@ -368,10 +369,11 @@ private function validateDuplicateAnnotationDoesnotExists(
368369
$parametersCount = count($paramPointers);
369370
if ($argumentsCount <= $parametersCount && $argumentsCount > 0) {
370371
$duplicateParameters = [];
371-
for ($i = 0; $i < sizeof($paramDefinitions); $i++) {
372+
$countParams = count($paramDefinitions);
373+
for ($i = 0; $i < $countParams; $i++) {
372374
if (isset($paramDefinitions[$i]['paramName'])) {
373375
$parameterContent = $paramDefinitions[$i]['paramName'];
374-
for ($j = $i + 1; $j < count($paramDefinitions); $j++) {
376+
for ($j = $i + 1; $j < $countParams; $j++) {
375377
if (isset($paramDefinitions[$j]['paramName'])
376378
&& $parameterContent === $paramDefinitions[$j]['paramName']
377379
) {
@@ -507,7 +509,8 @@ private function validateMethodParameterAnnotations(
507509
$phpcsFile,
508510
$paramPointers
509511
);
510-
for ($ptr = 0; $ptr < count($methodArguments); $ptr++) {
512+
$countArguments = count($methodArguments);
513+
for ($ptr = 0; $ptr < $countArguments; $ptr++) {
511514
$tokens = $phpcsFile->getTokens();
512515
if (isset($paramPointers[$ptr])) {
513516
$this->validateArgumentNameInParameterAnnotationExists(

Magento/Sniffs/Classes/ObjectInstantiationSniff.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ class ObjectInstantiationSniff implements Sniff
1818
*
1919
* @var string
2020
*/
21-
protected $warningMessage = 'Direct object instantiation (object of %s) is discouraged in Magento 2.';
21+
// phpcs:ignore Magento.Files.LineLength.MaxExceeded
22+
protected $warningMessage = 'Direct %s object instantiation is discouraged in Magento. Use dependency injection or factories instead.';
2223

2324
/**
2425
* Warning violation code.

Magento/Sniffs/Classes/ObjectManagerSniff.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@
99
use PHP_CodeSniffer\Files\File;
1010

1111
/**
12-
* Class ObjectManagerSniff
13-
* Detects direct ObjectManager usage.
12+
* Class ObjectManagerSniff detects direct ObjectManager usage.
1413
*/
1514
class ObjectManagerSniff implements Sniff
1615
{
@@ -19,7 +18,7 @@ class ObjectManagerSniff implements Sniff
1918
*
2019
* @var string
2120
*/
22-
// phpcs:ignore Generic.Files.LineLength.TooLong
21+
// phpcs:ignore Magento.Files.LineLength.MaxExceeded
2322
protected $warningMessage = 'The direct use of ObjectManager is discouraged. Inject necessary dependencies via constructor.';
2423

2524
/**

Magento/Sniffs/PHP/DateTimeSniff.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class DateTimeSniff implements Sniff
1818
*
1919
* @var string
2020
*/
21-
// phpcs:ignore Generic.Files.LineLength.TooLong
21+
// phpcs:ignore Magento.Files.LineLength.MaxExceeded
2222
protected $warningMessage = 'Overcomplicated Date/Time handling. Use \Magento\Framework\Stdlib\DateTime\TimezoneInterface instead.';
2323

2424
/**

Magento/Sniffs/PHP/FinalImplementationSniff.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function register()
2727
public function process(File $phpcsFile, $stackPtr)
2828
{
2929
$phpcsFile->addError(
30-
// phpcs:ignore Generic.Files.LineLength.TooLong
30+
// phpcs:ignore Magento.Files.LineLength.MaxExceeded
3131
'Final keyword is prohibited in Magento. It decreases extensibility and is not compatible with plugins and proxies.',
3232
$stackPtr,
3333
'FoundFinal'

Magento/Sniffs/PHP/LiteralNamespacesSniff.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ public function process(File $sourceFile, $stackPtr)
6262
}
6363

6464
/**
65+
* Checks if class or interface exists.
66+
*
67+
* ToDo: get rig of this check https://github.com/magento/magento-coding-standard/issues/9
68+
*
6569
* @param string $className
6670
* @return bool
6771
*/

Magento/Sniffs/Performance/EmptyCheckSniff.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ class EmptyCheckSniff implements Sniff
2020
*/
2121
protected $map = [
2222
'count' => [
23-
// phpcs:ignore Generic.Files.LineLength.TooLong
23+
// phpcs:ignore Magento.Files.LineLength.MaxExceeded
2424
'message' => 'count(...) function should not be used to check if array is empty. Use empty(...) language construct instead',
2525
'code' => 'FoundCount'
2626
],
2727
'strlen' => [
28-
// phpcs:ignore Generic.Files.LineLength.TooLong
28+
// phpcs:ignore Magento.Files.LineLength.MaxExceeded
2929
'message' => 'strlen(...) function should not be used to check if string is empty. Consider replace with (... === "") or (... !== "")',
3030
'code' => 'FoundStrlen'
3131
],
@@ -114,7 +114,7 @@ public function process(File $phpcsFile, $stackPtr)
114114
$phpcsFile->addWarning($message, $stackPtr, $code);
115115
}
116116
} else {
117-
// phpcs:ignore Generic.Files.LineLength.TooLong
117+
// phpcs:ignore Magento.Files.LineLength.MaxExceeded
118118
if ($phpcsFile->findNext($this->otherComparisonOperators, $functionPosition, $endOfStatementPosition) === false) {
119119
$phpcsFile->addWarning($message, $stackPtr, $code);
120120
}
@@ -130,7 +130,7 @@ public function process(File $phpcsFile, $stackPtr)
130130
*/
131131
private function findFunctionPosition($index)
132132
{
133-
// phpcs:ignore Generic.Files.LineLength.TooLong
133+
// phpcs:ignore Magento.Files.LineLength.MaxExceeded
134134
for ($i = $this->tokens[$index]['parenthesis_opener'] + 1; $i < $this->tokens[$index]['parenthesis_closer']; $i++) {
135135
if (array_key_exists($this->tokens[$i]['content'], $this->map)) {
136136
return $i;

0 commit comments

Comments
 (0)