Skip to content

Commit 26a3b65

Browse files
committed
Merge branch 'develop' of github.com:magento/magento-coding-standard into AC-666_AnotherExtensionsFiles
2 parents 6a735c1 + 0d6cb3c commit 26a3b65

File tree

117 files changed

+480
-103
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

117 files changed

+480
-103
lines changed

Magento2/Helpers/Commenting/PHPDocFormattingValidator.php

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

33
/**
4-
* Copyright © Magento. All rights reserved.
4+
* Copyright © Magento, Inc. All rights reserved.
55
* See COPYING.txt for license details.
66
*/
77
namespace Magento2\Helpers\Commenting;

Magento2/Sniffs/Classes/AbstractApiSniff.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22
/**
3-
* Copyright © Magento. All rights reserved.
3+
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
66
namespace Magento2\Sniffs\Classes;

Magento2/Sniffs/Classes/DiscouragedDependenciesSniff.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22
/**
3-
* Copyright © Magento. All rights reserved.
3+
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
66
namespace Magento2\Sniffs\Classes;

Magento2/Sniffs/CodeAnalysis/EmptyBlockSniff.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22
/**
3-
* Copyright © Magento. All rights reserved.
3+
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
66
namespace Magento2\Sniffs\CodeAnalysis;

Magento2/Sniffs/Commenting/ClassAndInterfacePHPDocFormattingSniff.php

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

33
/**
4-
* Copyright © Magento. All rights reserved.
4+
* Copyright © Magento, Inc. All rights reserved.
55
* See COPYING.txt for license details.
66
*/
77
namespace Magento2\Sniffs\Commenting;

Magento2/Sniffs/Commenting/ClassPropertyPHPDocFormattingSniff.php

+4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
26
namespace Magento2\Sniffs\Commenting;
37

48
use PHP_CodeSniffer\Files\File;

Magento2/Sniffs/Commenting/ConstantsPHPDocFormattingSniff.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22
/**
3-
* Copyright © Magento. All rights reserved.
3+
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
66
namespace Magento2\Sniffs\Commenting;

Magento2/Sniffs/Exceptions/DirectThrowSniff.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22
/**
3-
* Copyright © Magento. All rights reserved.
3+
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
66
namespace Magento2\Sniffs\Exceptions;

Magento2/Sniffs/Exceptions/ThrowCatchSniff.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22
/**
3-
* Copyright © Magento. All rights reserved.
3+
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
66

Magento2/Sniffs/Exceptions/TryProcessSystemResourcesSniff.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22
/**
3-
* Copyright © Magento. All rights reserved.
3+
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
66
namespace Magento2\Sniffs\Exceptions;

Magento2/Sniffs/Functions/DiscouragedFunctionSniff.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22
/**
3-
* Copyright © Magento. All rights reserved.
3+
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
66
namespace Magento2\Sniffs\Functions;

Magento2/Sniffs/Functions/StaticFunctionSniff.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22
/**
3-
* Copyright © Magento. All rights reserved.
3+
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
66
namespace Magento2\Sniffs\Functions;

Magento2/Sniffs/GraphQL/AbstractGraphQLSniff.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22
/**
3-
* Copyright © Magento. All rights reserved.
3+
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
66
namespace Magento2\Sniffs\GraphQL;

Magento2/Sniffs/GraphQL/ValidArgumentNameSniff.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22
/**
3-
* Copyright © Magento. All rights reserved.
3+
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
66

Magento2/Sniffs/GraphQL/ValidEnumValueSniff.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22
/**
3-
* Copyright © Magento. All rights reserved.
3+
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
66

Magento2/Sniffs/GraphQL/ValidFieldNameSniff.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22
/**
3-
* Copyright © Magento. All rights reserved.
3+
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
66
namespace Magento2\Sniffs\GraphQL;

Magento2/Sniffs/GraphQL/ValidTopLevelFieldNameSniff.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22
/**
3-
* Copyright © Magento. All rights reserved.
3+
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
66
namespace Magento2\Sniffs\GraphQL;

Magento2/Sniffs/GraphQL/ValidTypeNameSniff.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22
/**
3-
* Copyright © Magento. All rights reserved.
3+
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
66
namespace Magento2\Sniffs\GraphQL;

Magento2/Sniffs/Legacy/AbstractBlockSniff.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22
/**
3-
* Copyright © Magento. All rights reserved.
3+
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
66
declare(strict_types = 1);
+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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 CopyrightSniff 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()
24+
{
25+
return [T_OPEN_TAG];
26+
}
27+
28+
/**
29+
* @inheritDoc
30+
*/
31+
public function process(File $phpcsFile, $stackPtr)
32+
{
33+
if ($phpcsFile->findPrevious(T_OPEN_TAG, $stackPtr - 1) !== false) {
34+
return;
35+
}
36+
37+
$positionComment = $phpcsFile->findNext(T_DOC_COMMENT_STRING, $stackPtr);
38+
39+
if ($positionComment === false) {
40+
$phpcsFile->addWarning(
41+
'Copyright is missing',
42+
$stackPtr,
43+
self::WARNING_CODE
44+
);
45+
return;
46+
}
47+
48+
$content = $phpcsFile->getTokens()[$positionComment]['content'];
49+
$adobeCopyrightFound = preg_match(self::COPYRIGHT_ADOBE, $content);
50+
51+
if (strpos($content, self::COPYRIGHT_MAGENTO_TEXT) !== false || $adobeCopyrightFound) {
52+
return;
53+
}
54+
55+
$phpcsFile->addWarningOnLine(
56+
'Copyright is missing or has wrong format',
57+
$phpcsFile->getTokens()[$positionComment]['line'],
58+
self::WARNING_CODE
59+
);
60+
}
61+
}

Magento2/Sniffs/Legacy/MageEntitySniff.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22
/**
3-
* Copyright © Magento. All rights reserved.
3+
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
66
namespace Magento2\Sniffs\Legacy;
+114
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento2\Sniffs\Legacy;
8+
9+
use DOMDocument;
10+
use PHP_CodeSniffer\Files\File;
11+
use PHP_CodeSniffer\Sniffs\Sniff;
12+
13+
/**
14+
* Test for obsolete nodes/attributes in the widget.xml
15+
*/
16+
class WidgetXMLSniff implements Sniff
17+
{
18+
private const ERROR_CODE_OBSOLETE = 'FoundObsoleteNode';
19+
private const ERROR_CODE_FACTORY = 'FoundFactory';
20+
private const ERROR_CODE_XML = 'WrongXML';
21+
22+
/**
23+
* @inheritdoc
24+
*/
25+
public function register(): array
26+
{
27+
return [
28+
T_INLINE_HTML
29+
];
30+
}
31+
32+
/**
33+
* @inheritDoc
34+
*/
35+
public function process(File $phpcsFile, $stackPtr)
36+
{
37+
if ($stackPtr > 0) {
38+
return;
39+
}
40+
41+
$xml = simplexml_load_string($this->getFormattedXML($phpcsFile));
42+
43+
if ($xml === false) {
44+
$this->invalidXML($phpcsFile, $stackPtr);
45+
return;
46+
}
47+
48+
$foundElements = $xml->xpath('/widgets/*[@type]');
49+
50+
foreach ($foundElements as $element) {
51+
if (!property_exists($element->attributes(), 'type')) {
52+
continue;
53+
}
54+
$type = $element['type'];
55+
if (preg_match('/\//', $type)) {
56+
$phpcsFile->addError(
57+
"Factory name detected: {$type}.",
58+
dom_import_simplexml($element)->getLineNo() - 1,
59+
self::ERROR_CODE_FACTORY
60+
);
61+
}
62+
}
63+
64+
$foundElements = $xml->xpath('/widgets/*/supported_blocks');
65+
foreach ($foundElements as $element) {
66+
$phpcsFile->addError(
67+
"Obsolete node: <supported_blocks>. To be replaced with <supported_containers>",
68+
dom_import_simplexml($element)->getLineNo() - 1,
69+
self::ERROR_CODE_OBSOLETE
70+
);
71+
}
72+
73+
$foundElements = $xml->xpath('/widgets/*/*/*/block_name');
74+
foreach ($foundElements as $element) {
75+
$phpcsFile->addError(
76+
"Obsolete node: <block_name>. To be replaced with <container_name>",
77+
dom_import_simplexml($element)->getLineNo() - 1,
78+
self::ERROR_CODE_OBSOLETE
79+
);
80+
}
81+
}
82+
83+
/**
84+
* Adds an invalid XML error
85+
*
86+
* @param File $phpcsFile
87+
* @param int $stackPtr
88+
*/
89+
protected function invalidXML(File $phpcsFile, int $stackPtr): void
90+
{
91+
$phpcsFile->addError(
92+
sprintf(
93+
"Couldn't parse contents of '%s', check that they are in valid XML format",
94+
$phpcsFile->getFilename(),
95+
),
96+
$stackPtr,
97+
self::ERROR_CODE_XML
98+
);
99+
}
100+
101+
/**
102+
* Format the incoming XML to avoid tags split into several lines.
103+
*
104+
* @param File $phpcsFile
105+
* @return false|string
106+
*/
107+
private function getFormattedXML(File $phpcsFile)
108+
{
109+
$doc = new DomDocument('1.0');
110+
$doc->formatOutput = true;
111+
$doc->loadXML($phpcsFile->getTokensAsString(0, 999999));
112+
return $doc->saveXML();
113+
}
114+
}

Magento2/Sniffs/Methods/DeprecatedModelMethodSniff.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22
/**
3-
* Copyright © Magento. All rights reserved.
3+
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
66
namespace Magento2\Sniffs\Methods;

Magento2/Sniffs/Namespaces/ImportsFromTestNamespaceSniff.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22
/**
3-
* Copyright © Magento. All rights reserved.
3+
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
66
namespace Magento2\Sniffs\Namespaces;

Magento2/Sniffs/NamingConvention/InterfaceNameSniff.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22
/**
3-
* Copyright © Magento. All rights reserved.
3+
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
66
namespace Magento2\Sniffs\NamingConvention;

Magento2/Sniffs/PHP/FinalImplementationSniff.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22
/**
3-
* Copyright © Magento. All rights reserved.
3+
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
66
namespace Magento2\Sniffs\PHP;

Magento2/Sniffs/PHP/GotoSniff.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22
/**
3-
* Copyright © Magento. All rights reserved.
3+
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
66
namespace Magento2\Sniffs\PHP;

Magento2/Sniffs/PHP/ReturnValueCheckSniff.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22
/**
3-
* Copyright © Magento. All rights reserved.
3+
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
66
namespace Magento2\Sniffs\PHP;

Magento2/Sniffs/PHP/VarSniff.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22
/**
3-
* Copyright © Magento. All rights reserved.
3+
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
66
namespace Magento2\Sniffs\PHP;

0 commit comments

Comments
 (0)