Skip to content

Commit 8b81307

Browse files
committed
MM-4941: [EQP][Sniffs Consolidation] Create new GitHub repo and move MEQP2 sniffs
- Code review fixes
1 parent 1c22ba7 commit 8b81307

File tree

11 files changed

+20
-65
lines changed

11 files changed

+20
-65
lines changed

Magento/Sniffs/CodeAnalysis/EmptyBlockSniff.php

-3
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,7 @@ public function register()
2020
return array_merge(
2121
parent::register(),
2222
[
23-
T_CLASS,
24-
T_ABSTRACT,
2523
T_FUNCTION,
26-
T_INTERFACE,
2724
T_TRAIT
2825
]
2926
);

Magento/Sniffs/Performance/EmptyCheckSniff.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ class EmptyCheckSniff implements Sniff
2525
*
2626
* @var array
2727
*/
28-
2928
protected $map = [
3029
'count' => [
3130
// phpcs:ignore Generic.Files.LineLength.TooLong
@@ -34,12 +33,11 @@ class EmptyCheckSniff implements Sniff
3433
],
3534
'strlen' => [
3635
// phpcs:ignore Generic.Files.LineLength.TooLong
37-
'message' => 'strlen(...) function should not be used to check if string is empty. Consider replace with (=/!)== ""',
36+
'message' => 'strlen(...) function should not be used to check if string is empty. Consider replace with (... === "") or (... !== "")',
3837
'code' => 'FoundStrlen'
3938
],
4039
];
4140

42-
4341
/**
4442
* All tokens from current file.
4543
*

Magento/Sniffs/Templates/ThisInTemplateSniff.php

+2-18
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\Templates;
78

89
use PHP_CodeSniffer\Sniffs\Sniff;
@@ -34,15 +35,6 @@ class ThisInTemplateSniff implements Sniff
3435
*/
3536
protected $warningCode = 'FoundThis';
3637

37-
/**
38-
* List of methods, allowed to called via $this.
39-
*
40-
* @var array
41-
*/
42-
protected $allowedMethods = [
43-
'helper',
44-
];
45-
4638
/**
4739
* @inheritdoc
4840
*/
@@ -58,15 +50,7 @@ public function process(File $phpcsFile, $stackPtr)
5850
{
5951
$tokens = $phpcsFile->getTokens();
6052
if ($tokens[$stackPtr]['content'] === '$this') {
61-
$endOfStatementPtr = $phpcsFile->findEndOfStatement($stackPtr);
62-
$functionPtr = $phpcsFile->findNext(T_STRING, $stackPtr, $endOfStatementPtr);
63-
if ($functionPtr !== false) {
64-
if (!in_array($tokens[$functionPtr]['content'], $this->allowedMethods)) {
65-
$phpcsFile->addWarning($this->warningMessage, $stackPtr, $this->warningCode, [], $this->severity);
66-
}
67-
} else {
68-
$phpcsFile->addWarning($this->warningMessage, $stackPtr, $this->warningCode, [], $this->severity);
69-
}
53+
$phpcsFile->addWarning($this->warningMessage, $stackPtr, $this->warningCode, [], $this->severity);
7054
}
7155
}
7256
}

Magento/Tests/CodeAnalysis/EmptyBlockUnitTest.inc

+2-30
Original file line numberDiff line numberDiff line change
@@ -71,34 +71,6 @@ try {
7171

7272
if (true) {} elseif (false) {}
7373

74-
class EmptyBlockTestInc { /*Empty class block*/ }
74+
function emptyFunction () { /*Empty function block*/ }
7575

76-
class EmptyBlockTestIncTrue
77-
{
78-
public $field;
79-
}
80-
81-
abstract class EmptyBlockTestIncAbstract { /*Empty class block*/ }
82-
83-
abstract class EmptyBlockTestIncTrueAbstract
84-
{
85-
public $field;
86-
}
87-
88-
function emptyBlock () { /*Empty function block*/ }
89-
90-
function emptyBlockT () { return true; }
91-
92-
interface EmptyBlockInterface { /*Empty interface block*/ }
93-
94-
interface EmptyBlockInterfaceTrue {
95-
public function test();
96-
}
97-
98-
trait EmptyBlockTrait { /*Empty trait block*/ }
99-
100-
trait EmptyBlockTraitTrue {
101-
function test() {
102-
return true;
103-
}
104-
}
76+
function nonEmptyFunction () { return true; }

Magento/Tests/CodeAnalysis/EmptyBlockUnitTest.php

-4
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,6 @@ public function getErrorList()
3232
68 => 1,
3333
72 => 2,
3434
74 => 1,
35-
81 => 1,
36-
88 => 1,
37-
92 => 1,
38-
98 => 1,
3935
];
4036
}
4137

Magento/Tests/Exceptions/NamespaceUnitTest.inc

+6
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,9 @@ class TestNamespace
5454
}
5555
}
5656
}
57+
58+
try {
59+
doSomethind();
60+
} catch (\Exception $e) {
61+
logException($e->getMessage());
62+
}

Magento/Tests/Security/IncludeFileUnitTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
class IncludeFileUnitTest extends AbstractSniffUnitTest
1414
{
1515
/**
16-
* @inheritdoc
17-
*/
16+
* @inheritdoc
17+
*/
1818
public function getErrorList()
1919
{
2020
return [];

Magento/Tests/Strings/RegExUnitTest.inc

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

3-
$input = "Bet you want a BMW.";
3+
$input = "Test Input.";
44
echo preg_replace(
55
"/([a-z]*)/Xe",
66
"strtoupper('\\1')",
@@ -13,7 +13,7 @@ echo preg_replace(
1313
'get_input'
1414
);
1515

16-
$html = preg_replace('(<h([1-6])>(.*?)</h\1>)sex', '"<h$1>" . strtoupper("$2") . "</h$1>"', $html);
16+
$html = preg_replace('(<h([1-6])>(.*?)</h\1>)xes', '"<h$1>" . strtoupper("$2") . "</h$1>"', $html);
1717

1818
$a = preg_replace(
1919
'#<h([1-6])>(.*?)</h\1>#e',

Magento/Tests/Templates/ThisInTemplateUnitTest.php

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public function getWarningList()
2828
return [
2929
3 => 2,
3030
4 => 1,
31+
5 => 1,
3132
];
3233
}
3334
}

Magento/ruleset.xml

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<rule ref="Magento.Templates.ThisInTemplate">
1313
<include-pattern>*.phtml</include-pattern>
1414
</rule>
15-
<rule ref="Magento.Templates.XssTemplate">
15+
<rule ref="Magento.Security.XssTemplate">
1616
<include-pattern>*.phtml</include-pattern>
1717
</rule>
1818
<rule ref="Generic.Arrays.DisallowLongArraySyntax">
@@ -77,6 +77,7 @@
7777
<rule ref="PSR2">
7878
<severity>8</severity>
7979
<type>warning</type>
80+
<exclude name="Squiz.WhiteSpace.ControlStructureSpacing.NoLineAfterClose"/>
8081
</rule>
8182
<rule ref="PSR1.Classes.ClassDeclaration">
8283
<severity>10</severity>

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# Magento Coding Standard
22

3-
This is just the beginning of the coding standards consolidation process.
3+
A set of Magento rules for [PHP_CodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer) tool.
44

55
## Goals
66

77
1. Make it easier to run static checks for core project contributors and extensions developers.
8-
2. Store all related to Magento 2 sniffs in one place.
8+
2. Store all Magento 2 sniffs in one place.
99
3. Make static check consistent.

0 commit comments

Comments
 (0)