diff --git a/composer.json b/composer.json index 326593c..3b9e9ad 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "galek/coding-standard", - "bin": ["ecs"], + "bin": ["ecs", "cs"], "license": "MIT", "require": { "php": "^7.1", diff --git a/cs b/cs new file mode 100755 index 0000000..ec8cf58 --- /dev/null +++ b/cs @@ -0,0 +1,65 @@ +#!/usr/bin/env php +check(); +unset($xdebug); + +# 2. create container + +// Detect configuration from level option +$configs = []; +$configs[] = (new LevelFileFinder())->detectFromInputAndDirectory(new ArgvInput(), __DIR__ . '/../config/'); + +// Fallback to config option +ConfigFileFinder::detectFromInput('ecs', new ArgvInput()); +$configs[] = ConfigFileFinder::provide( + 'ecs', + ['easy-coding-standard.yml', 'easy-coding-standard.yaml', 'ecs.yml', 'ecs.yaml'] +); + +// remove empty values +$configs = array_filter($configs); + +/** + * @param string[] $configs + */ +function computeConfigHash(array $configs): string +{ + $hash = ''; + foreach ($configs as $config) { + $hash .= md5_file($config); + } + + return $hash; +} + +$environment = 'prod' . computeConfigHash($configs) . random_int(1, 100000); +$easyCodingStandardKernel = new EasyCodingStandardKernel($environment, InputDetector::isDebug()); +if ($configs !== []) { + $easyCodingStandardKernel->setConfigs($configs); +} + +$easyCodingStandardKernel->boot(); +$container = $easyCodingStandardKernel->getContainer(); + +# 3. run +$application = $container->get(EasyCodingStandardConsoleApplication::class); +exit($application->run());