Add php-cs-fixer"

This commit is contained in:
osaajani 2019-10-29 16:52:49 +01:00
parent 9e9cd47b91
commit 508aeb0957
9 changed files with 120 additions and 0 deletions

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,51 @@
<?php
$header = <<<'EOF'
This file is part of PHP CS Fixer.
(c) Fabien Potencier <fabien@symfony.com>
Dariusz Rumiński <dariusz.ruminski@gmail.com>
This source file is subject to the MIT license that is bundled
with this source code in the file LICENSE.
EOF;
$finder = PhpCsFixer\Finder::create()
->exclude('tests/Fixtures')
->in(__DIR__)
->append([__DIR__.'/php-cs-fixer'])
;
$config = PhpCsFixer\Config::create()
->setRiskyAllowed(true)
->setRules([
'@PHP56Migration' => true,
'@PHPUnit60Migration:risky' => true,
'@PhpCsFixer' => true,
'@PhpCsFixer:risky' => true,
'header_comment' => ['header' => $header],
'list_syntax' => ['syntax' => 'long'],
'mb_str_functions' => true,
'method_separation' => true,
'braces' => ['position_after_anonymous_constructs' => 'next', 'position_after_control_structures' => 'next', 'position_after_functions_and_oop_constructs' => 'next'],
])
->setFinder($finder)
;
// special handling of fabbot.io service if it's using too old PHP CS Fixer version
if (false !== getenv('FABBOT_IO')) {
try {
PhpCsFixer\FixerFactory::create()
->registerBuiltInFixers()
->registerCustomFixers($config->getCustomFixers())
->useRuleSet(new PhpCsFixer\RuleSet($config->getRules()));
} catch (PhpCsFixer\ConfigurationException\InvalidConfigurationException $e) {
$config->setRules([]);
} catch (UnexpectedValueException $e) {
$config->setRules([]);
} catch (InvalidArgumentException $e) {
$config->setRules([]);
}
}
return $config;

Binary file not shown.

68
tests/php-cs-fixer/run.php Executable file
View File

@ -0,0 +1,68 @@
#!/usr/bin/php
<?php
function help ()
{
echo 'Usage : ' . __FILE__ . ' <arg>' . "\n" .
'Args :' . "\n" .
' - help : Show help message.' . "\n" .
' - lint : Show coding standards to fix.' . "\n" .
' - help : Fix coding standards.' . "\n";
exit(100);
}
$lint_commands = [
'php ' . __DIR__ . '/php-cs-fixer.phar -v --dry-run fix ' . __DIR__ . '/../../controllers/',
'php ' . __DIR__ . '/php-cs-fixer.phar -v --dry-run fix ' . __DIR__ . '/../../models/',
];
$fix_commands = [
'php ' . __DIR__ . '/php-cs-fixer.phar fix ' . __DIR__ . '/../../controllers/',
'php ' . __DIR__ . '/php-cs-fixer.phar fix ' . __DIR__ . '/../../models/',
];
if (count($argv) < 2 || $argv[1] === 'help')
{
help();
}
if ($argv[1] === 'lint')
{
echo "######################" . "\n";
echo "# SHOW ERRORS TO FIX #" . "\n";
echo "######################" . "\n";
echo "\n";
foreach ($lint_commands as $lint_command)
{
echo "Run : " . $lint_command . " \n";
$return = shell_exec($lint_command);
echo $return;
echo "\n\n";
}
exit(0);
}
if ($argv[1] === 'fix')
{
echo "##############" . "\n";
echo "# FIX ERRORS #" . "\n";
echo "##############" . "\n";
echo "\n";
foreach ($fix_commands as $fix_command)
{
echo "Run : " . $fix_command . " \n";
$return = shell_exec($fix_command);
echo $return;
echo "\n\n";
}
exit(0);
}
echo "Invalid arg : " . $argv[1] . "\n";
help();