Skip to content

Commit 9185a9f

Browse files
import static test ruleset
1 parent f062ab4 commit 9185a9f

File tree

4 files changed

+89
-0
lines changed

4 files changed

+89
-0
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
/**
3+
* Copyright © Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento2\Sniffs\Namespaces;
7+
8+
use PHP_CodeSniffer\Sniffs\Sniff;
9+
use PHP_CodeSniffer\Files\File;
10+
11+
/**
12+
* Detects static test namespace.
13+
*/
14+
class UseDeclarationSniff implements Sniff
15+
{
16+
17+
/**
18+
* @var string
19+
*/
20+
private $_prohibitNamespace = 'Magento\Tests';
21+
22+
/**
23+
* @var string
24+
*/
25+
protected $warningMessage = 'Incorrect namespace has been imported.';
26+
27+
/**
28+
* @var string
29+
*/
30+
protected $warningCode = 'WrongImportNamespaces';
31+
32+
/**
33+
* @inheritdoc
34+
*/
35+
public function register()
36+
{
37+
return [T_USE];
38+
}
39+
40+
/**
41+
* @inheritdoc
42+
*/
43+
public function process(File $phpcsFile, $stackPtr)
44+
{
45+
$next = $phpcsFile->findNext([T_COMMA, T_SEMICOLON, T_OPEN_USE_GROUP, T_CLOSE_TAG], ($stackPtr + 1));
46+
$getTokenAsContent = $phpcsFile->getTokensAsString($stackPtr, ($next - $stackPtr));
47+
if (strpos($getTokenAsContent, $this->_prohibitNamespace) !== false) {
48+
$phpcsFile->addWarning($this->warningMessage, $stackPtr, $this->warningCode);
49+
}
50+
}
51+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?php
2+
use Magento\Tests;
3+
use Magento\Foo\Tests as FakeTest;
4+
use Magento\Real\Classes;
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
/**
3+
* Copyright © Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento2\Tests\Namespaces;
7+
8+
use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest;
9+
10+
/**
11+
* Class InterfaceNameUnitTest
12+
*/
13+
class UseDeclarationUnitTest extends AbstractSniffUnitTest
14+
{
15+
/**
16+
* @inheritdoc
17+
*/
18+
public function getErrorList()
19+
{
20+
return [];
21+
}
22+
23+
/**
24+
* @inheritdoc
25+
*/
26+
public function getWarningList()
27+
{
28+
return [2 => 1];
29+
}
30+
}

Magento2/ruleset.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,10 @@
189189
<exclude-pattern>*Test.php</exclude-pattern>
190190
<exclude-pattern>*/tests/*</exclude-pattern>
191191
</rule>
192+
<rule ref="Magento2.Namespaces.UseDeclaration">
193+
<severity>8</severity>
194+
<type>warning</type>
195+
</rule>
192196
<rule ref="Magento2.NamingConvention.InterfaceName">
193197
<severity>8</severity>
194198
<type>warning</type>

0 commit comments

Comments
 (0)