diff --git a/.gitignore b/.gitignore index 43c5bf4..60778ef 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ /.idea/ +.DS_Store /vendor/ .php-cs-fixer.cache composer.lock diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php new file mode 100644 index 0000000..4ab7bb4 --- /dev/null +++ b/.php-cs-fixer.dist.php @@ -0,0 +1,73 @@ +ignoreDotFiles(false) + ->ignoreVCSIgnored(true) + ->exclude(['dev-tools/phpstan', 'tests/Fixtures']) + ->in(__DIR__); + +$config = new PhpCsFixer\Config(); +$config + ->setRiskyAllowed(true) + ->setRules([ + '@PSR12' => true, + '@Symfony' => true, + '@Symfony:risky' => true, + '@PHP80Migration' => true, + '@PHP80Migration:risky' => true, + 'align_multiline_comment' => true, + 'array_indentation' => true, + 'binary_operator_spaces' => ['operators' => ['=' => 'align_single_space_minimal', '=>' => 'align_single_space_minimal', '??=' => 'align_single_space_minimal', '|' => 'no_space']], + 'blank_line_before_statement' => ['statements' => ['do', 'for', 'foreach', 'if', 'return', 'switch', 'while']], + 'class_attributes_separation' => ['elements' => ['method' => 'one', 'trait_import' => 'none']], + 'combine_consecutive_issets' => true, + 'combine_consecutive_unsets' => true, + 'concat_space' => ['spacing' => 'one'], + 'echo_tag_syntax' => ['format' => 'long'], + 'escape_implicit_backslashes' => true, + 'fopen_flags' => false, + 'fully_qualified_strict_types' => false, + 'function_to_constant' => ['functions' => ['get_class', 'get_called_class', 'php_sapi_name', 'phpversion', 'pi']], + 'heredoc_to_nowdoc' => true, + 'increment_style' => ['style' => 'post'], + 'method_argument_space' => ['on_multiline' => 'ensure_fully_multiline', 'keep_multiple_spaces_after_comma' => false, 'after_heredoc' => true], + 'method_chaining_indentation' => true, + 'modernize_types_casting' => false, + 'multiline_comment_opening_closing' => true, + 'multiline_whitespace_before_semicolons' => ['strategy' => 'no_multi_line'], + 'native_constant_invocation' => false, + 'native_function_invocation' => false, + 'no_alternative_syntax' => true, + 'no_null_property_initialization' => true, + 'no_superfluous_phpdoc_tags' => false, + 'no_unneeded_curly_braces' => true, + 'no_useless_return' => true, + 'not_operator_with_space' => false, + 'nullable_type_declaration_for_default_null_value' => true, + 'operator_linebreak' => true, + 'ordered_class_elements' => true, + 'ordered_imports' => ['imports_order' => ['class', 'function', 'const'], 'sort_algorithm' => 'alpha'], + 'php_unit_strict' => true, + 'php_unit_test_case_static_method_calls' => true, + 'phpdoc_add_missing_param_annotation' => true, + 'phpdoc_annotation_without_dot' => false, + 'phpdoc_no_alias_tag' => false, + 'phpdoc_no_empty_return' => false, + 'phpdoc_summary' => false, // no need to add dot at the end of short description + 'phpdoc_to_comment' => false, // allow use of docblock comment in function body + 'phpdoc_var_annotation_correct_order' => true, + 'pow_to_exponentiation' => false, + 'self_static_accessor' => true, + 'simplified_null_return' => false, + 'strict_comparison' => true, + 'strict_param' => true, + 'trailing_comma_in_multiline' => ['elements' => ['arrays', 'arguments', 'parameters', 'match']], + 'use_arrow_functions' => false, + 'whitespace_after_comma_in_array' => true, + 'yoda_style' => ['equal' => false, 'identical' => false, 'less_and_greater' => false, 'always_move_variable' => false], + ]) + ->setFinder($finder); + +return $config; diff --git a/composer.json b/composer.json index 44a415e..1752806 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,7 @@ "symfony/console": "^6.0.0" }, "require-dev": { - "friendsofphp/php-cs-fixer":"*", + "friendsofphp/php-cs-fixer":"^3.22", "phpstan/phpstan":"*" }, "bin": ["quality"] diff --git a/quality b/quality index 7d92aec..6235136 100755 --- a/quality +++ b/quality @@ -1,7 +1,7 @@ #!/usr/bin/env php getArguments() !== []) { $input->getArgument(self::ARGUMENT_INSTALL) !== null => $this->executeInstall($active_options, $input, $output), $input->getArgument(self::ARGUMENT_UNINSTALL) !== null => $this->executeUninstall($input, $output), - default => $this->executeRun($active_options, $input, $output) + default => $this->executeRun($active_options, $input, $output), }; } private function checkBinInstall(string $bin_name): bool { - return file_exists($this->getPath() .'/vendor/bin/'. $bin_name); + return file_exists($this->getPath() . '/vendor/bin/' . $bin_name); } private function checkPhpCsFixerConfigFileExist(): bool @@ -67,22 +67,20 @@ private function checkPhpCsFixerConfigFileExist(): bool return false; } - private static function getChangedFilesString():?string + private static function getChangedFilesString(): ?string { - exec('git status -v', $exec_output); + exec("git status -s | grep '^ M' | grep -v '^ D' | awk '{print $2}'", $exec_output); if ($exec_output === '') { return null; } - return implode(' ', array_map(function (string $output_line): string { - return trim(substr($output_line, 2)); - }, array_filter($exec_output, fn (string $output_line) => !str_starts_with($output_line, ' M')))); - + return implode(' ', $exec_output); } + private function executeRun(array $active_options, InputInterface $input, OutputInterface $output): int { - $changed_files_string = self::getChangedFilesString(); + $changed_files_string = self::getChangedFilesString(); if ($changed_files_string === null) { return self::SUCCESS; @@ -128,29 +126,35 @@ private function getPath(): string private function runPhpCsFixerFix(OutputInterface $output, string $change_files_string): int { if (!$this->checkBinInstall(self::PHPCSFIXER_BIN_NAME)) { - $output->writeln(" The PHPCsFixer packages not install in your project"); + $output->writeln(' The PHPCsFixer packages not install in your project'); + return self::FAILURE; } + if (!$this->checkPhpCsFixerConfigFileExist()) { $output->writeln(' The PHPCsFixer config file not found on your project '); + return self::FAILURE; } $output->writeln(' PHP Cs Fixer Fixing ... '); $base_path = $this->getPath(); exec("$base_path/vendor/bin/php-cs-fixer fix --config $base_path/$this->phpCsFixerConfig $change_files_string", $execute_output, $result_code); + if ($execute_output !== [] && $execute_output[0] !== '') { $output->writeln(' Some Files have fixed, please re-commit these changes'); + return self::FAILURE; } - + return $result_code; } private function runPhpStanFix(OutputInterface $output, string $change_files_string): int { if (!$this->checkBinInstall(self::PHPSTAN_BIN_NAME)) { - $output->writeln(" The PHPStan packages not install in your project"); + $output->writeln(' The PHPStan packages not install in your project'); + return self::FAILURE; } @@ -173,7 +177,7 @@ private function runPhpStanFix(OutputInterface $output, string $change_files_str private function executeInstall(array $active_options, InputInterface $input, OutputInterface $output): int { - $option_text = implode(' ', array_map(fn (string $active_option): string => '--' . $active_option, $active_options)); + $option_text = implode(' ', array_map(fn (string $active_option): string => '--' . $active_option, $active_options)); $execute_command = <<