PHP code example of yard / php-cs-fixer-rules
1. Go to this page and download the library: Download yard/php-cs-fixer-rules library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
yard / php-cs-fixer-rules example snippets
use PhpCsFixer\Finder;
$finder = Finder::create()
->in(__DIR__)
->name('*.php')
->notName('*.blade.php')
->ignoreDotFiles(true)
->ignoreVCS(true)
->exclude('public')
->exclude('node_modules')
->exclude('build');
return \Yard\PhpCsFixerRules\Config::create($finder);
/**
* Default rules:
*
* [
* 'method_chaining_indentation' => true,
* 'yoda_style' => [
* 'always_move_variable' => true,
* 'equal' => true,
* 'identical' => true,
* 'less_and_greater' => true,
* ],
* 'binary_operator_spaces' => [
* 'default' => 'single_space',
* 'operators' => [
* '=>' => null,
* '|' => 'no_space',
* ],
* ],
* ]
*/
$config = \Yard\PhpCsFixerRules\Config::create($finder)
->removeRules(['yoda_style', 'binary_operator_spaces']);
/**
* Expected rule set:
*
* [
* 'method_chaining_indentation' => true,
* ]
*/
return $config->removeRule('method_chaining_indentation');
/**
* Expected rule set: []
*/
/**
* Default rules:
*
* [
* 'yoda_style' => [
* 'always_move_variable' => true,
* 'equal' => true,
* 'identical' => true,
* 'less_and_greater' => true,
* ],
* 'binary_operator_spaces' => [
* 'default' => 'single_space',
* 'operators' => [
* '=>' => null,
* '|' => 'no_space',
* ],
* ],
* ]
*/
return \Yard\PhpCsFixerRules\Config::create($finder)
->mergeRules([
'yoda_style' => [
'equal' => false,
],
'binary_operator_spaces' => [
'operators' => [
'|' => 'single_space',
'<>' => null,
]
]
]);
/**
* Expected rule set:
*
* [
* 'yoda_style' => [
* 'always_move_variable' => true,
* 'equal' => false, // this setting changed!
* 'identical' => true,
* 'less_and_greater' => true,
* ],
* 'binary_operator_spaces' => [
* 'default' => 'single_space',
* 'operators' => [
* '=>' => null,
* '|' => 'single_space', // this setting changed!
* '<>' => null, // this setting was added!
* ],
* ],
* ]
*/
return \Yard\PhpCsFixerRules\Config::create($finder)
->setRiskyAllowed(false) // native PHP CS Fixer method
->mergeRules([ // Yard\PhpCsFixerRules\Config method
'yoda_style' => [
'equal' => false,
],
'binary_operator_spaces' => [
'operators' => [
'|' => 'single_space',
'<>' => null,
]
]
]);
return \Yard\PhpCsFixerRules\Config::create($finder)
->setRiskyAllowed(false);