- Notifications
You must be signed in to change notification settings - Fork162
Magento Coding Standard
License
OSL-3.0, Unknown licenses found
Licenses found
magento/magento-coding-standard
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
A set of Magento rules forPHP_CodeSniffer tool.
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'scomposer.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/)" ]}
You can install Magento Coding Standard by cloning this GitHub repo:
git clone git@github.com:magento/magento-coding-standard.gitcd magento-coding-standardcomposer install
It is possible also to install a standalone application viaComposer
composer create-project magento/magento-coding-standard --stability=dev magento-coding-standard
Command should return the list of installed coding standards including Magento2.
vendor/bin/phpcs -i
Once installed, you can runphpcs
from the command-line to analyze your codeMyAwesomeExtension
vendor/bin/phpcs --standard=Magento2 app/code/MyAwesomeExtension
Also, you can runphpcbf
from the command-line to fix your codeMyAwesomeExtension
for warnings like "PHPCBF CAN FIX THE [0-9]+ MARKED SNIFF VIOLATIONS AUTOMATICALLY"
vendor/bin/phpcbf --standard=Magento2 app/code/MyAwesomeExtension
See the communitycontribution model.
- Documentation of existing rules. SeeExtDN 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).
- Start with looking intoCommunity Dashboard. Any ticket in
Up for grabs
is a good candidate to start. - 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.
- The issue will appear in the
Backlog
column of theCommunity Dashboard. Once it will be discussed and getaccepted
label the issue will appear in theUp for grabs
column.
All rules should be covered by unit tests. EachTest.php
class should be accompanied by aTest.inc
file to allow for unit testing based upon the PHP_CodeSniffer parent classAbstractSniffUnitTest
.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
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 thepackage.json
file:
npm install
You can execute ESLint as follows:
npm run eslint -- path/to/analyze
Frommagento-coding-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 formagento
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
Each Magento source file included in this distribution is licensed under the OSL-3.0 license.
Please seeLICENSE.txt for the full text of theOpen Software License v. 3.0 (OSL-3.0).
About
Magento Coding Standard
Topics
Resources
License
OSL-3.0, Unknown licenses found
Licenses found
Code of conduct
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.