Skip to content

Commit 88d9f59

Browse files
committed
AC-206: Extracted Fframework only sniffs to a separate namespace
1 parent 47a6486 commit 88d9f59

29 files changed

+69
-132
lines changed

Diff for: .github/workflows/php.yml

+4-1
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,7 @@ jobs:
5959
run: vendor/bin/phpunit
6060

6161
- name: Run code style suite
62-
run: vendor/bin/phpcs --standard=Magento2 Magento2/Helpers/ Magento2/Sniffs
62+
run: vendor/bin/phpcs --standard=Magento2 Magento2/Helpers Magento2/Sniffs Magento2Framework/Sniffs
63+
64+
- name: Run framework suite
65+
run: vendor/bin/phpcs --standard=Magento2Framework Magento2/Helpers Magento2/Sniffs Magento2Framework/Sniffs

Diff for: Magento2/Sniffs/Legacy/RestrictedCodeSniff.php

+3-34
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ class RestrictedCodeSniff implements Sniff
3737
*/
3838
public function __construct()
3939
{
40-
$this->loadData('restricted_classes*.php');
40+
// phpcs:ignore Magento2.Security.IncludeFile.FoundIncludeFile
41+
$this->classes = include __DIR__ . '/_files/restricted_classes.php';
4142
}
4243

4344
/**
@@ -56,7 +57,7 @@ public function register()
5657
*/
5758
public function process(File $phpcsFile, $stackPtr)
5859
{
59-
// phpcs:ignore
60+
// phpcs:ignore Magento2.Functions.DiscouragedFunction
6061
if (array_key_exists(basename($phpcsFile->getFilename()), $this->fixtureFiles)) {
6162
return;
6263
}
@@ -99,36 +100,4 @@ private function isExcluded(string $token, File $phpcsFile): bool
99100
}
100101
return false;
101102
}
102-
103-
/**
104-
* Loads and merges data from fixtures
105-
*
106-
* @param string $filePattern
107-
* @return void
108-
*/
109-
private function loadData(string $filePattern)
110-
{
111-
// phpcs:ignore
112-
foreach (glob(__DIR__ . '/_files/' . $filePattern) as $file) {
113-
$relativePath = str_replace(
114-
'\\',
115-
'/',
116-
str_replace(__DIR__ . DIRECTORY_SEPARATOR, '', $file)
117-
);
118-
array_push($this->fixtureFiles, $relativePath);
119-
$this->classes = array_merge_recursive($this->classes, $this->readList($file));
120-
}
121-
}
122-
123-
/**
124-
* Isolate including a file into a method to reduce scope
125-
*
126-
* @param string $file
127-
* @return array
128-
*/
129-
private function readList($file)
130-
{
131-
// phpcs:ignore
132-
return include $file;
133-
}
134103
}

Diff for: Magento2/Sniffs/Legacy/_files/restricted_classes.php

+10-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
'exclude' => [
1818
'Magento/Framework/DB/Select.php',
1919
'Magento/Framework/DB/Adapter/Pdo/Mysql.php',
20-
'Magento/Framework/Model/ResourceModel/Iterator.php'
20+
'Magento/Framework/Model/ResourceModel/Iterator.php',
21+
'Magento/ResourceConnections/DB/Adapter/Pdo/MysqlProxy.php'
2122
]
2223
],
2324
'Zend_Db_Adapter_Pdo_Mysql' => [
@@ -48,7 +49,10 @@
4849
'Magento/Framework/Flag.php',
4950
'Magento/Widget/Setup/LayoutUpdateConverter.php',
5051
'Magento/Cms/Setup/ContentConverter.php',
51-
'Magento/Framework/Unserialize/Test/Unit/UnserializeTest.php'
52+
'Magento/Framework/Unserialize/Test/Unit/UnserializeTest.php',
53+
'Magento/Framework/Test/Unit/FlagTest.php',
54+
'Magento/Staging/Test/Unit/Model/Update/FlagTest.php',
55+
'Magento/Logging/Test/Unit/Setup/ObjectConverterTest.php'
5256
]
5357
],
5458
'ArrayObject' => [
@@ -67,7 +71,10 @@
6771
'Magento/Framework/Indexer/Test/Unit/BatchTest.php',
6872
'Magento/Framework/View/Element/UiComponent/ArrayObjectFactory.php',
6973
'Magento/Framework/View/Element/UiComponent/Config/Provider/Component/Definition.php',
70-
'Magento/Framework/Indexer/Action/Base.php'
74+
'Magento/Framework/Indexer/Action/Base.php',
75+
'Magento/MultipleWishlist/Test/Unit/Model/Search/Strategy/EmailTest.php',
76+
'Magento/Rma/Test/Unit/Model/RmaRepositoryTest.php',
77+
'Magento/Rma/Test/Unit/Model/Status/HistoryRepositoryTest.php'
7178
]
7279
],
7380
'Magento\Framework\View\Element\UiComponent\ArrayObjectFactory' => [

Diff for: Magento2/Sniffs/Legacy/_files/restricted_classes_ee.php

-32
This file was deleted.

Diff for: Magento2/Tests/Legacy/AbstractJsSniffUnitTestCase.php

-33
This file was deleted.

Diff for: Magento2/Sniffs/Legacy/CopyrightAnotherExtensionsFilesSniff.php renamed to Magento2Framework/Sniffs/Header/CopyrightAnotherExtensionsFilesSniff.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66
declare(strict_types = 1);
77

8-
namespace Magento2\Sniffs\Legacy;
8+
namespace Magento2Framework\Sniffs\Header;
99

1010
use Magento2\Sniffs\Less\TokenizerSymbolsInterface;
1111
use PHP_CodeSniffer\Files\File;
@@ -24,7 +24,7 @@ class CopyrightAnotherExtensionsFilesSniff implements Sniff
2424
* @var array
2525
*/
2626
public $supportedTokenizers = [TokenizerSymbolsInterface::TOKENIZER_CSS, 'PHP'];
27-
27+
2828
/**
2929
* @inheritDoc
3030
*/
@@ -44,7 +44,7 @@ public function process(File $phpcsFile, $stackPtr)
4444
if ($stackPtr > 0) {
4545
return;
4646
}
47-
47+
4848
$fileText = $phpcsFile->getTokensAsString($stackPtr, count($phpcsFile->getTokens()));
4949
$adobeCopyrightFound = preg_match(self::COPYRIGHT_ADOBE, $fileText);
5050

Diff for: Magento2/Sniffs/Legacy/CopyrightSniff.php renamed to Magento2Framework/Sniffs/Header/CopyrightSniff.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,26 @@
55
*/
66
declare(strict_types = 1);
77

8-
namespace Magento2\Sniffs\Legacy;
8+
namespace Magento2Framework\Sniffs\Header;
99

1010
use PHP_CodeSniffer\Files\File;
1111
use PHP_CodeSniffer\Sniffs\Sniff;
1212

1313
class CopyrightSniff implements Sniff
1414
{
1515
private const WARNING_CODE = 'FoundCopyrightMissingOrWrongFormat';
16-
16+
1717
private const COPYRIGHT_MAGENTO_TEXT = 'Copyright © Magento, Inc. All rights reserved.';
1818
private const COPYRIGHT_ADOBE = '/Copyright \d+ Adobe/';
19-
19+
2020
/**
2121
* @inheritdoc
2222
*/
2323
public function register()
2424
{
2525
return [T_OPEN_TAG];
2626
}
27-
27+
2828
/**
2929
* @inheritDoc
3030
*/

Diff for: Magento2/Sniffs/Legacy/LicenseSniff.php renamed to Magento2Framework/Sniffs/Header/LicenseSniff.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66
declare(strict_types = 1);
77

8-
namespace Magento2\Sniffs\Legacy;
8+
namespace Magento2Framework\Sniffs\Header;
99

1010
use Magento2\Sniffs\Less\TokenizerSymbolsInterface;
1111
use PHP_CodeSniffer\Files\File;
@@ -21,9 +21,9 @@ class LicenseSniff implements Sniff
2121
public $supportedTokenizers = [TokenizerSymbolsInterface::TOKENIZER_CSS, 'PHP'];
2222

2323
private const WARNING_CODE = 'FoundLegacyTextInCopyright';
24-
24+
2525
private const LEGACY_TEXTS = ['Irubin Consulting Inc', 'DBA Varien', 'Magento Inc'];
26-
26+
2727
/**
2828
* @inheritdoc
2929
*/
@@ -34,15 +34,15 @@ public function register()
3434
T_INLINE_HTML
3535
];
3636
}
37-
37+
3838
/**
3939
* @inheritDoc
4040
*/
4141
public function process(File $phpcsFile, $stackPtr)
4242
{
4343
$tokens = $phpcsFile->getTokens();
4444
$content = null;
45-
45+
4646
if ($tokens[$stackPtr]['code'] === T_DOC_COMMENT_STRING) {
4747
$content = $tokens[$stackPtr]['content'];
4848
}

Diff for: Magento2/Tests/Legacy/CopyrightAnotherExtensionsFilesUnitTest.php renamed to Magento2Framework/Tests/Header/CopyrightAnotherExtensionsFilesUnitTest.php

+23-2
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,31 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6-
namespace Magento2\Tests\Legacy;
6+
namespace Magento2Framework\Tests\Header;
77

8-
class CopyrightAnotherExtensionsFilesUnitTest extends AbstractJsSniffUnitTestCase
8+
use PHP_CodeSniffer\Config;
9+
use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest;
10+
11+
class CopyrightAnotherExtensionsFilesUnitTest extends AbstractSniffUnitTest
912
{
13+
/**
14+
* @inheritDoc
15+
*/
16+
protected function setUp(): void
17+
{
18+
parent::setUp();
19+
20+
$config = new Config();
21+
$config->extensions = array_merge(
22+
$config->extensions,
23+
[
24+
'js' => 'PHP'
25+
]
26+
);
27+
28+
$GLOBALS['PHP_CODESNIFFER_CONFIG'] = $config;
29+
}
30+
1031
/**
1132
* @inheritdoc
1233
*/

Diff for: Magento2/Tests/Legacy/CopyrightUnitTest.php renamed to Magento2Framework/Tests/Header/CopyrightUnitTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6-
namespace Magento2\Tests\Legacy;
6+
namespace Magento2Framework\Tests\Header;
77

88
use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest;
99

@@ -25,7 +25,7 @@ public function getWarningList($testFile = ''): array
2525
if ($testFile === 'CopyrightUnitTest.4.inc' || $testFile === 'CopyrightUnitTest.5.inc') {
2626
return [];
2727
}
28-
28+
2929
if ($testFile === 'CopyrightUnitTest.1.inc') {
3030
return [
3131
1 => 1,

Diff for: Magento2/Tests/Legacy/LicenseUnitTest.php renamed to Magento2Framework/Tests/Header/LicenseUnitTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6-
namespace Magento2\Tests\Legacy;
6+
namespace Magento2Framework\Tests\Header;
77

88
use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest;
99

@@ -25,7 +25,7 @@ public function getWarningList($testFile = ''): array
2525
if ($testFile === 'LicenseUnitTest.1.inc' || $testFile === 'LicenseUnitTest.3.xml') {
2626
return [];
2727
}
28-
28+
2929
if ($testFile === 'LicenseUnitTest.2.inc') {
3030
return [
3131
3 => 1,

Diff for: Magento2/magento-only-ruleset.xml renamed to Magento2Framework/ruleset.xml

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
<?xml version="1.0"?>
2-
<ruleset name="Magento2 Only">
3-
<description>Magento Coding Standard sniffs applicable for Magento Open Source development only</description>
4-
<rule ref="Magento2.Legacy.License">
2+
<ruleset name="Magento2Framework">
3+
<description>Magento Coding Standard sniffs applicable for the framework testing only</description>
4+
<rule ref="Magento2Framework.Header.License">
55
<severity>5</severity>
66
<type>warning</type>
77
</rule>
8-
<rule ref="Magento2.Legacy.CopyrightAnotherExtensionsFiles">
8+
<rule ref="Magento2Framework.Header.CopyrightAnotherExtensionsFiles">
99
<severity>5</severity>
1010
<type>warning</type>
1111
<exclude-pattern>*\.php$</exclude-pattern>
1212
<exclude-pattern>*\.phtml$</exclude-pattern>
1313
</rule>
14-
<rule ref="Magento2.Legacy.Copyright">
14+
<rule ref="Magento2Framework.Header.Copyright">
1515
<severity>5</severity>
1616
<type>warning</type>
1717
<include-pattern>*\.php$</include-pattern>

Diff for: composer.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@
2727
"PHP_CodeSniffer/Tokenizers/"
2828
],
2929
"psr-4": {
30-
"Magento2\\": "Magento2/"
30+
"Magento2\\": "Magento2/",
31+
"Magento2Framework\\": "Magento2Framework/"
3132
}
3233
},
3334
"scripts": {

0 commit comments

Comments
 (0)