Skip to content

Commit b00d7cf

Browse files
Merge pull request #62 from magento-commerce/imported-magento-magento-coding-standard-269
[Imported] AC-666: Copyright test for another extensions files
2 parents 0d6cb3c + 26a3b65 commit b00d7cf

8 files changed

+171
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types = 1);
7+
8+
namespace Magento2\Sniffs\Legacy;
9+
10+
use PHP_CodeSniffer\Files\File;
11+
use PHP_CodeSniffer\Sniffs\Sniff;
12+
13+
class CopyrightAnotherExtensionsFilesSniff implements Sniff
14+
{
15+
private const WARNING_CODE = 'FoundCopyrightMissingOrWrongFormat';
16+
17+
private const COPYRIGHT_MAGENTO_TEXT = 'Copyright © Magento, Inc. All rights reserved.';
18+
private const COPYRIGHT_ADOBE = '/Copyright \d+ Adobe/';
19+
20+
/**
21+
* @inheritDoc
22+
*/
23+
public function register(): array
24+
{
25+
return [
26+
T_INLINE_HTML
27+
];
28+
}
29+
30+
/**
31+
* @inheritDoc
32+
*/
33+
public function process(File $phpcsFile, $stackPtr)
34+
{
35+
if ($stackPtr > 0) {
36+
return;
37+
}
38+
39+
$fileText = $phpcsFile->getTokensAsString($stackPtr, count($phpcsFile->getTokens()));
40+
$adobeCopyrightFound = preg_match(self::COPYRIGHT_ADOBE, $fileText);
41+
42+
if (strpos($fileText, self::COPYRIGHT_MAGENTO_TEXT) !== false || $adobeCopyrightFound) {
43+
return;
44+
}
45+
46+
$phpcsFile->addWarningOnLine(
47+
'Copyright is missing or has wrong format',
48+
null,
49+
self::WARNING_CODE
50+
);
51+
}
52+
}
+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento2\Tests\Legacy;
7+
8+
use PHP_CodeSniffer\Config;
9+
use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest;
10+
11+
/**
12+
* Implements an abstract base for unit tests that cover less sniffs.
13+
*/
14+
abstract class AbstractJsSniffUnitTestCase extends AbstractSniffUnitTest
15+
{
16+
/**
17+
* @inheritDoc
18+
*/
19+
protected function setUp(): void
20+
{
21+
parent::setUp();
22+
23+
$config = new Config();
24+
$config->extensions = array_merge(
25+
$config->extensions,
26+
[
27+
'js' => 'PHP'
28+
]
29+
);
30+
31+
$GLOBALS['PHP_CODESNIFFER_CONFIG'] = $config;
32+
}
33+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights another text to test.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<tag>
9+
10+
</tag>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/**
2+
* Copyright Adobe.
3+
* See COPYING.txt for license details.
4+
*/
5+
6+
define([
7+
'jquery'
8+
], function (){
9+
10+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/**
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
6+
define([
7+
'jquery'
8+
], function (){
9+
10+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento2\Tests\Legacy;
7+
8+
class CopyrightAnotherExtensionsFilesUnitTest extends AbstractJsSniffUnitTestCase
9+
{
10+
/**
11+
* @inheritdoc
12+
*/
13+
public function getErrorList()
14+
{
15+
return [];
16+
}
17+
18+
/**
19+
* @inheritdoc
20+
*/
21+
public function getWarningList($testFile = '')
22+
{
23+
if ($testFile === 'CopyrightAnotherExtensionsFilesUnitTest.1.xml') {
24+
return [
25+
null => 1,
26+
];
27+
}
28+
if ($testFile === 'CopyrightAnotherExtensionsFilesUnitTest.2.js') {
29+
return [
30+
null => 1,
31+
];
32+
}
33+
if ($testFile === 'CopyrightAnotherExtensionsFilesUnitTest.3.xml') {
34+
return [];
35+
}
36+
if ($testFile === 'CopyrightAnotherExtensionsFilesUnitTest.4.js') {
37+
return [];
38+
}
39+
return [];
40+
}
41+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/**
4+
* Copyright 2020 Adobe
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<tag>
9+
10+
</tag>

Diff for: Magento2/ruleset.xml

+5-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<description>Magento Coding Standard</description>
44

55
<!-- File extensions to be checked. -->
6-
<arg name="extensions" value="php,phtml,graphqls/GraphQL,less/CSS,html/PHP,xml"/>
6+
<arg name="extensions" value="php,phtml,graphqls/GraphQL,less/CSS,html/PHP,xml,js/PHP"/>
77

88
<!-- Severity 10 errors: Critical code issues. -->
99
<rule ref="Generic.Functions.CallTimePassByReference">
@@ -634,6 +634,10 @@
634634
<exclude-pattern>*/Test/*</exclude-pattern>
635635
<exclude-pattern>*Test.php</exclude-pattern>
636636
</rule>
637+
<rule ref="Magento2.Legacy.CopyrightAnotherExtensionsFiles">
638+
<severity>5</severity>
639+
<type>warning</type>
640+
</rule>
637641
<rule ref="Magento2.Legacy.Copyright">
638642
<severity>5</severity>
639643
<type>warning</type>

0 commit comments

Comments
 (0)