diff --git a/.gitignore b/.gitignore index 88e99d5..666d621 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ -vendor -composer.lock \ No newline at end of file +/vendor +/composer.lock +/.php_cs.cache diff --git a/.php_cs b/.php_cs deleted file mode 100644 index a4cbffb..0000000 --- a/.php_cs +++ /dev/null @@ -1,56 +0,0 @@ -exclude('vendor') - ->in(__DIR__); - -// Return a Code Sniffing configuration using -// all sniffers needed for PSR-2 -// and additionally: -// - Remove leading slashes in use clauses. -// - PHP single-line arrays should not have trailing comma. -// - Single-line whitespace before closing semicolon are prohibited. -// - Remove unused use statements in the PHP source code -// - Ensure Concatenation to have at least one whitespace around -// - Remove trailing whitespace at the end of blank lines. -return Symfony\CS\Config\Config::create() - ->level(Symfony\CS\FixerInterface::PSR2_LEVEL) - ->fixers([ - 'remove_leading_slash_use', - 'single_array_no_trailing_comma', - 'spaces_before_semicolon', - 'unused_use', - 'concat_with_spaces', - 'whitespacy_lines', - 'ordered_use', - 'single_quote', - 'duplicate_semicolon', - 'extra_empty_lines', - 'phpdoc_no_package', - 'phpdoc_scalar', - 'no_empty_lines_after_phpdocs' - ]) - ->finder($finder); \ No newline at end of file diff --git a/.php_cs.dist b/.php_cs.dist new file mode 100644 index 0000000..c335e9b --- /dev/null +++ b/.php_cs.dist @@ -0,0 +1,77 @@ +setRiskyAllowed(true) + ->setRules([ + '@PSR2' => true, + 'array_syntax' => [ + 'syntax' => 'short', + ], + 'binary_operator_spaces' => true, + 'concat_space' => [ + 'spacing' => 'one', + ], + 'function_typehint_space' => true, + 'hash_to_slash_comment' => true, + 'linebreak_after_opening_tag' => true, + 'lowercase_cast' => true, + 'method_separation' => true, + 'native_function_casing' => true, + 'new_with_braces' => true, + 'no_alias_functions' => true, + 'no_blank_lines_after_class_opening' => true, + 'no_blank_lines_after_phpdoc' => true, + 'no_blank_lines_before_namespace' => true, + 'no_empty_comment' => true, + 'no_empty_phpdoc' => true, + 'no_empty_statement' => true, + 'no_extra_consecutive_blank_lines' => [ + 'continue', + 'curly_brace_block', + 'extra', + 'parenthesis_brace_block', + 'square_brace_block', + 'throw', + ], + 'no_leading_import_slash' => true, + 'no_leading_namespace_whitespace' => true, + 'no_multiline_whitespace_around_double_arrow' => true, + 'no_multiline_whitespace_before_semicolons' => true, + 'no_short_bool_cast' => true, + 'no_singleline_whitespace_before_semicolons' => true, + 'no_trailing_comma_in_list_call' => true, + 'no_trailing_comma_in_singleline_array' => true, + 'no_unneeded_control_parentheses' => [ + 'break', + 'clone', + 'continue', + 'echo_print', + 'return', + 'switch_case', + ], + 'no_unreachable_default_argument_value' => true, + 'no_unused_imports' => true, + 'no_useless_else' => true, + 'no_useless_return' => true, + 'no_whitespace_before_comma_in_array' => true, + 'no_whitespace_in_blank_line' => true, + 'normalize_index_brace' => true, + 'ordered_imports' => true, + 'phpdoc_add_missing_param_annotation' => true, + 'phpdoc_no_package' => true, + 'phpdoc_order' => true, + 'phpdoc_scalar' => true, + 'phpdoc_types' => true, + 'self_accessor' => true, + 'short_scalar_cast' => true, + 'single_quote' => true, + 'standardize_not_equals' => true, + 'ternary_operator_spaces' => true, + 'trailing_comma_in_multiline_array' => true, + 'whitespace_after_comma_in_array' => true, + ]) + ->setFinder( + PhpCsFixer\Finder::create() + ->in(__DIR__) + ->exclude('res') + ->exclude('vendor') + ); diff --git a/.styleci.yml b/.styleci.yml new file mode 100644 index 0000000..c83a7c6 --- /dev/null +++ b/.styleci.yml @@ -0,0 +1,58 @@ +preset: psr2 + +enabled: + - alpha_ordered_imports + - binary_operator_spaces + - concat_with_spaces + - function_typehint_space + - hash_to_slash_comment + - linebreak_after_opening_tag + - lowercase_cast + - method_separation + - native_function_casing + - new_with_braces + - no_alias_functions + - no_blank_lines_after_class_opening + - no_blank_lines_after_phpdoc + - no_blank_lines_before_namespace + - no_empty_comment + - no_empty_phpdoc + - no_empty_statement + - no_extra_block_blank_lines + - no_extra_consecutive_blank_lines + - no_leading_import_slash + - no_leading_namespace_whitespace + - no_multiline_whitespace_around_double_arrow + - no_multiline_whitespace_before_semicolons + - no_short_bool_cast + - no_singleline_whitespace_before_semicolons + - no_trailing_comma_in_list_call + - no_trailing_comma_in_singleline_array + - no_unneeded_control_parentheses + - no_unreachable_default_argument_value + - no_unused_imports + - no_useless_else + - no_useless_return + - no_whitespace_before_comma_in_array + - no_whitespace_in_blank_line + - normalize_index_brace + - phpdoc_add_missing_param_annotation + - phpdoc_no_package + - phpdoc_order + - phpdoc_scalar + - phpdoc_types + - self_accessor + - short_array_syntax + - short_scalar_cast + - single_quote + - standardize_not_equals + - ternary_operator_spaces + - trailing_comma_in_multiline_array + - whitespace_after_comma_in_array + +finder: + name: + - "*.php" + exclude: + - "res" + - "vendor" diff --git a/src/Config.php b/src/Config.php index f16fd0f..fbf2f10 100644 --- a/src/Config.php +++ b/src/Config.php @@ -17,11 +17,11 @@ class Config /** * @var array */ - public static $defaultConfig = array( + public static $defaultConfig = [ 'env-dir' => '', 'cache-dir' => null, 'allow-overrides' => true, - ); + ]; /** * @var array @@ -87,7 +87,7 @@ public function get($key, $flags = 0) */ public function all($flags = 0) { - $all = array(); + $all = []; foreach ($this->config as $key => $_) { $all['config'][$key] = $this->get($key, $flags); } @@ -100,9 +100,9 @@ public function all($flags = 0) */ public function raw() { - return array( + return [ 'config' => $this->config, - ); + ]; } /** @@ -176,7 +176,7 @@ public static function load(\Composer\IO\IOInterface $io, \Composer\Config $comp { static $config; if ($config === null) { - $baseDir = realpath(substr($composerConfig->get('vendor-dir'), 0, -strlen($composerConfig->get('vendor-dir', Config::RELATIVE_PATHS)))); + $baseDir = realpath(substr($composerConfig->get('vendor-dir'), 0, -strlen($composerConfig->get('vendor-dir', self::RELATIVE_PATHS)))); $localConfig = \Composer\Factory::getComposerFile(); $file = new \Composer\Json\JsonFile($localConfig, new \Composer\Util\RemoteFilesystem($io)); diff --git a/src/Plugin.php b/src/Plugin.php index da24e7c..a186d38 100644 --- a/src/Plugin.php +++ b/src/Plugin.php @@ -65,9 +65,9 @@ public function activate(Composer $composer, IOInterface $io) */ public static function getSubscribedEvents() { - return array( - ScriptEvents::PRE_AUTOLOAD_DUMP => array('onPreAutoloadDump') - ); + return [ + ScriptEvents::PRE_AUTOLOAD_DUMP => ['onPreAutoloadDump'], + ]; } /** @@ -98,9 +98,9 @@ public function onPreAutoloadDump() * Constructs the include file content * * @param string $includeFile The path to the file that will be included by composer in autoload.php - * @return string * @throws \RuntimeException * @throws \InvalidArgumentException + * @return string */ protected function getIncludeFileContent($includeFile) { diff --git a/tests/Unit/CacheTest.php b/tests/Unit/CacheTest.php index 76a841d..fa4415c 100644 --- a/tests/Unit/CacheTest.php +++ b/tests/Unit/CacheTest.php @@ -45,7 +45,7 @@ protected function tearDown() $cacheDir = __DIR__ . '/Fixtures/cache'; foreach (glob($cacheDir . '/*.php') as $file) { unlink($file); - }; + } } /**