Skip to content

Commit

Permalink
[bugfix] resolve path issue, fix multiple path php-cs-fix launch
Browse files Browse the repository at this point in the history
  • Loading branch information
alexndr-novikov committed Oct 9, 2019
1 parent 98bcda2 commit 31d0fab
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions bin/spiral-cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

declare(strict_types=1);


class CodeStyleHelper
{
public const PACKAGE_NAME = 'code-style';
Expand Down Expand Up @@ -33,6 +34,7 @@ class CodeStyleHelper
if (file_exists($file)) {
define('COMPOSER_AUTOLOAD', realpath($file));
define('VENDOR_DIR', dirname(realpath($file)));
define('PROJECT_ROOT', dirname(VENDOR_DIR));
break;
}
}
Expand Down Expand Up @@ -85,6 +87,14 @@ class CodeStyleHelper
{
return CONFIG_DIR . DIRECTORY_SEPARATOR . self::PHP_CS_FIXER_CONFIG_FILE;
}

public function wrapPaths(array $paths) : array
{
array_walk($paths, function (&$path) {
$path = PROJECT_ROOT . DIRECTORY_SEPARATOR . $path;
});
return $paths;
}
}


Expand All @@ -109,22 +119,24 @@ $codeStyleApp->addCommands([
InputArgument::IS_ARRAY | InputArgument::REQUIRED,
'Enumerate directories or files to check'
)
->setCode(static function (InputInterface $input, OutputInterface $output) use ($codeStyleHelper) {
->setCode(function (InputInterface $input, OutputInterface $output) use ($codeStyleHelper) {

$paths = $codeStyleHelper->wrapPaths($input->getArgument('paths'));

// PHPCBF call
$_SERVER['argv'] = array_merge([
'placeholder',
'--report=code',
'--standard=' . $codeStyleHelper->getPhpCsConfigPath(),
'src',
], $input->getArgument('paths'));
], $paths);

$runner = new Runner();
$runner->runPHPCBF();

// PHPCS-Fixer call
$application = new PhpCsFixApplication();
foreach ($input->getArgument('paths') as $path) {
$application->setAutoExit(false);
foreach ($paths as $path) {
$_SERVER['argv'] = [
'placeholder',
'fix',
Expand All @@ -142,12 +154,12 @@ $codeStyleApp->addCommands([
InputArgument::IS_ARRAY | InputArgument::REQUIRED,
'Enumerate directories or files to check'
)
->setCode(static function (InputInterface $input, OutputInterface $output) use ($codeStyleHelper) {
->setCode(function (InputInterface $input, OutputInterface $output) use ($codeStyleHelper) {
$_SERVER['argv'] = array_merge([
'placeholder',
'--report=code',
'--standard=' . $codeStyleHelper->getPhpCsConfigPath(),
], $input->getArgument('paths'));
], $codeStyleHelper->wrapPaths($input->getArgument('paths')));
$runner = new Runner();
$exitCode = $runner->runPHPCS();

Expand Down

0 comments on commit 31d0fab

Please sign in to comment.