From 91ef467872a79cdd7e0c20daea5e8c2498a5db6b Mon Sep 17 00:00:00 2001 From: Jesse Donat Date: Fri, 3 Mar 2023 13:35:52 -0600 Subject: [PATCH] php-cs-fixer cleanup --- .php_cs => .php-cs-fixer.dist.php | 35 ++++++++++++++++--- .../ClosingBraceNewlineSniff.php | 16 ++++----- .../OpeningOneTrueBraceSniff.php | 13 +++---- .../General/BinaryOperationNewlineSniff.php | 13 +++---- .../General/ReturnTrailingNewlineSniff.php | 10 ++---- .../MethodParameterFormattingSniff.php | 10 ++---- 6 files changed, 48 insertions(+), 49 deletions(-) rename .php_cs => .php-cs-fixer.dist.php (81%) diff --git a/.php_cs b/.php-cs-fixer.dist.php similarity index 81% rename from .php_cs rename to .php-cs-fixer.dist.php index 504542c..bab7f63 100644 --- a/.php_cs +++ b/.php-cs-fixer.dist.php @@ -6,7 +6,7 @@ ->name('*.php'); -return PhpCsFixer\Config::create() +return (new PhpCsFixer\Config) ->setUsingCache(true) ->setIndent("\t") ->setLineEnding("\n") @@ -14,12 +14,12 @@ ->setRiskyAllowed(true) ->setRules( [ - '@PHPUnit60Migration:risky' => true, + '@PHPUnit84Migration:risky' => true, 'php_unit_test_case_static_method_calls' => [ 'call_type' => 'this', ], - 'concat_space' => [ + 'concat_space' => [ 'spacing' => 'one', ], @@ -36,7 +36,10 @@ 'no_leading_import_slash' => true, 'no_leading_namespace_whitespace' => true, + 'array_indentation' => true, + 'no_whitespace_in_blank_line' => true, + 'no_trailing_whitespace' => true, 'phpdoc_add_missing_param_annotation' => [ 'only_untyped' => true, ], 'phpdoc_indent' => true, @@ -84,6 +87,7 @@ 'single_line_after_imports' => true, 'single_blank_line_before_namespace' => true, + 'single_line_comment_spacing' => true, 'blank_line_after_namespace' => true, 'single_blank_line_at_eof' => true, 'ternary_to_null_coalescing' => true, @@ -102,11 +106,11 @@ ], 'blank_line_before_statement' => [ - 'statements' => [ 'continue', 'try', 'switch', 'die', 'exit', 'throw', 'return', 'yield', 'do' ], + 'statements' => [ 'continue', 'try', 'switch', 'exit', 'throw', 'return', 'yield', 'do' ], ], 'no_superfluous_phpdoc_tags' => [ - 'remove_inheritdoc' => false, // specifically for this, for now + 'remove_inheritdoc' => true, ], 'no_superfluous_elseif' => true, @@ -118,6 +122,7 @@ 'escape_implicit_backslashes' => true, 'explicit_indirect_variable' => true, 'heredoc_to_nowdoc' => true, + 'heredoc_indentation' => true, 'no_singleline_whitespace_before_semicolons' => true, @@ -148,6 +153,26 @@ 'elseif' => true, 'simple_to_complex_string_variable' => true, + + 'global_namespace_import' => [ + 'import_classes' => false, + 'import_constants' => false, + 'import_functions' => false, + ], + + 'trailing_comma_in_multiline' => true, + 'single_line_comment_style' => true, + + 'is_null' => true, + 'yoda_style' => [ + 'equal' => false, + 'identical' => false, + 'less_and_greater' => null, + ], + + 'empty_loop_condition' => [ + 'style' => 'for', + ], ] ) ->setFinder($finder); diff --git a/src/Corpus/Sniffs/ControlStructures/ClosingBraceNewlineSniff.php b/src/Corpus/Sniffs/ControlStructures/ClosingBraceNewlineSniff.php index 0f1e200..0dec737 100644 --- a/src/Corpus/Sniffs/ControlStructures/ClosingBraceNewlineSniff.php +++ b/src/Corpus/Sniffs/ControlStructures/ClosingBraceNewlineSniff.php @@ -33,17 +33,11 @@ class ClosingBraceNewlineSniff implements Sniff { public const CODE_MUST_NEWLINE_FOLLOWING_CURLY_BRACKET = 'MustNewlineFollowingCurlyBracket'; - /** - * @inheritDoc - */ - public function register() { + public function register() : array { return [ T_CLOSE_CURLY_BRACKET ]; } - /** - * @inheritDoc - */ - public function process( File $phpcsFile, $stackPtr ) { + public function process( File $phpcsFile, $stackPtr ) : void { $tokens = $phpcsFile->getTokens(); $prevPtr = $phpcsFile->findPrevious(T_WHITESPACE, $stackPtr - 1, null, true); @@ -68,9 +62,11 @@ public function process( File $phpcsFile, $stackPtr ) { return; } - $fix = $phpcsFile->addFixableError('Must be a newline following closing curly bracket', + $fix = $phpcsFile->addFixableError( + 'Must be a newline following closing curly bracket', $stackPtr, - self::CODE_MUST_NEWLINE_FOLLOWING_CURLY_BRACKET); + self::CODE_MUST_NEWLINE_FOLLOWING_CURLY_BRACKET + ); if( $fix ) { $phpcsFile->fixer->beginChangeset(); $phpcsFile->fixer->addNewline($stackPtr); diff --git a/src/Corpus/Sniffs/ControlStructures/OpeningOneTrueBraceSniff.php b/src/Corpus/Sniffs/ControlStructures/OpeningOneTrueBraceSniff.php index 7c71e8c..896e28f 100644 --- a/src/Corpus/Sniffs/ControlStructures/OpeningOneTrueBraceSniff.php +++ b/src/Corpus/Sniffs/ControlStructures/OpeningOneTrueBraceSniff.php @@ -38,17 +38,11 @@ class OpeningOneTrueBraceSniff implements Sniff { public const CODE_BRACE_ON_NEWLINE = 'BraceOnNewLine'; - /** - * @inheritDoc - */ - public function register() { + public function register() : array { return [ T_OPEN_CURLY_BRACKET ]; } - /** - * @inheritDoc - */ - public function process( File $phpcsFile, $stackPtr ) { + public function process( File $phpcsFile, $stackPtr ) : void { $tokens = $phpcsFile->getTokens(); $prev = $phpcsFile->findPrevious(T_WHITESPACE, $stackPtr - 1, 0, true); if( !$prev || $tokens[$prev]['line'] === $tokens[$stackPtr]['line'] ) { @@ -67,7 +61,8 @@ public function process( File $phpcsFile, $stackPtr ) { $fix = $phpcsFile->addFixableError( 'Opening brace should be on the same line as the declaration', $stackPtr, - self::CODE_BRACE_ON_NEWLINE); + self::CODE_BRACE_ON_NEWLINE + ); if( $fix ) { $phpcsFile->fixer->beginChangeset(); for( $i = $prev + 1; $i < $stackPtr; $i++ ) { diff --git a/src/Corpus/Sniffs/General/BinaryOperationNewlineSniff.php b/src/Corpus/Sniffs/General/BinaryOperationNewlineSniff.php index 0065396..25e1cc3 100644 --- a/src/Corpus/Sniffs/General/BinaryOperationNewlineSniff.php +++ b/src/Corpus/Sniffs/General/BinaryOperationNewlineSniff.php @@ -34,17 +34,11 @@ class BinaryOperationNewlineSniff implements Sniff { public const CODE_BOOLEAN_OPERATION_SHOULD_LEAD_LINE = 'BooleanOperationShouldLeadLine'; - /** - * @inheritDoc - */ - public function register() { + public function register() : array { return [ T_BOOLEAN_AND, T_BOOLEAN_OR ]; } - /** - * @inheritDoc - */ - public function process( File $phpcsFile, $stackPtr ) { + public function process( File $phpcsFile, $stackPtr ) : void { $tokens = $phpcsFile->getTokens(); $nextPtr = $phpcsFile->findNext(T_WHITESPACE, $stackPtr + 1, null, true); @@ -52,7 +46,8 @@ public function process( File $phpcsFile, $stackPtr ) { return; } - $fix = $phpcsFile->addFixableError('Boolean %s should start line and not end previous line', + $fix = $phpcsFile->addFixableError( + 'Boolean %s should start line and not end previous line', $stackPtr, self::CODE_BOOLEAN_OPERATION_SHOULD_LEAD_LINE, [ $tokens[$stackPtr]['content'] ] diff --git a/src/Corpus/Sniffs/General/ReturnTrailingNewlineSniff.php b/src/Corpus/Sniffs/General/ReturnTrailingNewlineSniff.php index 697a391..868dfbc 100644 --- a/src/Corpus/Sniffs/General/ReturnTrailingNewlineSniff.php +++ b/src/Corpus/Sniffs/General/ReturnTrailingNewlineSniff.php @@ -31,17 +31,11 @@ class ReturnTrailingNewlineSniff implements Sniff { public const CODE_RETURN_HAS_TRAILING_NEWLINE = 'ReturnHasTrailingNewline'; - /** - * @inheritDoc - */ - public function register() { + public function register() : array { return [ T_RETURN ]; } - /** - * @inheritDoc - */ - public function process( File $phpcsFile, $stackPtr ) { + public function process( File $phpcsFile, $stackPtr ) : void { $tokens = $phpcsFile->getTokens(); $eosPtr = $phpcsFile->findEndOfStatement($stackPtr); diff --git a/src/Corpus/Sniffs/Methods/MethodParameterFormattingSniff.php b/src/Corpus/Sniffs/Methods/MethodParameterFormattingSniff.php index 16c67b0..2b8d60e 100644 --- a/src/Corpus/Sniffs/Methods/MethodParameterFormattingSniff.php +++ b/src/Corpus/Sniffs/Methods/MethodParameterFormattingSniff.php @@ -32,17 +32,11 @@ class MethodParameterFormattingSniff implements Sniff { public const CODE_OVERLY_LONG_ARGUMENT_LIST = 'OverlyLongArgumentList'; - /** - * @inheritDoc - */ - public function register() { + public function register() : array { return [ T_FUNCTION, T_CLOSURE ]; } - /** - * @inheritDoc - */ - public function process( File $phpcsFile, $stackPtr ) { + public function process( File $phpcsFile, $stackPtr ) : void { $tokens = $phpcsFile->getTokens(); $scopePtr = $tokens[$stackPtr]['scope_opener'] ?? $phpcsFile->findEndOfStatement($stackPtr);