Skip to content

Version 10 master update #272

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 44 commits into from
Sep 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
ac5f9fd
AC-667: Create phpcs static check for EmailTemplateTest
jcuerdo Sep 7, 2021
0cb8f67
AC-667: Create phpcs static check for EmailTemplateTest
jcuerdo Sep 7, 2021
4a78a94
AC-667: Create phpcs static check for EmailTemplateTest
jcuerdo Sep 7, 2021
e4698fb
AC-667: Create phpcs static check for EmailTemplateTest
jcuerdo Sep 7, 2021
e4f5540
Update Magento2/ruleset.xml
jcuerdo Sep 8, 2021
2751031
AC-667: Create phpcs static check for EmailTemplateTest
jcuerdo Sep 8, 2021
e3f4d87
Merge pull request #58 from magento-commerce/imported-magento-magento…
jcuerdo Sep 8, 2021
8b2cd90
AC-666: Create phpcs static check for CopyrightTest
eliseacornejo Sep 9, 2021
702cd60
AC-661: Create phpcs static check for XmlTest
jcuerdo Sep 9, 2021
76359c2
AC-661: Create phpcs static check for XmlTest
jcuerdo Sep 9, 2021
e2c2d07
AC-666: Create phpcs static check for CopyrightTest
eliseacornejo Sep 9, 2021
a25e2ca
AC-661: Create phpcs static check for XmlTest
jcuerdo Sep 9, 2021
dc49aaa
AC-661: Create phpcs static check for XmlTest
jcuerdo Sep 9, 2021
f4b0117
AC-666: Create phpcs static check for CopyrightTest
eliseacornejo Sep 9, 2021
64512dd
AC-661: Create phpcs static check for XmlTest
jcuerdo Sep 9, 2021
df14044
AC-661: Create phpcs static check for XmlTest
jcuerdo Sep 9, 2021
2f4c72e
AC-661: Create phpcs static check for XmlTest
jcuerdo Sep 9, 2021
7a6f29f
AC-666: Create phpcs static check for CopyrightTest
eliseacornejo Sep 9, 2021
a2864d2
AC-666: Create phpcs static check for CopyrightTest
eliseacornejo Sep 13, 2021
74c47b2
AC-661: Create phpcs static check for XmlTest
jcuerdo Sep 13, 2021
dae1ab3
AC-661: Create phpcs static check for XmlTest
jcuerdo Sep 13, 2021
d528da6
AC-666: Static check for CopyrightTest for another extensions files
eliseacornejo Sep 13, 2021
6a735c1
AC-666: Static check for CopyrightTest for another extensions files
eliseacornejo Sep 13, 2021
9b4da0c
Merge pull request #60 from magento-commerce/imported-magento-magento…
jcuerdo Sep 13, 2021
0d6cb3c
Merge pull request #61 from magento-commerce/imported-magento-magento…
eliseacornejo Sep 13, 2021
26a3b65
Merge branch 'develop' of github.com:magento/magento-coding-standard …
eliseacornejo Sep 13, 2021
b00d7cf
Merge pull request #62 from magento-commerce/imported-magento-magento…
eliseacornejo Sep 13, 2021
ef00afd
Fixed wrongly returning error for valid descriptions
svera Sep 13, 2021
95c56c9
Update Magento2/Sniffs/Commenting/ClassPropertyPHPDocFormattingSniff.php
svera Sep 14, 2021
2a57af8
Update Magento2/Sniffs/Commenting/ClassPropertyPHPDocFormattingSniff.php
svera Sep 14, 2021
f209db6
Fixed wrongly returning error for valid descriptions
svera Sep 14, 2021
1ed4156
Fixed wrongly returning error for valid descriptions
svera Sep 14, 2021
efaffac
Fixed wrongly returning error for valid descriptions
svera Sep 14, 2021
62e0fc1
Fixed wrongly returning error for valid descriptions
svera Sep 14, 2021
5b4b543
Fixed wrongly returning error for valid descriptions
svera Sep 14, 2021
0c29f5b
Fixed wrongly returning error for valid descriptions
svera Sep 14, 2021
3fb9cba
Fixed wrongly returning error for valid descriptions
svera Sep 14, 2021
d238849
Fixed wrongly returning error for valid descriptions
svera Sep 14, 2021
e92e17d
Fixed wrongly returning error for valid descriptions
svera Sep 14, 2021
0fb55fc
Fixed wrongly returning error for valid descriptions
svera Sep 14, 2021
a25482e
Merge pull request #63 from magento-commerce/imported-svera-magento-c…
svera Sep 14, 2021
813a761
Increased version to 10
svera Sep 14, 2021
f7df455
Increased version to 10
svera Sep 14, 2021
ec62c5c
Merge pull request #65 from magento-commerce/imported-svera-magento-c…
sivaschenko Sep 14, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Magento2/Helpers/Commenting/PHPDocFormattingValidator.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

/**
* Copyright © Magento. All rights reserved.
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento2\Helpers\Commenting;
Expand Down
2 changes: 1 addition & 1 deletion Magento2/Sniffs/Classes/AbstractApiSniff.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Copyright © Magento. All rights reserved.
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento2\Sniffs\Classes;
Expand Down
2 changes: 1 addition & 1 deletion Magento2/Sniffs/Classes/DiscouragedDependenciesSniff.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Copyright © Magento. All rights reserved.
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento2\Sniffs\Classes;
Expand Down
2 changes: 1 addition & 1 deletion Magento2/Sniffs/CodeAnalysis/EmptyBlockSniff.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Copyright © Magento. All rights reserved.
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento2\Sniffs\CodeAnalysis;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

/**
* Copyright © Magento. All rights reserved.
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento2\Sniffs\Commenting;
Expand Down
51 changes: 35 additions & 16 deletions Magento2/Sniffs/Commenting/ClassPropertyPHPDocFormattingSniff.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento2\Sniffs\Commenting;

use PHP_CodeSniffer\Files\File;
Expand Down Expand Up @@ -108,10 +112,11 @@ public function processMemberVar(File $phpcsFile, $stackPtr)
if ($varParts[1]) {
return;
}
$error = 'Short description duplicates class property name.';
$phpcsFile->addWarning($error, $isShortDescriptionAfterVar, 'AlreadyHaveMeaningFulNameVar');
$error = 'Short description must be before @var tag.';
$phpcsFile->addWarning($error, $isShortDescriptionAfterVar, 'ShortDescriptionAfterVar');
return;
}

// Check if class has already have meaningful description before @var tag
$isShortDescriptionPreviousVar = $phpcsFile->findPrevious(
T_DOC_COMMENT_STRING,
Expand All @@ -121,23 +126,37 @@ public function processMemberVar(File $phpcsFile, $stackPtr)
null,
false
);
if ($this->PHPDocFormattingValidator->providesMeaning(
$isShortDescriptionPreviousVar,
$commentStart,
$tokens
) !== true) {
preg_match(
'`^((?:\|?(?:array\([^\)]*\)|[\\\\\[\]]+))*)( .*)?`i',
$tokens[($foundVar + 2)]['content'],
$varParts
);
if ($varParts[1]) {
return;
}

if ($isShortDescriptionPreviousVar === false) {
return;
}

$propertyNamePosition = $phpcsFile->findNext(
T_VARIABLE,
$foundVar,
null,
false,
null,
false
);
if ($propertyNamePosition === false) {
return;
};
$propertyName = trim($tokens[$propertyNamePosition]['content'], '$');
$shortDescription = strtolower($tokens[$isShortDescriptionPreviousVar]['content']);

if ($shortDescription === strtolower($propertyName)) {
$error = 'Short description duplicates class property name.';
$phpcsFile->addWarning($error, $isShortDescriptionPreviousVar, 'AlreadyHaveMeaningFulNameVar');
$phpcsFile->addWarning($error, $isShortDescriptionPreviousVar, 'AlreadyHaveMeaningfulNameVar');
return;
}

$propertyNameParts = array_filter(preg_split('/(?=[A-Z])/', $propertyName));

if ($shortDescription === strtolower(implode(' ', $propertyNameParts))) {
$error = 'Short description duplicates class property name.';
$phpcsFile->addWarning($error, $isShortDescriptionPreviousVar, 'AlreadyHaveMeaningfulNameVar');
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Copyright © Magento. All rights reserved.
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento2\Sniffs\Commenting;
Expand Down
2 changes: 1 addition & 1 deletion Magento2/Sniffs/Exceptions/DirectThrowSniff.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Copyright © Magento. All rights reserved.
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento2\Sniffs\Exceptions;
Expand Down
2 changes: 1 addition & 1 deletion Magento2/Sniffs/Exceptions/ThrowCatchSniff.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Copyright © Magento. All rights reserved.
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Copyright © Magento. All rights reserved.
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento2\Sniffs\Exceptions;
Expand Down
2 changes: 1 addition & 1 deletion Magento2/Sniffs/Functions/DiscouragedFunctionSniff.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Copyright © Magento. All rights reserved.
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento2\Sniffs\Functions;
Expand Down
2 changes: 1 addition & 1 deletion Magento2/Sniffs/Functions/StaticFunctionSniff.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Copyright © Magento. All rights reserved.
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento2\Sniffs\Functions;
Expand Down
2 changes: 1 addition & 1 deletion Magento2/Sniffs/GraphQL/AbstractGraphQLSniff.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Copyright © Magento. All rights reserved.
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento2\Sniffs\GraphQL;
Expand Down
2 changes: 1 addition & 1 deletion Magento2/Sniffs/GraphQL/ValidArgumentNameSniff.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Copyright © Magento. All rights reserved.
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

Expand Down
2 changes: 1 addition & 1 deletion Magento2/Sniffs/GraphQL/ValidEnumValueSniff.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Copyright © Magento. All rights reserved.
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

Expand Down
2 changes: 1 addition & 1 deletion Magento2/Sniffs/GraphQL/ValidFieldNameSniff.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Copyright © Magento. All rights reserved.
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento2\Sniffs\GraphQL;
Expand Down
2 changes: 1 addition & 1 deletion Magento2/Sniffs/GraphQL/ValidTopLevelFieldNameSniff.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Copyright © Magento. All rights reserved.
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento2\Sniffs\GraphQL;
Expand Down
2 changes: 1 addition & 1 deletion Magento2/Sniffs/GraphQL/ValidTypeNameSniff.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Copyright © Magento. All rights reserved.
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento2\Sniffs\GraphQL;
Expand Down
2 changes: 1 addition & 1 deletion Magento2/Sniffs/Legacy/AbstractBlockSniff.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Copyright © Magento. All rights reserved.
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types = 1);
Expand Down
52 changes: 52 additions & 0 deletions Magento2/Sniffs/Legacy/CopyrightAnotherExtensionsFilesSniff.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types = 1);

namespace Magento2\Sniffs\Legacy;

use PHP_CodeSniffer\Files\File;
use PHP_CodeSniffer\Sniffs\Sniff;

class CopyrightAnotherExtensionsFilesSniff implements Sniff
{
private const WARNING_CODE = 'FoundCopyrightMissingOrWrongFormat';

private const COPYRIGHT_MAGENTO_TEXT = 'Copyright © Magento, Inc. All rights reserved.';
private const COPYRIGHT_ADOBE = '/Copyright \d+ Adobe/';

/**
* @inheritDoc
*/
public function register(): array
{
return [
T_INLINE_HTML
];
}

/**
* @inheritDoc
*/
public function process(File $phpcsFile, $stackPtr)
{
if ($stackPtr > 0) {
return;
}

$fileText = $phpcsFile->getTokensAsString($stackPtr, count($phpcsFile->getTokens()));
$adobeCopyrightFound = preg_match(self::COPYRIGHT_ADOBE, $fileText);

if (strpos($fileText, self::COPYRIGHT_MAGENTO_TEXT) !== false || $adobeCopyrightFound) {
return;
}

$phpcsFile->addWarningOnLine(
'Copyright is missing or has wrong format',
null,
self::WARNING_CODE
);
}
}
61 changes: 61 additions & 0 deletions Magento2/Sniffs/Legacy/CopyrightSniff.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types = 1);

namespace Magento2\Sniffs\Legacy;

use PHP_CodeSniffer\Files\File;
use PHP_CodeSniffer\Sniffs\Sniff;

class CopyrightSniff implements Sniff
{
private const WARNING_CODE = 'FoundCopyrightMissingOrWrongFormat';

private const COPYRIGHT_MAGENTO_TEXT = 'Copyright © Magento, Inc. All rights reserved.';
private const COPYRIGHT_ADOBE = '/Copyright \d+ Adobe/';

/**
* @inheritdoc
*/
public function register()
{
return [T_OPEN_TAG];
}

/**
* @inheritDoc
*/
public function process(File $phpcsFile, $stackPtr)
{
if ($phpcsFile->findPrevious(T_OPEN_TAG, $stackPtr - 1) !== false) {
return;
}

$positionComment = $phpcsFile->findNext(T_DOC_COMMENT_STRING, $stackPtr);

if ($positionComment === false) {
$phpcsFile->addWarning(
'Copyright is missing',
$stackPtr,
self::WARNING_CODE
);
return;
}

$content = $phpcsFile->getTokens()[$positionComment]['content'];
$adobeCopyrightFound = preg_match(self::COPYRIGHT_ADOBE, $content);

if (strpos($content, self::COPYRIGHT_MAGENTO_TEXT) !== false || $adobeCopyrightFound) {
return;
}

$phpcsFile->addWarningOnLine(
'Copyright is missing or has wrong format',
$phpcsFile->getTokens()[$positionComment]['line'],
self::WARNING_CODE
);
}
}
50 changes: 50 additions & 0 deletions Magento2/Sniffs/Legacy/EmailTemplateSniff.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento2\Sniffs\Legacy;

use PHP_CodeSniffer\Files\File;
use PHP_CodeSniffer\Sniffs\Sniff;

/**
* Test for obsolete email directives in view/email/*.html
*/
class EmailTemplateSniff implements Sniff
{
private const OBSOLETE_EMAIL_DIRECTIVES = [
'/\{\{htmlescape.*?\}\}/i' => 'Directive {{htmlescape}} is obsolete. Use {{var}} instead.',
'/\{\{escapehtml.*?\}\}/i' => 'Directive {{escapehtml}} is obsolete. Use {{var}} instead.',
];

private const ERROR_CODE = 'FoundObsoleteEmailDirective';

/**
* @inheritdoc
*/
public function register(): array
{
return [
T_INLINE_HTML
];
}

/**
* @inheritDoc
*/
public function process(File $phpcsFile, $stackPtr)
{
$content = $phpcsFile->getTokens()[$stackPtr]['content'];
foreach (self::OBSOLETE_EMAIL_DIRECTIVES as $directiveRegex => $errorMessage) {
if (preg_match($directiveRegex, $content)) {
$phpcsFile->addError(
$errorMessage,
$stackPtr,
self::ERROR_CODE
);
}
}
}
}
2 changes: 1 addition & 1 deletion Magento2/Sniffs/Legacy/MageEntitySniff.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Copyright © Magento. All rights reserved.
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento2\Sniffs\Legacy;
Expand Down
Loading