moddit / phpcs
Moddit PHP CS Rules
Installs: 19
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Type:phpcodesniffer-standard
pkg:composer/moddit/phpcs
Requires (Dev)
README
This project uses PHP_CodeSniffer to ensure that your PHP code adheres to a set of coding standards.
Requirements
- PHP 8.0 or higher
- Composer
Installation
-
Install PHP_CodeSniffer via Composer globally:
composer global require squizlabs/php_codesniffer
-
Verify the installation:
phpcs --version
-
Show the current PHP CodeSniffer ruleset:
phpcs --config-show
-
Set the moddit/phpcs as your global PHP CodeSniffer:
composer global require moddit/phpcs # Installing this package rule set phpcs --config-set default_standard ModditPHPCS # Updating default standard ruleset
Project ruleset
Your project needs a phpcs.xml file to instantly know which ruleset and folder to lint/format. Create or update the phpcs.xml file in the root of the project as follows. Don't forget to edit the project name and set the files to lint/format:
<?xml version="1.0"?> <!-- @see https://pear.php.net/manual/en/package.php.php-codesniffer.annotated-ruleset.php --> <ruleset name="Project Name"> <file>app</file> <!-- For Laravel --> <file>wp/wp-content/themes/blue-headless/includes</file> <!-- For WordPress --> <rule ref="ModditPHPCS"></rule> <!-- Our ruleset name --> </ruleset>
Usage
To check the PHP files in your project, run the following command from your global Composer packages:
phpcs
Or if the project has no phpcs.xml file in the root folder, specify the folder to lint:
phpcs ./path/to/php
Fixing Code
PHP_CodeSniffer also includes a tool to automatically fix coding standard violations. To use it, run:
phpcbf ./path/to/your/php/files
Or fix all folder files configured in the ruleset of the project's phpcs.xml:
phpcbf
IDEA Extensions
Visual Studio Code
To show phpcs.xml lint errors in Visual Studio Code, you can use the following extensions:
- PHP CodeSniffer: This extension integrates PHP_CodeSniffer with Visual Studio Code. Including linting and error fixing based on
phpcs.xmlext install shevaua.phpcs
PhpStorm
To show phpcs.xml lint errors in PhpStorm, you can configure the built-in PHP CodeSniffer integration:
For more detailed instructions, refer to the PhpStorm documentation.
Contributing
Contributions are welcome! Please submit a pull request or open an issue to discuss any changes.
License
This project is licensed under the MIT License. See the LICENSE file for details.