itrocks / coding-standard
CodeSniffer ruleset for the it.rocks 0.2+ coding standard
Installs: 0
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
Type:phpcodesniffer-standard
Requires
- php: >=8.1
- brainmaestro/composer-git-hooks: ^2.4
- squizlabs/php_codesniffer: ^3.0
Requires (Dev)
- phpunit/phpunit: 9.*
This package is auto-updated.
Last update: 2024-11-07 10:57:31 UTC
README
A coding standard to check against the it.rocks coding standards.
1. Installation
1.1 Composer
This standard can be installed with Composer dependency manager:
-
Install Composer
-
Install coding standard as a dependency of your project
composer require --dev itrocks/coding-standard
- Check the installed coding standards for "ITRocks"
vendor/bin/phpcs -i
Should display the ITRocks coding standard, between others
- If needed, add the coding standard to the PHP_CodeSniffer install path
vendor/bin/phpcs --config-set installed_paths `realpath vendor/itrocks/coding-standard/ITRocks`
- Done!
vendor/bin/phpcs --standard=ITRocks ./
1.2 Stand-alone
- Checkout this repository
git clone https://git.crafter.fr/itrocks/coding-standard
- Install dependencies
cd coding-standard
composer install
- Check the installed coding standards for "ITRocks"
vendor/bin/phpcs -i
- If needed, add the coding standard to the PHP_CodeSniffer install path
vendor/bin/phpcs --config-set installed_paths `realpath ITRocks`
- Usage
vendor/bin/phpcs --standard=ITRocks /home/vendor/project
You can check that this tools himself respect ITRocks standard
vendor/bin/phpcs --standard=ITRocks --extensions=php $CI_PROJECT_DIR/ITRocks
2. Run unit tests
From the command line
Simply run
vendor/bin/phpunit
From PHPStorm, with PHP installed locally
Right-click on "phpunit.xml.dist" and select "Run phpunit.xml.dist".
This works only for coding-standard being installed into a dependency of your project. If you want to run tests on a standalone mode, you have to change this file path into the phpunit.xml.dist file :
- for dependency : bootstrap="../../../vendor/squizlabs/php_codesniffer/tests/bootstrap.php"
- for standalone : bootstrap="vendor/squizlabs/php_codesniffer/tests/bootstrap.php"
3. PhpStorm integration
After having cloned this project on your disk, you're able to integrate coding standards rules directly in PhpStorm.
Go in PhpStorm settings Languages & Framework > PHP > Code Sniffer
to configure the path of phpcs executable:
Click on Apply button.
Now, go to: Editor > Inspections > PHP > PHP Code Sniffer validation
, check the checkbox and configure as following:
That's it!
To inspect a file/directory, just right click on it in the project windows, select "Inspect Code...", then OK.
4. PhpStorm AutoFix
- Go to Settings -> Tools -> External tools
- Configure the following
- Name : Apply Coding Standards
- Program :
/home/vendor/project/vendor/bin/phpcbf
(Use the path to your project) - Arguments :
-vvv --standard=ITRocks --extensions=php,fixed.inc $FilePath$
- Project directory :
$ProjectFileDir$
- Go to Settings -> Keymap -> External Tools -> Coding Standard
- Right click -> Add Keyboard Shortcut
- Add : Ctrl+<
Now you can auto-fix your php files using the Ctrl+< keyboard combination, or the menu Tools -> External Tools -> Apply Coding Standards