How to install phpcs for magento 2

Step-by-Step Installation of phpcs for Magento 2

Install PHP_CodeSniffer via Composer, If it's not already installed. Create A directory and open the terminal
Copy
                            
composer require --dev squizlabs/php_codesniffer
This installs phpcs and phpcbf binaries in vendor/bin/. Install Magento 2 Coding Standard
Copy
                            
composer require --dev magento/magento-coding-standard
Register Magento Coding Standard with phpcs
Copy
                            
vendor/bin/phpcs --config-set installed_paths vendor/magento/magento-coding-standard
Verify the Installed Standards
Copy
                            
vendor/bin/phpcs -i
To check a PHP file or folder using the Magento 2 coding standard
Copy
                            
vendor/bin/phpcs --standard=Magento2 app/code/Vendor/Module
To auto-fix fixable issues:
Copy
                            
vendor/bin/phpcbf --standard=Magento2 app/code/Vendor/Module
2025-06-16 04:42:46
Copyright © 2013-present Magento, Inc. All rights reserved.