Skip to content

Commit 6e5f03a

Browse files
authored
Merge pull request #66 from magento-commerce/imported-magento-magento-coding-standard-272
[Imported] Version 10 master update
2 parents 64fe3cd + ec62c5c commit 6e5f03a

File tree

130 files changed

+812
-125
lines changed

Some content is hidden

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

130 files changed

+812
-125
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

+35-16
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;
@@ -108,10 +112,11 @@ public function processMemberVar(File $phpcsFile, $stackPtr)
108112
if ($varParts[1]) {
109113
return;
110114
}
111-
$error = 'Short description duplicates class property name.';
112-
$phpcsFile->addWarning($error, $isShortDescriptionAfterVar, 'AlreadyHaveMeaningFulNameVar');
115+
$error = 'Short description must be before @var tag.';
116+
$phpcsFile->addWarning($error, $isShortDescriptionAfterVar, 'ShortDescriptionAfterVar');
113117
return;
114118
}
119+
115120
// Check if class has already have meaningful description before @var tag
116121
$isShortDescriptionPreviousVar = $phpcsFile->findPrevious(
117122
T_DOC_COMMENT_STRING,
@@ -121,23 +126,37 @@ public function processMemberVar(File $phpcsFile, $stackPtr)
121126
null,
122127
false
123128
);
124-
if ($this->PHPDocFormattingValidator->providesMeaning(
125-
$isShortDescriptionPreviousVar,
126-
$commentStart,
127-
$tokens
128-
) !== true) {
129-
preg_match(
130-
'`^((?:\|?(?:array\([^\)]*\)|[\\\\\[\]]+))*)( .*)?`i',
131-
$tokens[($foundVar + 2)]['content'],
132-
$varParts
133-
);
134-
if ($varParts[1]) {
135-
return;
136-
}
129+
130+
if ($isShortDescriptionPreviousVar === false) {
131+
return;
132+
}
133+
134+
$propertyNamePosition = $phpcsFile->findNext(
135+
T_VARIABLE,
136+
$foundVar,
137+
null,
138+
false,
139+
null,
140+
false
141+
);
142+
if ($propertyNamePosition === false) {
143+
return;
144+
};
145+
$propertyName = trim($tokens[$propertyNamePosition]['content'], '$');
146+
$shortDescription = strtolower($tokens[$isShortDescriptionPreviousVar]['content']);
147+
148+
if ($shortDescription === strtolower($propertyName)) {
137149
$error = 'Short description duplicates class property name.';
138-
$phpcsFile->addWarning($error, $isShortDescriptionPreviousVar, 'AlreadyHaveMeaningFulNameVar');
150+
$phpcsFile->addWarning($error, $isShortDescriptionPreviousVar, 'AlreadyHaveMeaningfulNameVar');
139151
return;
140152
}
153+
154+
$propertyNameParts = array_filter(preg_split('/(?=[A-Z])/', $propertyName));
155+
156+
if ($shortDescription === strtolower(implode(' ', $propertyNameParts))) {
157+
$error = 'Short description duplicates class property name.';
158+
$phpcsFile->addWarning($error, $isShortDescriptionPreviousVar, 'AlreadyHaveMeaningfulNameVar');
159+
}
141160
}
142161

143162
/**

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);
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+
}
+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+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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 PHP_CodeSniffer\Files\File;
10+
use PHP_CodeSniffer\Sniffs\Sniff;
11+
12+
/**
13+
* Test for obsolete email directives in view/email/*.html
14+
*/
15+
class EmailTemplateSniff implements Sniff
16+
{
17+
private const OBSOLETE_EMAIL_DIRECTIVES = [
18+
'/\{\{htmlescape.*?\}\}/i' => 'Directive {{htmlescape}} is obsolete. Use {{var}} instead.',
19+
'/\{\{escapehtml.*?\}\}/i' => 'Directive {{escapehtml}} is obsolete. Use {{var}} instead.',
20+
];
21+
22+
private const ERROR_CODE = 'FoundObsoleteEmailDirective';
23+
24+
/**
25+
* @inheritdoc
26+
*/
27+
public function register(): array
28+
{
29+
return [
30+
T_INLINE_HTML
31+
];
32+
}
33+
34+
/**
35+
* @inheritDoc
36+
*/
37+
public function process(File $phpcsFile, $stackPtr)
38+
{
39+
$content = $phpcsFile->getTokens()[$stackPtr]['content'];
40+
foreach (self::OBSOLETE_EMAIL_DIRECTIVES as $directiveRegex => $errorMessage) {
41+
if (preg_match($directiveRegex, $content)) {
42+
$phpcsFile->addError(
43+
$errorMessage,
44+
$stackPtr,
45+
self::ERROR_CODE
46+
);
47+
}
48+
}
49+
}
50+
}

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;

0 commit comments

Comments
 (0)