Magento Coding Standard

Overview

Magento Coding Standard

A set of Magento rules for PHP_CodeSniffer tool.

Installation within a Magento 2 site

To use within your Magento 2 project you can use:

composer require --dev magento/magento-coding-standard

Due to security, when installed this way the Magento standard for phpcs cannot be added automatically. You can achieve this by adding the following to your project's composer.json:

"scripts": {
    "post-install-cmd": [
      "([ $COMPOSER_DEV_MODE -eq 0 ] || vendor/bin/phpcs --config-set installed_paths ../../magento/magento-coding-standard/)"
    ],
    "post-update-cmd": [
      "([ $COMPOSER_DEV_MODE -eq 0 ] || vendor/bin/phpcs --config-set installed_paths ../../magento/magento-coding-standard/)"
    ]
}

Installation for development

You can install Magento Coding Standard by cloning this GitHub repo:

git clone [email protected]:magento/magento-coding-standard.git
cd magento-coding-standard
composer install

It is possible also to install a standalone application via Composer

composer create-project magento/magento-coding-standard --stability=dev magento-coding-standard

Verify installation

Command should return the list of installed coding standards including Magento2.

vendor/bin/phpcs -i

Usage

Once installed, you can run phpcs from the command-line to analyze your code MyAwesomeExtension

vendor/bin/phpcs --standard=Magento2 app/code/MyAwesomeExtension

Fixing issues automatically

Also, you can run phpcbf from the command-line to fix your code MyAwesomeExtension for warnings like "PHPCBF CAN FIX THE [0-9]+ MARKED SNIFF VIOLATIONS AUTOMATICALLY"

vendor/bin/phpcbf --standard=Magento2 app/code/MyAwesomeExtension

Contribution

See the community contribution model.

Where to contribute

  • Documentation of existing rules. See ExtDN PHP CodeSniffer rules for Magento 2 as a good example.
  • Bug fixes and improvements of existing rules.
  • Creation of new PHP CodeSniffer rules.
  • Discussions on new rules (through periodic hangouts or discussions per GitHub issue).

How to contribute

  1. Start with looking into Community Dashboard. Any ticket in Up for grabs is a good candidate to start.
  2. Didn't satisfy your requirements? Create one of three types of issues:
    • Bug report - Found a bug in the code? Let us know!
    • Existing rule enhancement - Know how to improve existing rules? Open an issue describe how to enhance Magento Coding Standard.
    • New rule proposal - Know how to improve Magento ecosystem code quality? Do not hesitate to open a proposal.
  3. The issue will appear in the Backlog column of the Community Dashboard. Once it will be discussed and get accepted label the issue will appear in the Up for grabs column.

Testing

All rules should be covered by unit tests. Each Test.php class should be accompanied by a Test.inc file to allow for unit testing based upon the PHP_CodeSniffer parent class AbstractSniffUnitTest. You can verify your code by running

vendor/bin/phpunit

Also, verify that the sniffer code itself is written according to the Magento Coding Standard:

vendor/bin/phpcs --standard=Magento2 Magento2/ --extensions=php

ESLint

Prerequisites: Node.js (^12.22.0, ^14.17.0, or >=16.0.0).

You need to run the following command to install all the necessary packages described in the package.json file:

npm install

You can execute ESLint as follows:

npm run eslint -- path/to/analyze

RECTOR PHP

From magento-condign-standard project, you can execute rector php as follows:

vendor/bin/rector process Magento2 Magento2Framework PHP_CodeSniffer --dry-run --autoload-file vendor/squizlabs/php_codesniffer/autoload.php

The rules from rector that are applied are set inside the config file: rector.php

The option --dry-run displays errors found, but code is not automatically fixed.

To run rector for magento projects you need to:

  • Specify the magento path and the autoload file for the magento project:
vendor/bin/rector process MAGENTO_PATH --dry-run --autoload-file MAGENTO_AUTOLOAD_FILE

Example:

vendor/bin/rector process magento2ce/app/code/Magento/Cms/Model --dry-run --autoload-file magento2ce/vendor/autoload.php

License

Each Magento source file included in this distribution is licensed under the OSL-3.0 license.

Please see LICENSE.txt for the full text of the Open Software License v. 3.0 (OSL-3.0).

Comments
  • "Copyright is missing or has wrong format" warning on custom modules

    Preconditions

    Hi folks, I recently tried upgrading the coding standards library in my custom module from version 6 to version 10 and it suddenly starts complaining about missing copyright headers in files in my module?

    This is something I should decide, not something you should decide right?

    This coding standards library is still meant for 3rd party modules as well, right? Not only for checking core Magento files?

    Steps to reproduce

    1. Have a custom module
    2. Have a file etc/di.xml in that module that contains no copyright header

    Expected result

    1. No warnings

    Actual result

    1. Getting a warning:
    FILE: /path/to/custom/module/etc/di.xml
    ----------------------------------------------------------------------------------------------------
    FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
    ----------------------------------------------------------------------------------------------------
      | WARNING | Copyright is missing or has wrong format
    ----------------------------------------------------------------------------------------------------
    
    bug Progress: done 
    opened by hostep 21
  • Exception thrown in single catch block passes

    Exception thrown in single catch block passes

    Preconditions

    • Magento.Exceptions.ThrowCatch rule implemented (magento/magento-coding-standard#43; tested on Magento Coding Standard 2.0.0 and 1.0.1)

    Steps to reproduce

    • Run phpcs with --standard=Magento2 against file containing multiple catch blocks (it fails as it should):
    <?php
    /**
     * Copyright © Magento, Inc. All rights reserved.
     * See COPYING.txt for license details.
     */
    
    namespace Magento;
    
    /**
     * Doer
     */
    class Doer
    {
        /**
         * Do Something
         */
        public function doSomething()
        {
            try {
                $result = 2;
            } catch (\DummyException $e) {
                throw $e;
            } catch (\NewException $e) {
                throw $e;
            }
    
            return $result;
        }
    }
    

    Run phpcs with --standard=Magento2 against file containing one catch block (it passes when it should not):

    <?php
    /**
     * Copyright © Magento, Inc. All rights reserved.
     * See COPYING.txt for license details.
     */
    
    namespace Magento;
    
    /**
     * Doer
     */
    class Doer
    {
        /**
         * Do Something
         */
        public function doSomething()
        {
            try {
                $result = 2;
            } catch (\DummyException $e) {
                throw $e;
            }
    
            return $result;
        }
    }
    

    Expected result

    • Both files should fail Magento.Exceptions.ThrowCatch rule

    Actual result

    • Only file with two catch blocks fails Magento.Exceptions.ThrowCatch rule
    bug need to discuss false negative 
    opened by danmooney2 21
  • AC-1895: Avoid having duplicated issues in magento-coding-standard

    AC-1895: Avoid having duplicated issues in magento-coding-standard

    There are a couple of sniffs duplicated between PHPCS and PHP Compatibility. I've picked the ones with better coverage after doing some tests.

    | Excluded | Kept | Description | | --- | --- | --- | | Generic.PHP.DeprecatedFunctions | PHPCompatibility.FunctionUse.RemovedFunctions | Excluded one only catches deprecations and, due to it using get_defined_functions() to get deprecated methods, it doesn't include functions coming from extensions or deprecations from different PHP versions than the one which is running the sniff. | | PHPCompatibility.Syntax.ForbiddenCallTimePassByReference | Generic.Functions.CallTimePassByReference | Both are equivalent, there is no special advantage of one over the other; in fact, call-time pass-by-reference is forbidden since PHP 5.4 so we can remove both checks. |

    Progress: done 
    opened by svera 15
  • PHP Syntax errors in xml files

    PHP Syntax errors in xml files

    Preconditions

    1. magento/magento-coding-standard v9
    2. A magento module that has an xml file that starts with <?xml version="1.0" ?>

    Steps to reproduce

    1. run bin/phpcs ./ --standard=Magento2 --severity=10

    Expected result

    1. Nothing module passes the test

    Actual result

    FILE: /opt/atlassian/pipelines/agent/build/etc/module.xml
    ----------------------------------------------------------------------
    FOUND 1 ERROR AFFECTING 1 LINE
    ----------------------------------------------------------------------
     1 | ERROR | PHP syntax error: syntax error, unexpected 'version'
       |       | (T_STRING)
    ----------------------------------------------------------------------
    
    FILE: /opt/atlassian/pipelines/agent/build/etc/di.xml
    ----------------------------------------------------------------------
    FOUND 1 ERROR AFFECTING 1 LINE
    ----------------------------------------------------------------------
     1 | ERROR | PHP syntax error: syntax error, unexpected 'version'
       |       | (T_STRING)
    ----------------------------------------------------------------------
    

    This bug got introduced in v9 because our pipelines were running v8 yesterday and didn't have this issue at the time.

    bug Progress: done 
    opened by Hexmage 15
  • [New Rule] Slow array SHOULD NOT be used in loop

    [New Rule] Slow array SHOULD NOT be used in loop

    Rule

    The use of slow array functions (array_merge) in loop is discouraged.

    Reason

    Merging arrays in a loop is slow and causes high CPU usage. Some benchmarking.

    Bad example:

        $options = [];
        foreach ($configurationSources as $source) {
            // code here
            $options = array_merge($options, $source->getOptions());
        }
    

    Good example:

        $options = [];
        foreach ($configurationSources as $source) {
            // code here
            $options[] = $source->getOptions();
        }
    
        // PHP 5.6+
        $options = array_merge([], ...$options);
    

    Implementation

    • Subscribe to T_STRING token and check if it's content is array_merge.
    • Try to find outer loop.
    • If loop is found rase a warning (need to discuss additional logic).
    <severity>7</severity>
    <type>warning</type>
    
    proposal accepted new rule 
    opened by lenaorobei 12
  • [New rule] Do not use in_array

    [New rule] Do not use in_array

    Rule

    in_array creating performance issue in many places when it used a lot of times.

    Reason

    Performance diff: https://stackoverflow.com/questions/13483219/what-is-faster-in-array-or-isset

    It causes performance issues:

    • https://github.com/magento/magento2/pull/24677
    • https://github.com/magento/magento2/issues/20966
    • https://github.com/magento/magento2/pull/4088

    Implementation

    proposal 
    opened by ihor-sviziev 11
  • [New Rule] Function/method call in for loop declaration MUST be avoided

    [New Rule] Function/method call in for loop declaration MUST be avoided

    Rule

    Function/method call in for loop declaration MUST be avoided.

    Reason

    PHP will call the method/function on each iteration of the for loop.

    Bad Example:

    for ($i = 0; $i < count($array); $i++){
        //code goes here
    }
    

    Good example:

    $count = count($array);
    for ($i = 0; $i < $count; $i++){
        //code goes here
    }
    

    Implementation

    • Subscribe to the T_FOR token.
    • Check if condition contains function call (T_STRING with followed by open parentheses).
    proposal need to discuss new rule waiting for feedback 
    opened by lenaorobei 10
  • Require `const` visibility

    Require `const` visibility

    Rule

    Currently const are declared without visibility: https://github.com/magento/magento2/blob/78bb169ff9721c8d05c35b4c29a4464fd45bccbe/app/code/Magento/Catalog/Model/Product.php#L54-L73

    I suggest extending Coding Standard to require visibility - for example:

    public const PRIMARY_KEY = 'entity_id';
    private const DEFAULT_TIMEOUT = 60;
    

    Reason

    const should be explicit if we can use them as a reference or it's declaration is only internal.

    Implementation

    N/A

    proposal partners-contribution Partner: Mediotype Progress: done 
    opened by lbajsarowicz 9
  • Add magento/magento-coding-standard as a dependency to magento/magento2

    Add magento/magento-coding-standard as a dependency to magento/magento2

    Description

    This unified coding standard will contain all Magento related sniffs, so there is no need to keep core sniffs under Magento 2 dev/tests/static folded.

    Acceptance Criteria

    1. Sniffs are removed from Magento 2 dev/tests/static/framework/Magento folder.
    2. magento/magento-coding-standard depencency is added to the require-dev section of Magento 2 composer.json file.
    3. No duplicate findings detected by other static tools (eg: Magento\TestFramework\Utility\XssOutputValidatorTest covers the same as XssTemplateSniff, FinalImplementation Mess Detector rule and FinalImplementation sniff).
    4. Static build is green.

    Additional information

    Needs to be done after the first Magento Coding Standard release.

    opened by lenaorobei 9
  • Fixed undefined variable error in AutogeneratedClassNotInConstructorSniff

    Fixed undefined variable error in AutogeneratedClassNotInConstructorSniff

    Fixes: https://github.com/magento/magento-coding-standard/issues/314

    Refactored the sniff for better readability, simplified and fixed the implementation. Added additional filtering by autogenerated class suffixes (Proxy and Interceptors are not covered as they are handled by DiscouragedDependenciesSniff)

    Test results on magento2 codebase:

    
    $ vendor/bin/phpcs --standard=Magento2 --sniffs=Magento2.PHP.AutogeneratedClassNotInConstructor magento2/app/code
    
    FILE: magento2/app/code/Magento/Ui/Controller/Adminhtml/Index/Render.php
    ------------------------------------------------------------------------------------------------------------------------------------------------------
    FOUND 1 ERROR AFFECTING 1 LINE
    ------------------------------------------------------------------------------------------------------------------------------------------------------
    67 | ERROR | Class \Magento\Framework\Controller\Result\JsonFactory needs to be requested in constructor, otherwise compiler will not be able to
    |       | find and generate this classes
    ------------------------------------------------------------------------------------------------------------------------------------------------------
    
    
    FILE: magento2/app/code/Magento/CatalogSearch/Model/ResourceModel/Advanced/Collection.php
    ------------------------------------------------------------------------------------------------------------------------------------------------------
    FOUND 1 ERROR AFFECTING 1 LINE
    ------------------------------------------------------------------------------------------------------------------------------------------------------
    194 | ERROR | Class \Magento\Framework\Api\Search\SearchResultFactory needs to be requested in constructor, otherwise compiler will not be able to
    |       | find and generate this classes
    ------------------------------------------------------------------------------------------------------------------------------------------------------
    
    
    FILE: magento2/app/code/Magento/CatalogSearch/Model/ResourceModel/Fulltext/Collection.php
    ------------------------------------------------------------------------------------------------------------------------------------------------------
    FOUND 1 ERROR AFFECTING 1 LINE
    ------------------------------------------------------------------------------------------------------------------------------------------------------
    181 | ERROR | Class \Magento\Framework\Api\Search\SearchResultFactory needs to be requested in constructor, otherwise compiler will not be able to
    |       | find and generate this classes
    ------------------------------------------------------------------------------------------------------------------------------------------------------
    
    
    FILE: magento2/app/code/Magento/Catalog/Controller/Adminhtml/Product/Builder.php
    ------------------------------------------------------------------------------------------------------------------------------------------------------
    FOUND 1 ERROR AFFECTING 1 LINE
    ------------------------------------------------------------------------------------------------------------------------------------------------------
    81 | ERROR | Class \Magento\Store\Model\StoreFactory needs to be requested in constructor, otherwise compiler will not be able to find and generate
    |       | this classes
    ------------------------------------------------------------------------------------------------------------------------------------------------------
    
    
    FILE: magento2/app/code/Magento/Rule/Model/AbstractModel.php
    ------------------------------------------------------------------------------------------------------------------------------------------------------
    FOUND 2 ERRORS AFFECTING 2 LINES
    ------------------------------------------------------------------------------------------------------------------------------------------------------
    495 | ERROR | Class \Magento\Framework\Api\ExtensionAttributesFactory needs to be requested in constructor, otherwise compiler will not be able to
    |       | find and generate this classes
    507 | ERROR | Class \Magento\Framework\Api\AttributeValueFactory needs to be requested in constructor, otherwise compiler will not be able to find
    |       | and generate this classes
    ------------------------------------------------------------------------------------------------------------------------------------------------------
    
    
    FILE: magento2/app/code/Magento/ConfigurableProduct/Model/LinkManagement.php
    ------------------------------------------------------------------------------------------------------------------------------------------------------
    FOUND 1 ERROR AFFECTING 1 LINE
    ------------------------------------------------------------------------------------------------------------------------------------------------------
    208 | ERROR | Class \Magento\ConfigurableProduct\Helper\Product\Options\Factory needs to be requested in constructor, otherwise compiler will not be
    |       | able to find and generate this classes
    ------------------------------------------------------------------------------------------------------------------------------------------------------
    
    
    FILE: magento2/app/code/Magento/Customer/Controller/Account/Logout.php
    ------------------------------------------------------------------------------------------------------------------------------------------------------
    FOUND 1 ERROR AFFECTING 1 LINE
    ------------------------------------------------------------------------------------------------------------------------------------------------------
    75 | ERROR | Class CookieMetadataFactory needs to be requested in constructor, otherwise compiler will not be able to find and generate this classes
    ------------------------------------------------------------------------------------------------------------------------------------------------------
    
    Time: 1 mins, 59.01 secs; Memory: 64MB
    
    
    Progress: done 
    opened by sivaschenko 8
  • Discourage local-FS-only methods

    Discourage local-FS-only methods

    This PR addsgetimagesize() to discouraged functions as it does not work with remote storage implementations.

    Task: https://jira.corp.magento.com/browse/MC-38508

    Progress: done 
    opened by shiftedreality 8
  • RestrictedCodeSniff suggests Laminas\Filter\FilterInterface, which is not required by Magento 2.4.5-p1 anymore

    RestrictedCodeSniff suggests Laminas\Filter\FilterInterface, which is not required by Magento 2.4.5-p1 anymore

    Preconditions

    1. Magento 2.4.5-p1
    2. Magento Coding Standard, 26

    Steps to reproduce

    1. Create a file, where you include \Zend_Filter_Interface in the constructor
    2. Run vendor/bin/phpcs --standard=dev/tests/static/framework/Magento on that file.

    Expected result

    1. RestrictedCodeSniff should suggest a class, which exists in a clean Magento instance

    Actual result

    1. The following error comes up: ERROR | Class 'Zend_Filter_Interface' is restricted in XXX. Suggested replacement: Laminas\Filter\FilterInterface
    bug Progress: ready for grooming 
    opened by norgeindian 1
  • Exception class Magento\Framework\Validator\ValidateException does not exist

    Exception class Magento\Framework\Validator\ValidateException does not exist

    Preconditions

    Add attribute in Data Patch using $eavSetup->addAttribute() method. Place DataPatch in Vendor/Module/Setup/Patch/Data/AddTestAttribute.php file.

    Example

    $eavSetup = $this->eavSetupFactory->create(['setup' => $this->moduleDataSetup]);
    $eavSetup->addAttribute(Product::ENTITY, $attributeCode, $attribute);
    

    Steps to reproduce

    run vendor/bin/phpcs --standard=Magento2 app/code/Vendor/Module/Setup/Patch/Data/AddTestAttribute.php

    Expected result

    class 'Zend_Validate_Exception' is restricted in app/code/Vendor/Module/Setup/Patch/Data/AddTestAttribute.php. 
    Suggested replacement: Magento\Framework\Validator\Exception
    

    Actual result

    class 'Zend_Validate_Exception' is restricted in app/code/Vendor/Module/Setup/Patch/Data/AddTestAttribute.php. 
    Suggested replacement: Magento\Framework\Validator\ValidateException
    

    Line

    https://github.com/magento/magento-coding-standard/blob/097bda3e015f35dc7c2efc0b8c7a7d8dfc158a63/Magento2/Sniffs/Legacy/_files/restricted_classes.php#L129

    Solution

    The Magento\Framework\Validator\ValidateException should be replaced with Magento\Framework\Validator\Exception

    Progress: ready for grooming 
    opened by okolya 2
  • strpos(): Argument #3 ($offset) must be contained in argument #1 ($haystack) in Magento2/Sniffs/Less/ClassNamingSniff.php:69

    strpos(): Argument #3 ($offset) must be contained in argument #1 ($haystack) in Magento2/Sniffs/Less/ClassNamingSniff.php:69

    Preconditions

    Example of less file

    .legal-store-information{
      color: #aaa!important;
      padding: 13px;
      text-align: center;
      font-family: Arial, sans-serif;
      font-size: 0.8em;
      display: block;
    
      .a{
        color: #aaa!important;
    
        &:hover {
          color: #fff!important;
        }
        &:visited {
          color: #aaa!important;
        }
      }
    }
    

    Steps to reproduce

    1. run vendor/bin/phpcs -d memory_limit=2G --standard=Magento2 --report-\\Micheh\\PhpCodeSniffer\\Report\\Gitlab=report-phpcs.json --basepath=/var/www/html app/design/frontend/Phoenix/

    Expected result

    Normal report

    Actual result

    Fatal Error.

    PHP Fatal error:  Uncaught ValueError: strpos(): Argument #3 ($offset) must be contained in argument #1 ($haystack) in /var/www/html/vendor/magento/magento-coding-standard/Magento2/Sniffs/Less/ClassNamingSniff.php:69
    Stack trace:
    #0 /var/www/html/vendor/magento/magento-coding-standard/Magento2/Sniffs/Less/ClassNamingSniff.php(69): strpos()
    #1 /var/www/html/vendor/squizlabs/php_codesniffer/src/Files/File.php(498): Magento2\Sniffs\Less\ClassNamingSniff->process()
    #2 /var/www/html/vendor/squizlabs/php_codesniffer/src/Files/LocalFile.php(92): PHP_CodeSniffer\Files\File->process()
    #3 /var/www/html/vendor/squizlabs/php_codesniffer/src/Runner.php(628): PHP_CodeSniffer\Files\LocalFile->process()
    #4 /var/www/html/vendor/squizlabs/php_codesniffer/src/Runner.php(434): PHP_CodeSniffer\Runner->processFile()
    #5 /var/www/html/vendor/squizlabs/php_codesniffer/src/Runner.php(114): PHP_CodeSniffer\Runner->run()
    #6 /var/www/html/vendor/squizlabs/php_codesniffer/bin/phpcs(18): PHP_CodeSniffer\Runner->runPHPCS()
    #7 {main}
      thrown in /var/www/html/vendor/magento/magento-coding-standard/Magento2/Sniffs/Less/ClassNamingSniff.php on line 69
    

    As you can see from less file, a class name is shorter than the expected offset 2. A possible solution is to check the string length before checking the underscore in the className, or check if the found position is bigger than 2

    bug Progress: PR created 
    opened by lykhouzov 1
  • Forbid Framework\Module\Status::setIsEnabled

    Forbid Framework\Module\Status::setIsEnabled

    Rule

    Forbid calling Magento\Framework\Module\Status::setIsEnabled

    Reason

    Experienced downtime as a result of a magento marketplace module (feefo/reviews) calling setIsEnabled(true) in production mode. The target was Magento_Review, which was installed but not enabled, causing blocks to attempt to load data from database tables which did not exist (declarative schema had removed them). Usage of this function outwith console command handlers should result in an automated knockback from the Magento marketplace due to potential to cause downtime like this.

    Implementation

    ForbiddenFunctionsSniff

    proposal Progress: ready for grooming 
    opened by maaarghk 1
  • Too strict or early rule for Zend_Validate

    Too strict or early rule for Zend_Validate

    Steps to reproduce

    1. Use Zend_Validate in your extension
    2. Validate extension with the last (26) version of Magento Coding Standard

    Expected result

    1. Extension is not valid and there is a correct suggestion or it is not ERROR level but WARNING
    2. Suggested replacement is present in 2.4.0 Magento versions as it is supported to November 28, 2022

    Actual result

    1. Extension not valid
    2. Suggested replacement (\Magento\Framework\Validator\ValidatorChain) is missing in 2.4.0-2.4.5

    Pull request #420 bring these new changes.

    bug Progress: ready for grooming 
    opened by 06romix 6
Releases(v29)
  • v29(Dec 21, 2022)

  • v28(Dec 15, 2022)

  • v27(Oct 17, 2022)

  • v26(Oct 5, 2022)

    What's Changed

    • Fix Rector tests by @bl4de in https://github.com/magento/magento-coding-standard/pull/410
    • Allow to skip see tag in annotation with specific deprecated comment by @loginesta in https://github.com/magento/magento-coding-standard/pull/419
    • Add eliminated classes to Magento coding standards in Legacy\RestrictedCodeSniff by @karyna-tsymbal-atwix in https://github.com/magento/magento-coding-standard/pull/420

    Full Changelog: https://github.com/magento/magento-coding-standard/compare/v25...v26

    Source code(tar.gz)
    Source code(zip)
  • v25(Jun 21, 2022)

    Bugfixes

    • Avoid processing less and CSS pseudo-classes by @svera
    • Allow empty constructor function blocks when using property promotion by @mfickers
    Source code(tar.gz)
    Source code(zip)
  • v24(Jun 14, 2022)

    Bug fixes:

    Fixed error when calling hasDeprecatedWellFormatted with a false $commentStartPtr in https://github.com/magento/magento-coding-standard/pull/400 by @mattijv

    Source code(tar.gz)
    Source code(zip)
  • v23(Jun 1, 2022)

    Improvements

    • Added match keyword to a Reserved words sniff by @karyna-tsymbal-atwix
    • Require content for @see and @deprecated tags in #393 by @loginesta
    • Corrected messages for discouraged functions by @sivaschenko
    Source code(tar.gz)
    Source code(zip)
  • v22(Apr 26, 2022)

    What's Changed

    • AC-2724: Update rector dependency to the latest version by @eliseacornejo in https://github.com/magento/magento-coding-standard/pull/384
    • Fix warnings detected by phpcs & phpunit by @fredden in https://github.com/magento/magento-coding-standard/pull/383
    • AC-1879: Magento2/Sniffs/Legacy/ObsoleteResponseSniff.php issue by @bl4de in https://github.com/magento/magento-coding-standard/pull/386

    Full Changelog: https://github.com/magento/magento-coding-standard/compare/v21...v22

    Source code(tar.gz)
    Source code(zip)
  • v21(Apr 5, 2022)

    What's Changed

    • AC-1655: Fixed obsolete attributes not detected by @svera in https://github.com/magento/magento-coding-standard/pull/380

    Full Changelog: https://github.com/magento/magento-coding-standard/compare/v20...v21

    Source code(tar.gz)
    Source code(zip)
  • v20(Mar 30, 2022)

    What's Changed

    • AC-2394 Update eslint npm dependency by @loginesta in https://github.com/magento/magento-coding-standard/pull/379

    Full Changelog: https://github.com/magento/magento-coding-standard/compare/v19...v20

    Source code(tar.gz)
    Source code(zip)
  • v19(Mar 8, 2022)

    What's changed

    • AC-2219: Implemented autofixing for Magento2.Functions.FunctionsDeprecatedWithoutArgument.FunctionsDeprecatedWithoutArgument check

    Full Changelog: https://github.com/magento/magento-coding-standard/compare/v18...v19

    Source code(tar.gz)
    Source code(zip)
  • v18(Feb 15, 2022)

    What's Changed

    • AC-1895: Avoid having duplicated issues in magento-coding-standard by @svera in https://github.com/magento/magento-coding-standard/pull/362
    • AC-1895: Exclude sniff that is duplicated by @eliseacornejo in https://github.com/magento/magento-coding-standard/pull/365
    • PHP 8.1 Compatibility by @sivaschenko in https://github.com/magento/magento-coding-standard/pull/366
    • AC-2224: Remove incorrect and outdated rules by @loginesta in https://github.com/magento/magento-coding-standard/pull/368
    • Use development php configuration for tests by @sivaschenko in https://github.com/magento/magento-coding-standard/pull/367
    • Autofix for ThisInTemplate sniff by @sivaschenko in https://github.com/magento/magento-coding-standard/pull/369
    • Removed obsolete layout check by @sivaschenko in https://github.com/magento/magento-coding-standard/pull/370
    • AC-2222: [UCT Autofixing] PHPCompatibility.ForbiddenFinalPrivateMethods by @svera in https://github.com/magento/magento-coding-standard/pull/373
    • Improve: Exclude minified JS files. by @edspc in https://github.com/magento/magento-coding-standard/pull/372

    Full Changelog: https://github.com/magento/magento-coding-standard/compare/v17...v18

    Source code(tar.gz)
    Source code(zip)
  • v17(Jan 11, 2022)

    New rules

    • AC-1060: Move relevant sniffs from phpcompatibility by @svera
    • AC-391: Static test to cover "deprecated" jQuery methods by @Rrego6
    • Fixed graphql unit test failing as it was extending from a wrong class by @svera
    • AC-1717: Passing null to non-nullable internal function parameters is deprecated by @svera
    • AC-1718 return types for arrayaccess methods by @svera

    Improvements

    • AC-99: Update Third Party library: jquery.tabs by @krissyhiserote
    • Allow use of modern syntax in JavaScript files by @fredden
    • Run tests on php 8.1 by @ihor-sviziev
    • Simplify file structure for ESLint ruleset by @fredden
    • Disallow Yoda Conditions in JavaScript files by @fredden

    Fixes

    • Fix DirectThrowSniff false positive by @rmsundar1
    Source code(tar.gz)
    Source code(zip)
  • v16(Nov 23, 2021)

    New Rules

    • Created Sniff to validate function which usage without arguments is deprecated in PHP 8.1 https://github.com/magento/magento-coding-standard/pull/325 by @anzin
    • Added deprecated function PHP 8.1 to DiscouragedFunctionSniff https://github.com/magento/magento-coding-standard/pull/326 by @anzin
    • Added PSR12.Properties.ConstantVisibility rule to the ruleset https://github.com/magento/magento-coding-standard/pull/330 by @rmsundar1
    • AC-1059: Included PHPCompatibility rules https://github.com/magento/magento-coding-standard/pull/332 by @svera

    Improvements

    • Updated rule names for better, more granular messaging https://github.com/magento/magento-coding-standard/pull/328 by @fredden
    • AC-1740: Added RectorPHP and included it as part of the GitHub actions https://github.com/magento/magento-coding-standard/pull/333 by @eliseacornejo

    Fixes

    • Fixed code ArrayAutovivificationSniff for specific code constructions https://github.com/magento/magento-coding-standard/pull/329 by @anzin
    • Fix GraphQL sniffs unit tests https://github.com/magento/magento-coding-standard/pull/334 by @eliseacornejo
    • Fixed AutogeneratedClassNotInConstructorSniff for specific code constructions https://github.com/magento/magento-coding-standard/pull/336 by @sivaschenko
    • Added support of PHP Attributes to the method annotation sniff https://github.com/magento/magento-coding-standard/pull/335 by @karyna-tsymbal-atwix
    Source code(tar.gz)
    Source code(zip)
  • v15(Nov 9, 2021)

    New Rules

    • Added Sniff to check auto vivification on an array (PHP 8.1 compatibility) in #322 by @anzin

    Improvements

    • Excluded JS files for PSR sniffs in #324 by @sivaschenko
    • AC-1509: Removed deprecated JSCS package in #327 by @loginesta
    Source code(tar.gz)
    Source code(zip)
  • v14(Nov 2, 2021)

    New Rules

    • AC-681: Create phpcs static check for PhtmlTemplateTest in #306 by @eliseacornejo
    • AC-683: Create phpcs static check for TableTest in #309 by @svera
    • AC-676: Create phpcs static check for ObsoleteConnectionTest in #310 by @eliseacornejo
    • AC-670: phpcs layouttest in #298 by @svera
    • AC-678: Create phpcs sniff for ObsoleteResponseTest in #311 by @eliseacornejo
    • AC-663: PHPCS classes test in #274 by @svera
    • AC-672: Create phpcs static check for LicenseTest in #312 by @eliseacornejo
    • Added copyright verification for graphqls files in #321 by @sivaschenko

    Improvements

    • AC-1167: Add all filesystem PHP native functions covered by Filesystem\DriverInterface to DiscouragedFunctionSniff in #308 by @loginesta
    • AC-206: Create UCT phpcs ruleset for customizations only in #313 by @svera
    • AC-1549: Create codes for each type of returned error / warning in #316 by @svera

    Fixes

    • AC-1314: Fix copyright sniff for less files in #284 by @eliseacornejo
    • Fixed undefined index in Magento2.Commenting.ClassPropertyPHPDocFormatting in #317 by @sivaschenko
    • Extracted js tests to a separate build in #318 by @sivaschenko
    • Fixed undefined variable error in AutogeneratedClassNotInConstructorSniff in #319 by @sivaschenko
    Source code(tar.gz)
    Source code(zip)
  • v13(Oct 5, 2021)

    New rules

    • AC-679 Create phpcs static check for ObsoleteSystemConfigurationTest by @eliseacornejo
    • AC-682 Create phpcs static check for RestrictedCodeTest by @svera
    • AC-679 Create phpcs static check for ObsoleteSystemConfigurationTest by @eliseacornejo
    • AC-677 Create phpcs static test for ObsoleteMenuTest by @loginesta
    • AC-674 Create phpcs static check for ObsoleteAclTest by @loginesta
    • AC-667 Create phpcs static check for EmailTemplateTest by @jcuerdo

    Other

    • AC-1159 Remove eslint tests from magento2 repo and reuse new version of magento-coding-standard instead by @loginesta
    • AC-1355 Move JSCS into magento-coding-standards repo by @loginesta
    Source code(tar.gz)
    Source code(zip)
  • v12(Sep 28, 2021)

  • v11(Sep 28, 2021)

    New rules

    • AC-1102: Static test to verify self-closing tags for non-void html elements by @xmav
    • AC-662: Create phpcs static check for AutogeneratedClassNotInConstructorTest by @jcuerdo
    • AC-1156: Move custom eslint tests to magento-coding-standard repo by @loginesta
    • AC-665: Create phpcs static check for ConfigTest by @svera
    • AC-669: Create phpcs static check for InstallUpgradeTest by @svera

    Fixes

    • AC-1307: PHP Syntax errors in xml files by @eliseacornejo
    • AC-1335: Exclude the copyright sniff by @eliseacornejo
    Source code(tar.gz)
    Source code(zip)
  • v10(Sep 14, 2021)

    New Rules

    • Added sniff detecting obsolete email directives in #261 by @jcuerdo
    • Added sniff detecting obsolete widget configurations in #266 by @jcuerdo
    • Added sniff checking for correct copyright headers in #267 and #269 by @eliseacornejo

    Fixes

    • Fixed wrongly returning error for valid descriptions in #270 by @svera
    Source code(tar.gz)
    Source code(zip)
  • v9(Sep 7, 2021)

    New Rules

    • Added sniff to ensure proper sniff for class properties PHPDoc formatting in #140 by @konarshankar07
    • Test moved from magento2: sniff looking for occurrences of obsolete active and version attributes in the module.xml file in #230 by @svera
    • Test moved from magento2: sniff looking for occurrences of obsolete nodes: param, instance, array, item[@key] and value in di.xml in #233 by @loginesta

    Improvements

    • Added eval and proc* functions to the InsecureFunctionSniff class by @orsinijose
    • Updated html, less and annotation rules severity in #255 by @eliseacornejo
    • Improved less verification by catching newlines in the middle of a style definition in #258 by @svera
    • Ignore PHPUnit results cache file in #254 by @fredden

    Fixes

    • Fixed fatal error when docblock includes parametry type but is missing the parameter name in #256 by @fredden

    Test coverage

    • Created unit test for Magento2\Less\SemicolonSpacingSniff in #253 by @loginesta
    • Createe unit test for Magento2\Less\ColourDefinitionSniff check in #238 by @svera
    • Created unit test for Magento2\Less\QuotesSniff check in #248 by @svera
    • Created unit test for CombinatorIndentationSniff in #249 by @svera
    • Created unit test for Magento2\Less\TypeSelectorsSniff in #250 by @svera
    • Created unit test for Magento2\Less\ZeroUnitsSniff in #251 by @svera
    • Created unit test for Magento2\Less\PropertiesLineBreakSniff in #244 by @svera
    • Created unit test for Magento2\Less\TypeSelectorConcatenationSniff check in #247 by @loginesta
    • Created unit test for Magento2\Less\VariablesSniff in #252 by @loginesta
    • Created unit test for Magento2\Less\ColonSpacingSniff in #237 by @svera
    • Created unit test for Magento2\Less\BracesFormattingSniff in #236 by @svera
    Source code(tar.gz)
    Source code(zip)
  • v8(Aug 25, 2021)

    Fixes

    • Fixed ImportsFromTestNamespace from lock on group use with trailing comma @fsw
    • Moved abstract unit test to autoload-dev @sivaschenko
    • Unit test coverage and fixes for HTML, annotation and less sniffs @eliseacornejo
    Source code(tar.gz)
    Source code(zip)
  • 7(Aug 20, 2021)

    New Rules

    • Added sniff to ensure correct usage of getChildHtml and getChildChildHtml AbstractBlock methods @eliseacornejo
    • Annotation, Html and Less sniffs has been moved from the magento/magento2 repo @loginesta

    Fixes

    • Avoid infinite loop when Parse Error occurs @fredden
    • Fix TypeError for phpcs->addWarning() @fredden
    • Fixed HtmlDirectiveSniff @asheem-patro
    • Add test coverage for HtmlBindingSniff @ihor-sviziev
    • Moved parameter and variable tokenizers from the magento/magento2 repo @edspc

    Infrastructure and updates

    • Github Actions are now used to validate pull requests @ihor-sviziev
    • All dependencies have been updated to the latest versions. The package is now PHP 8 compatible. @andrewbess @drpayyne
    Source code(tar.gz)
    Source code(zip)
  • v6(Dec 3, 2020)

    New Rules

    • Added sniff to prohibit imports from Magento\Tests namespace outside of tests in #149 by @konarshankar07
    • Added sniff to discourage the use of Resource class from Model class (i.e. getResource()->load($object)) in #189 by @milindsingh

    Improvements

    • squizlabs/php_codesniffer dependency version updated from ^3.4 to ^3.5 for PHP 7.4 compatibility
    • Discouraged functions list was updated to include all the aliases of the existing discouraged functions in #179 by @andrewbess
    • Modified deprecated validator to allow missing the comment if see tag is set in #181 by @sinisa86

    Fixes

    • Fixed issue when PHP files which contain phtml in the name were detected as templates in #180 by @sinisa86
    Source code(tar.gz)
    Source code(zip)
  • v5(Nov 5, 2019)

    New Rules

    • Implemented GraphQL sniffs magento/architecture#269 in magento/magento-coding-standard#141 by @jean-bernard-valentaten
    • Implemented sniff for classes and interfaces PHPDoc formatting magento/magento-coding-standard#105 in magento/magento-coding-standard#124 by @udovicic
    • Implemented sniff that verifies that system resources processing is wrapped with try catch construction magento/magento-coding-standard#21 in magento/magento-coding-standard#77 by @larsroettig
    • Implemented sniff that checks that @deprecated tag is explained magento/magento-coding-standard#131 in magento/magento-coding-standard#134 by @udovicic

    Improvements

    • Added check for the use of helpers in Magento2.Templates.ThisInTemplate sniff and updated documentation with recommendation magento/magento-coding-standard#121 in magento/magento-coding-standard#122 @diazwatson
    • Added alternatives for discouraged functions magento/magento-coding-standard#102 in magento/magento-coding-standard#123 by @diazwatson
    • No longer require a space before a colon for control structures using the alternative syntax magento/magento-coding-standard#118 in magento/magento-coding-standard#132 by @hostep
    • Add excludes for test files <exclude-pattern>*/tests/*</exclude-pattern> magento/magento-coding-standard#136 in magento/magento-coding-standard#138 by @konarshankar07
    • Improved documentation with How to use phpcbf in magento/magento-coding-standard#150 by @lfluvisotto

    Fixes

    • Fixed issue with false-positive Empty FUNCTION statement detected for around plugins magento/magento-coding-standard#95 in magento/magento-coding-standard#126 by @konarshankar07
    • Fixed issue in line length sniff for phrase and __ keyword by removing redundant rule and using generic one magento/magento-coding-standard#75 in magento/magento-coding-standard#127 by @konarshankar07
    Source code(tar.gz)
    Source code(zip)
  • v4(Aug 6, 2019)

    New Rules

    • Rule for constants PHPDoc formatting magento/magento-coding-standard#107 in magento/magento-coding-standard#116 by @udovicic

    Improvements

    • Enhanced documentation for ThisInTemplate rule magento/magento-coding-standard#108 in magento/magento-coding-standard#119 by @diazwatson

    Fixes

    • Fixed ThrowCatch false positive findings magento/magento-coding-standard#93 in magento/magento-coding-standard#120 by @larsroettig
    Source code(tar.gz)
    Source code(zip)
  • v3(Jun 18, 2019)

    Versioning

    Starting from the current release new versioning strategy will be used. One release line will be supported based on incremental approach despite introduced changes and single number sequence-based version identifier will be incremented every release. Please refer to the wiki page and https://github.com/magento/architecture/pull/136 thread for more details.

    New Rules

    • Increased the severity level to 10 for InsecureFunctionSniff #104

    Improvements

    • Improved LiteralNamespacesSniff by removing class exists checks and adding exclude patterns #9 in #89 by @ldusan84
    • htmlspecialchars is added to the list of discouraged functions in #96 by @davemacaulay
    • Removed Squiz.Commenting.ClassComment from the ruleset since it does not cover all Magento cases #106
    • Added excludes for phtml files #112

    Fixes

    • Undefined index: comment_closer in AbstractApiSniff.php #86 in #87 by @mzeis
    • Fixed ForeachArrayMergeSniff throws an error for inline control structure #110 in #111
    Source code(tar.gz)
    Source code(zip)
  • 2.0.0(Apr 17, 2019)

    New Rules

    • Magento2.Classes.DiscouragedDependencies detects explicit request of proxies and interceptors in constructors. https://github.com/magento/magento-coding-standard/issues/18 -> https://github.com/magento/magento-coding-standard/pull/59 by @maderlock
    • Magento2.Performance.ForeachArrayMerge detects array_merge(...) usage in a loop. https://github.com/magento/magento-coding-standard/issues/20 -> https://github.com/magento/magento-coding-standard/pull/72 by @larsroettig

    Improvements

    • PHP CodeSniffer dependency ^3.4 https://github.com/magento/magento-coding-standard/issues/84 -> https://github.com/magento/magento-coding-standard/pull/85 by @sergeynezbritskiy

    Fixes

    • */Fixtures/* exclude for rules that do not apply to test files.

    Documentation

    Source code(tar.gz)
    Source code(zip)
  • 1.0.2(Apr 5, 2019)

    • added test files excludes for specific rules: Magento2.Security.IncludeFile, Magento2.Security.Supergloba, Magento2.SQL.RawQuery, Magento2.Exceptions.DirectThrow, Magento2.Functions.DiscouragedFunction, Magento2.Functions.StaticFunction, Magento2.CodeAnalysis.EmptyBlock, Squiz.Functions.GlobalFunction, Squiz.PHP.GlobalKeyword, PSR1.Files.SideEffects -> fixed https://github.com/magento/magento-coding-standard/issues/80.
    Source code(tar.gz)
    Source code(zip)
  • 1.0.1(Apr 1, 2019)

    • removed EmptyCheckSniff since there is no performance impact;
    • added more excludes for */Test/* files;
    • removed Squiz.Commenting.FunctionCommentThrowTag because it doesn't work with @inheritdoc tags.
    Source code(tar.gz)
    Source code(zip)
Owner
Magento
Magento
Magento 1.x Coding Standard

Magento Extension Quality Program Coding Standard ⚠️ Versions 3.0.0 and above of the MEQP Coding Standard are for Magento 1.x code only. To check Mage

Magento 224 Nov 29, 2022
Magento Coding Standard

Magento Coding Standard A set of Magento rules for PHP_CodeSniffer tool. Installation within a Magento 2 site To use within your Magento 2 project you

Magento 290 Dec 31, 2022
Documentation on clean coding and demonstration of studied clean coding principals with PHP.

practice-php-clean-code Documentation on clean coding and demonstration of studied clean coding principals with PHP. The document contained in this re

Ferdous Islam 1 Feb 21, 2022
Easy Coding Standard configurations for Craft CMS projects.

Easy Coding Standard config for Craft CMs This package provides Easy Coding Standard configurations for Craft CMS plugins and projects. In general, we

Craft CMS 10 Dec 18, 2022
A wrapper around symplify/config-transformer used to update recipes and using easy coding standard for generating readable config files.

Symfony Recipes Yaml to PHP Converter This is a wrapper around the symplify/config-transformer used to convert Symfony core recipes which uses .yaml c

Alexander Schranz 3 Nov 24, 2022
A tool that allows to quickly export data from Magento 1 and Magento 2 store and import it back into Magento 2

Simple Import / Export tool A tool that allows to quickly export data from Magento 1 and Magento 2 store and import it back into Magento 2. Table data

EcomDev B.V. 51 Dec 5, 2022
A tool to automatically fix Twig Coding Standards issues

Twig CS Fixer Installation This standard can be installed with the Composer dependency manager. Add the coding standard as a dependency of your projec

Vincent Langlet 50 Jan 6, 2023
This shell script and PHP file create a browseable HTML site from the Zig standard library source.

Browseable Zig standard library This shell script and PHP file create a browseable HTML site from the Zig standard library source. The idea is to inve

Dave Gauer 3 Mar 20, 2022
Composer installer for PHP_CodeSniffer coding standards

PHP_CodeSniffer Standards Composer Installer Plugin This composer installer plugin allows for easy installation of PHP_CodeSniffer coding standards (r

Dealerdirect 462 Dec 22, 2022
PHPCheckstyle is an open-source tool that helps PHP programmers adhere to certain coding conventions.

PHPCheckstyle Overview PHPCheckstyle is an open-source tool that helps PHP programmers adhere to certain coding conventions. The tools checks the inpu

PHPCheckstyle 157 Dec 5, 2022
Igbinary is a drop in replacement for the standard php serializer.

igbinary Igbinary is a drop in replacement for the standard php serializer. Instead of the time and space consuming textual representation used by PHP

Igbinary development 727 Dec 21, 2022
A Symfony2 bundle that integrates Select2 as a drop-in replacement for a standard entity field on a Symfony form.

select2entity-bundle Introduction This is a Symfony bundle which enables the popular Select2 component to be used as a drop-in replacement for a stand

Ross Keatinge 214 Nov 21, 2022
This package provides a set of factories to be used with containers using the PSR-11 standard for an easy Doctrine integration in a project

psr-container-doctrine: Doctrine Factories for PSR-11 Containers Doctrine factories for PSR-11 containers. This package provides a set of factories to

Roave, LLC 84 Dec 14, 2022
This composer installer plugin allows for easy installation of PHP_CodeSniffer coding standards

PHP_CodeSniffer Standards Composer Installer Plugin This composer installer plugin allows for easy installation of PHP_CodeSniffer coding standards (r

PHPCSStandards 393 Feb 25, 2022
PHP_CodeSniffer tokenizes PHP files and detects violations of a defined set of coding standards.

PHP_CodeSniffer is a set of two PHP scripts; the main phpcs script that tokenizes PHP, JavaScript and CSS files to detect violations of a defined coding standard, and a second phpcbf script to automatically correct coding standard violations. PHP_CodeSniffer is an essential development tool that ensures your code remains clean and consistent.

Squiz Labs 9.9k Jan 5, 2023
This tool can write the monolog standard log directly to clickhouse in real time via the tcp protocol

log2ck This tool can write the monolog standard log directly to clickhouse in real time via the tcp protocol. If you can write regular rules, other st

Hisune 9 Aug 15, 2022
Pattern Lab Standard Edition for Twig

Pattern Lab Standard Edition for Twig The Standard Edition for Twig gives developers and designers a clean and stable base from which to develop a Twi

Pattern Lab 102 Oct 24, 2022