An Interest In:
Web News this Week
- March 21, 2024
- March 20, 2024
- March 19, 2024
- March 18, 2024
- March 17, 2024
- March 16, 2024
- March 15, 2024
May 17, 2021 11:47 pm GMT
Original Link: https://dev.to/arielmejiadev/install-php-code-sniffer-fixer-in-a-laravel-project-32ha
Install PHP code sniffer fixer in a Laravel project
Code sniffer is a package to apply syntax rules to our php code to follow PSR-standards, here a guide to install and use it:
Install code sniffer
composer require friendsofphp/php-cs-fixer
Add a configuration file
touch .php-cs-fixer.php
You can add your configuration rules, here a good example to use it in a laravel projects:
<?php$finder = PhpCsFixer\Finder::create() ->in(__DIR__) ->exclude(['bootstrap', 'storage', 'vendor']) ->name('*.php') ->name('_ide_helper') ->notName('*.blade.php') ->ignoreDotFiles(true) ->ignoreVCS(true);$config = new PhpCsFixer\Config();return $config->setRules([ '@PSR2' => true, 'array_syntax' => ['syntax' => 'short'], 'ordered_imports' => ['sort_algorithm' => 'alpha'], 'no_unused_imports' => true,]) ->setUsingCache(false) ->setFinder($finder);
Execute the code sniffer fixer
On terminal execute this command:
vendor/bin/php-cs-fixer fix
You can add more flags to customize the behavior of the fixer, here another example:
vendor/bin/php-cs-fixer fix --allow-risky=yes --dry-run --verbose
You can install husky with npm
to fire this commands on husky hooks and execute any of this commands automatically, this is all thanks for reading.
Original Link: https://dev.to/arielmejiadev/install-php-code-sniffer-fixer-in-a-laravel-project-32ha
Share this article:
Tweet
View Full Article
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To