Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: magento/magento-coding-standard
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v32
Choose a base ref
...
head repository: magento/magento-coding-standard
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v33
Choose a head ref

Commits on Jan 11, 2022

  1. Copy the full SHA
    83ddd30 View commit details
  2. Copy the full SHA
    0f1c1f1 View commit details
  3. Disallow useless constructs

    fredden committed Jan 11, 2022
    Copy the full SHA
    241f932 View commit details

Commits on Jan 25, 2022

  1. Allow Template Literals

    pykettk authored Jan 25, 2022
    Copy the full SHA
    784a702 View commit details

Commits on Mar 4, 2022

  1. Add semicolon as statement separator in the special annotation check …

    …of the `Magento2.Security.XssTemplate` sniff
    aadmathijssen committed Mar 4, 2022
    Copy the full SHA
    21db432 View commit details

Commits on Jul 13, 2022

  1. Copy the full SHA
    b67b072 View commit details

Commits on Jan 26, 2023

  1. Automatically remove useless comments

    When issues are detected and classified as
    Magento2.Commenting.ClassAndInterfacePHPDocFormatting.ForbiddenTags or
    Magento2.Commenting.ClassAndInterfacePHPDocFormatting.InvalidDescription,
    these can be fixed by removing the offending comment.
    fredden committed Jan 26, 2023
    Copy the full SHA
    5936239 View commit details

Commits on Feb 14, 2023

  1. Copy the full SHA
    18a4579 View commit details

Commits on Mar 30, 2023

  1. Copy the full SHA
    252371e View commit details

Commits on Apr 15, 2023

  1. Copy the full SHA
    ed981cf View commit details

Commits on May 16, 2023

  1. Copy the full SHA
    350cf9a View commit details

Commits on May 24, 2023

  1. Copy the full SHA
    cf43987 View commit details

Commits on Jun 12, 2023

  1. Copy the full SHA
    087b1a2 View commit details
  2. Copy the full SHA
    889b4d2 View commit details

Commits on Jul 6, 2023

  1. Copy the full SHA
    7b6bd74 View commit details
  2. Add docblock to appease coding standard

    Note that these are useless, as it's the default behaviour to inherit from the
    parent docblock.
    fredden committed Jul 6, 2023
    Copy the full SHA
    b8acb6c View commit details

Commits on Jul 26, 2023

  1. Update README.md

    Fixed a typo in readme.md
    snoop0x7b authored Jul 26, 2023
    Copy the full SHA
    5497f3f View commit details

Commits on Sep 14, 2023

  1. Copy the full SHA
    cac6058 View commit details

Commits on Sep 20, 2023

  1. Merge pull request #237 from magento-commerce/imported-fredden-magent…

    …o-coding-standard-469
    
    [Imported] Allow more recent versions of rector
    sidolov authored Sep 20, 2023
    Copy the full SHA
    e9b46ea View commit details
  2. Removing dependency on symfony/polyfill, is no longer required now th…

    …at we dropped support for PHP 7.4
    hostep committed Sep 20, 2023
    Copy the full SHA
    8f01c09 View commit details
  3. Merge pull request #238 from magento-commerce/imported-hostep-magento…

    …-coding-standard-468
    
    [Imported] Removing dependency on symfony/polyfill, is no longer required now th…
    sidolov authored Sep 20, 2023
    Copy the full SHA
    a0b6fc9 View commit details
  4. Merge pull request #239 from magento-commerce/imported-sandipklevu-ma…

    …gento-coding-standard-447
    
    [Imported] Allow readonly between phpdoc and property name
    sidolov authored Sep 20, 2023
    Copy the full SHA
    7f3030b View commit details
  5. Merge pull request #240 from magento-commerce/imported-fredden-magent…

    …o-coding-standard-445
    
    [Imported] Add suggested replacement for \posix_isatty()
    sidolov authored Sep 20, 2023
    Copy the full SHA
    b7bf3fb View commit details
  6. Merge pull request #241 from magento-commerce/imported-pykettk-magent…

    …o-coding-standard-442
    
    [Imported] Make Unescaped Output Fail With Error Severity 10
    sidolov authored Sep 20, 2023
    Copy the full SHA
    6197724 View commit details
  7. Merge pull request #242 from magento-commerce/imported-fredden-magent…

    …o-coding-standard-458
    
    [Imported] Add sniff for deprecated use of $block->escape... methods
    sidolov authored Sep 20, 2023
    Copy the full SHA
    153e14a View commit details
  8. Merge pull request #243 from magento-commerce/imported-fredden-magent…

    …o-coding-standard-361
    
    [Imported] [eslint] Disallow useless constructs
    sidolov authored Sep 20, 2023
    Copy the full SHA
    dccf910 View commit details
  9. Merge pull request #244 from magento-commerce/imported-fredden-magent…

    …o-coding-standard-358
    
    [Imported] [eslint] Enforce consistent indentation
    sidolov authored Sep 20, 2023
    Copy the full SHA
    60be03f View commit details
  10. Copy the full SHA
    045be18 View commit details
  11. Merge pull request #245 from magento-commerce/imported-fredden-magent…

    …o-coding-standard-359
    
    [Imported] [eslint] Forbid overriding built-in objects
    sidolov authored Sep 20, 2023
    Copy the full SHA
    c8ce5be View commit details
  12. Merge pull request #246 from magento-commerce/imported-pykettk-magent…

    …o-coding-standard-364
    
    [Imported] Allow Use of Template Literals
    sidolov authored Sep 20, 2023
    Copy the full SHA
    6e8b466 View commit details
  13. Merge pull request #247 from magento-commerce/imported-isaaceindhoven…

    …-magento-coding-standard-378
    
    [Imported] Add semicolon as statement separator in the special annotation check of the `Magento2.Security.XssTemplate` sniff
    sidolov authored Sep 20, 2023
    Copy the full SHA
    b7c053f View commit details

Commits on Sep 26, 2023

  1. Merge pull request #248 from magento-commerce/imported-snoop0x7b-mage…

    …nto-coding-standard-459
    
    [Imported] Update README.md
    sidolov authored Sep 26, 2023
    Copy the full SHA
    5c20e3e View commit details
  2. Merge pull request #249 from magento-commerce/imported-fredden-magent…

    …o-coding-standard-356
    
    [Imported] [eslint] Enforce consistent spacing around keywords
    sidolov authored Sep 26, 2023
    Copy the full SHA
    a9d34af View commit details
  3. Merge pull request #250 from magento-commerce/imported-fredden-magent…

    …o-coding-standard-433
    
    [Imported] Automatically remove useless comments
    sidolov authored Sep 26, 2023
    Copy the full SHA
    d1711ba View commit details

Commits on Sep 27, 2023

  1. Merge pull request #251 from magento-commerce/imported-fredden-magent…

    …o-coding-standard-437
    
    [Imported] Ensure only the relevant docblock is read
    sidolov authored Sep 27, 2023
    Copy the full SHA
    78200c1 View commit details
  2. Merge pull request #252 from magento-commerce/imported-fredden-magent…

    …o-coding-standard-417
    
    [Imported] Include all Magento2 sniffs in Magento2Framework
    sidolov authored Sep 27, 2023
    Copy the full SHA
    6cbe6a3 View commit details

Commits on Nov 14, 2023

  1. Copy the full SHA
    6db538b View commit details
  2. Copy the full SHA
    3b504d5 View commit details

Commits on Nov 30, 2023

  1. ACP2E-2635: Replace phpcompatibility/php-compatibility with magento/p…

    …hp-compatibility-fork
    
    * Fix fatal error in MethodAnnotationStructureSniff when there is no comment preceding a function or class method
    bubasuma committed Nov 30, 2023
    Copy the full SHA
    2a50cc7 View commit details

Commits on Dec 1, 2023

  1. Merge pull request #253 from magento-l3/ACP2E-2635

    ACP2E-2635: Replace phpcompatibility/php-compatibility with magento/php-compatibility-fork
    victor-v-rad authored Dec 1, 2023
    Copy the full SHA
    7aef678 View commit details

Commits on Dec 4, 2023

  1. Copy the full SHA
    a72c166 View commit details
  2. Merge pull request #254 from magento-l3/ACP2E-2674

    ACP2E-2674: [MCS] Fix duplicate "Comment block is missing"
    victor-v-rad authored Dec 4, 2023
    Copy the full SHA
    372d4c6 View commit details

Commits on Dec 6, 2023

  1. Copy the full SHA
    d142dbb View commit details

Commits on Dec 15, 2023

  1. Copy the full SHA
    cf0c761 View commit details

Commits on Dec 19, 2023

  1. Copy the full SHA
    3b9314d View commit details
  2. Copy the full SHA
    b167086 View commit details
  3. Merge pull request #255 from magento-gl/Hammer_PlatForm_Health_247Beta3

    [Hammer][Platform Health 247-beta3] PHP8.3 Support
    sidolov authored Dec 19, 2023
    Copy the full SHA
    7521587 View commit details
Showing with 1,061 additions and 295 deletions.
  1. +2 −1 .github/workflows/php.yml
  2. +24 −4 Magento2/Sniffs/Annotation/MethodAnnotationStructureSniff.php
  3. +40 −2 Magento2/Sniffs/Commenting/ClassAndInterfacePHPDocFormattingSniff.php
  4. +1 −0 Magento2/Sniffs/Commenting/ClassPropertyPHPDocFormattingSniff.php
  5. +1 −0 Magento2/Sniffs/Functions/DiscouragedFunctionSniff.php
  6. +106 −0 Magento2/Sniffs/Legacy/EscapeMethodsOnBlockClassSniff.php
  7. +2 −2 Magento2/Sniffs/Security/XssTemplateSniff.php
  8. +61 −1 Magento2/Tests/Annotation/MethodAnnotationStructureUnitTest.inc
  9. +7 −1 Magento2/Tests/Annotation/MethodAnnotationStructureUnitTest.php
  10. +7 −0 Magento2/Tests/Commenting/ClassAndInterfacePHPDocFormattingUnitTest.1.inc
  11. +165 −0 Magento2/Tests/Commenting/ClassAndInterfacePHPDocFormattingUnitTest.1.inc.fixed
  12. +17 −0 Magento2/Tests/Commenting/ClassAndInterfacePHPDocFormattingUnitTest.2.inc
  13. +165 −0 Magento2/Tests/Commenting/ClassAndInterfacePHPDocFormattingUnitTest.2.inc.fixed
  14. +2 −1 Magento2/Tests/Commenting/ClassAndInterfacePHPDocFormattingUnitTest.php
  15. +10 −0 Magento2/Tests/Commenting/ClassPropertyPHPDocFormattingUnitTest.inc
  16. +87 −0 Magento2/Tests/Legacy/EscapeMethodsOnBlockClassUnitTest.inc
  17. +87 −0 Magento2/Tests/Legacy/EscapeMethodsOnBlockClassUnitTest.inc.fixed
  18. +45 −0 Magento2/Tests/Legacy/EscapeMethodsOnBlockClassUnitTest.php
  19. +7 −1 Magento2/ruleset.xml
  20. +2 −0 Magento2Framework/ruleset.xml
  21. +1 −1 README.md
  22. +7 −8 composer.json
  23. +193 −259 composer.lock
  24. +10 −2 eslint/.eslintrc-magento
  25. +12 −12 eslint/rules/utils.js
3 changes: 2 additions & 1 deletion .github/workflows/php.yml
Original file line number Diff line number Diff line change
@@ -15,6 +15,7 @@ jobs:
php-version:
- "8.1"
- "8.2"
- "8.3"
dependencies:
- "lowest"
- "highest"
@@ -89,4 +90,4 @@ jobs:
run: composer install

- name: Run rector
run: vendor/bin/rector process Magento2 Magento2Framework PHP_CodeSniffer --dry-run --autoload-file vendor/squizlabs/php_codesniffer/autoload.php --autoload-file vendor/phpcompatibility/php-compatibility/PHPCSAliases.php
run: vendor/bin/rector process Magento2 Magento2Framework PHP_CodeSniffer --dry-run --autoload-file vendor/squizlabs/php_codesniffer/autoload.php --autoload-file vendor/magento/php-compatibility-fork/PHPCSAliases.php
28 changes: 24 additions & 4 deletions Magento2/Sniffs/Annotation/MethodAnnotationStructureSniff.php
Original file line number Diff line number Diff line change
@@ -51,13 +51,33 @@ public function register()
public function process(File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();
$commentStartPtr = $phpcsFile->findPrevious(T_DOC_COMMENT_OPEN_TAG, ($stackPtr), 0);
$commentEndPtr = $phpcsFile->findPrevious(T_DOC_COMMENT_CLOSE_TAG, ($stackPtr), 0);
if (!$commentStartPtr) {
$phpcsFile->addError('Comment block is missing', $stackPtr, 'MethodArguments');
$commentEndPtr = $stackPtr;
$tokensToFind = [
\T_SEMICOLON,
\T_OPEN_CURLY_BRACKET,
\T_CLOSE_CURLY_BRACKET,
\T_ATTRIBUTE_END,
\T_DOC_COMMENT_CLOSE_TAG
];

do {
$commentEndPtr = $phpcsFile->findPrevious($tokensToFind, $commentEndPtr - 1);
if ($commentEndPtr !== false
&& $tokens[$commentEndPtr]['code'] === \T_ATTRIBUTE_END
&& isset($tokens[$commentEndPtr]['attribute_opener'])
) {
$commentEndPtr = $tokens[$commentEndPtr]['attribute_opener'];
}
} while ($commentEndPtr !== false && !in_array($tokens[$commentEndPtr]['code'], $tokensToFind, true));

if ($commentEndPtr === false || $tokens[$commentEndPtr]['code'] !== \T_DOC_COMMENT_CLOSE_TAG) {
$phpcsFile->addError('Comment block is missing', $stackPtr, 'NoCommentBlock');
return;
}

$commentStartPtr = $tokens[$commentEndPtr]['comment_opener']
?? $phpcsFile->findPrevious(T_DOC_COMMENT_OPEN_TAG, $commentEndPtr - 1);

if ($this->PHPDocFormattingValidator->hasDeprecatedWellFormatted($commentStartPtr, $tokens) !== true) {
$phpcsFile->addWarning(
'Motivation behind the added @deprecated tag MUST be explained. '
Original file line number Diff line number Diff line change
@@ -63,15 +63,29 @@ public function process(File $phpcsFile, $stackPtr)
return;
}

$commentCloserPtr = $tokens[$commentStartPtr]['comment_closer'];

if ($this->PHPDocFormattingValidator->providesMeaning($namePtr, $commentStartPtr, $tokens) !== true) {
$phpcsFile->addWarning(
$fix = $phpcsFile->addFixableWarning(
sprintf(
'%s description must contain meaningful information beyond what its name provides or be removed.',
ucfirst($tokens[$stackPtr]['content'])
),
$stackPtr,
'InvalidDescription'
);

if ($fix) {
for ($i = $commentStartPtr; $i <= $commentCloserPtr; $i++) {
$phpcsFile->fixer->replaceToken($i, '');
}

if ($tokens[$commentStartPtr - 1]['code'] === T_WHITESPACE
&& $tokens[$commentCloserPtr + 1]['code'] === T_WHITESPACE
) {
$phpcsFile->fixer->replaceToken($commentCloserPtr + 1, '');
}
}
}

if ($this->PHPDocFormattingValidator->hasDeprecatedWellFormatted($commentStartPtr, $tokens) !== true) {
@@ -105,11 +119,35 @@ private function validateTags(File $phpcsFile, $commentStartPtr, $tokens)
}

if (in_array($tokens[$i]['content'], $this->forbiddenTags) === true) {
$phpcsFile->addWarning(
$fix = $phpcsFile->addFixableWarning(
sprintf('Tag %s MUST NOT be used.', $tokens[$i]['content']),
$i,
'ForbiddenTags'
);

if ($fix) {
for ($j = $i - 1; $j > $commentStartPtr; $j--) {
if (!in_array($tokens[$j]['code'], [T_DOC_COMMENT_STAR, T_DOC_COMMENT_WHITESPACE], true)) {
break;
}

if ($tokens[$j]['code'] === T_DOC_COMMENT_WHITESPACE && $tokens[$j]['content'] === "\n") {
break;
}

$phpcsFile->fixer->replaceToken($j, '');
}

$phpcsFile->fixer->replaceToken($i, '');

for ($j = $i + 1; $j < $commentCloserPtr; $j++) {
$phpcsFile->fixer->replaceToken($j, '');

if ($tokens[$j]['code'] === T_DOC_COMMENT_WHITESPACE && $tokens[$j]['content'] === "\n") {
break;
}
}
}
}
}

Original file line number Diff line number Diff line change
@@ -32,6 +32,7 @@ class ClassPropertyPHPDocFormattingSniff extends AbstractVariableSniff
T_NULLABLE,
T_BITWISE_AND,
T_TYPE_UNION,
T_READONLY,
];

/**
1 change: 1 addition & 0 deletions Magento2/Sniffs/Functions/DiscouragedFunctionSniff.php
Original file line number Diff line number Diff line change
@@ -104,6 +104,7 @@ class DiscouragedFunctionSniff extends ForbiddenFunctionsSniff
'^parsekit_compile_string$' => null,
'^pathinfo$' => 'Magento\Framework\Filesystem\Io\File::getPathInfo',
'^pcntl_.*$' => null,
'^posix_isatty$' => 'stream_isatty',
'^posix_.*$' => null,
'^pfpro_.*$' => null,
'^pfsockopen$' => null,
106 changes: 106 additions & 0 deletions Magento2/Sniffs/Legacy/EscapeMethodsOnBlockClassSniff.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
<?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;
use PHP_CodeSniffer\Util\Tokens;

class EscapeMethodsOnBlockClassSniff implements Sniff
{
private const ESCAPER_METHODS = [
'escapeCss' => true,
'escapeHtml' => true,
'escapeHtmlAttr' => true,
'escapeJs' => true,
'escapeJsQuote' => true,
'escapeQuote' => true,
'escapeUrl' => true,
'escapeXssInUrl' => true,
];

/**
* @inheritDoc
*/
public function register()
{
return [
T_OBJECT_OPERATOR,
];
}

/**
* @inheritDoc
*/
public function process(File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();

if ($stackPtr <= 1 || !isset($tokens[$stackPtr + 2])) {
return;
}

$objectPtr = $stackPtr - 1;
if ($tokens[$objectPtr]['code'] !== T_VARIABLE) {
$objectPtr = $phpcsFile->findPrevious(Tokens::$emptyTokens, $objectPtr, null, true);

if (!$objectPtr) {
return;
}
}

if ($tokens[$objectPtr]['code'] !== T_VARIABLE
|| $tokens[$objectPtr]['content'] !== '$block'
) {
return;
}

$methodPtr = $stackPtr + 1;
if ($tokens[$methodPtr]['code'] !== T_STRING) {
$methodPtr = $phpcsFile->findNext(Tokens::$emptyTokens, $methodPtr, null, true);

if (!$methodPtr) {
return;
}
}

if ($tokens[$methodPtr]['code'] !== T_STRING
|| !isset(self::ESCAPER_METHODS[$tokens[$methodPtr]['content']])
) {
return;
}

$openParenPtr = $methodPtr + 1;
if ($tokens[$openParenPtr]['code'] !== T_OPEN_PARENTHESIS) {
$openParenPtr = $phpcsFile->findNext(Tokens::$emptyTokens, $openParenPtr, null, true);

if (!$openParenPtr) {
return;
}
}

if ($tokens[$openParenPtr]['code'] !== T_OPEN_PARENTHESIS) {
return;
}

$fix = $phpcsFile->addFixableWarning(
'Using %s on $block is deprecated. Please use equivalent method on $escaper',
$methodPtr,
'Found',
[
$tokens[$methodPtr]['content'], // method name
]
);

if ($fix) {
$phpcsFile->fixer->replaceToken($objectPtr, '$escaper');
}
}
}
4 changes: 2 additions & 2 deletions Magento2/Sniffs/Security/XssTemplateSniff.php
Original file line number Diff line number Diff line change
@@ -147,11 +147,11 @@ public function process(File $phpcsFile, $stackPtr)
private function findSpecialAnnotation($stackPtr)
{
if ($this->tokens[$stackPtr]['code'] === T_ECHO) {
$startOfStatement = $this->file->findPrevious(T_OPEN_TAG, $stackPtr);
$startOfStatement = $this->file->findPrevious([T_OPEN_TAG, T_SEMICOLON], $stackPtr);
return $this->file->findPrevious(T_COMMENT, $stackPtr, $startOfStatement);
}
if ($this->tokens[$stackPtr]['code'] === T_OPEN_TAG_WITH_ECHO) {
$endOfStatement = $this->file->findNext(T_CLOSE_TAG, $stackPtr);
$endOfStatement = $this->file->findNext([T_CLOSE_TAG, T_SEMICOLON], $stackPtr);
return $this->file->findNext(T_COMMENT, $stackPtr, $endOfStatement);
}
return false;
62 changes: 61 additions & 1 deletion Magento2/Tests/Annotation/MethodAnnotationStructureUnitTest.inc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php

function functionWithNoPrecedingDocBlock() {}
/**
* Class for method structure for annotations test cases
*/
@@ -389,4 +389,64 @@ class MethodAnnotationFixture
{
return false;
}

/** @var OutputInterface */
private $output;

private function thisMethodHasNoDocBlock(): bool
{
return false;
}
}

/**
* Class with comment
*/
class ClassWithDocBlock
{
private function methodWithNoDocBlock(): bool
{
return false;
}

#[
/**
* This docBloc is not for the method but for the attribute
*/
\ReturnTypeWillChange
]
public function methodWithDocBlockInsideAttributesDelimiters(string $text): string
{
return $text;
}

#[\ReturnTypeWillChange]
public function methodWithAttributeAndNoDocBlock(string $text): string
{
return $text;
}

/**
* Short description.
*
* @param string $text
* @return string
*/
#[\ReturnTypeWillChange]
public function methodWithAttributeAndValidDocBlock(string $text): string
{
return $text;
}

#[\ReturnTypeWillChange]
/**
* Short description.
*
* @param string $text
* @return string
*/
public function methodWithAttributeAndValidDocBlock2(string $text): string
{
return $text;
}
}
Original file line number Diff line number Diff line change
@@ -15,6 +15,7 @@ class MethodAnnotationStructureUnitTest extends AbstractSniffUnitTest
public function getErrorList()
{
return [
2 => 1,
10 => 1,
18 => 1,
30 => 1,
@@ -31,13 +32,18 @@ public function getErrorList()
185 => 1,
227 => 1,
235 => 1,
261 => 1,
268 => 2,
269 => 1,
277 => 1,
278 => 1,
288 => 1,
289 => 1,
298 => 1
298 => 1,
396 => 1,
407 => 1,
418 => 1,
424 => 1,
];
}

Original file line number Diff line number Diff line change
@@ -179,3 +179,10 @@ class AlsoDeprecatedButHandler

}

/**
* @package this tag should not be used
*/
class OnlyUselessCommentContent
{

}
Loading