From 3302a8c115b4365e4456f2ce2576390e10d30ed3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Stasicki?= Date: Thu, 12 Jun 2025 14:47:49 +0200 Subject: [PATCH 1/6] Disable TypedClassConstantFixer for PHP < 8.3 --- src/Unwanted.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Unwanted.php b/src/Unwanted.php index f2d6b96..16cb3c5 100644 --- a/src/Unwanted.php +++ b/src/Unwanted.php @@ -14,6 +14,7 @@ use PhpCsFixerCustomFixers\Fixer\PhpdocVarAnnotationToAssertFixer; use PhpCsFixerCustomFixers\Fixer\PromotedConstructorPropertyFixer; use PhpCsFixerCustomFixers\Fixer\ReadonlyPromotedPropertiesFixer; +use PhpCsFixerCustomFixers\Fixer\TypedClassConstantFixer; final class Unwanted { @@ -55,6 +56,7 @@ public static function isUnwanted(string $name): bool PhpdocVarAnnotationToAssertFixer::name(), PromotedConstructorPropertyFixer::name(), ReadonlyPromotedPropertiesFixer::name(), + TypedClassConstantFixer::name(), ], true, ); From 1b4c53690d877947f2146ed311945bd4b3b071f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Stasicki?= Date: Thu, 12 Jun 2025 14:58:11 +0200 Subject: [PATCH 2/6] Disable PhpdocTagNoNamedArgumentsFixer for backward compatibility --- src/Unwanted.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Unwanted.php b/src/Unwanted.php index 16cb3c5..82b4a77 100644 --- a/src/Unwanted.php +++ b/src/Unwanted.php @@ -11,6 +11,7 @@ use PhpCsFixerCustomFixers\Fixer\NoNullableBooleanTypeFixer; use PhpCsFixerCustomFixers\Fixer\NoReferenceInFunctionDefinitionFixer; use PhpCsFixerCustomFixers\Fixer\PhpdocOnlyAllowedAnnotationsFixer; +use PhpCsFixerCustomFixers\Fixer\PhpdocTagNoNamedArgumentsFixer; use PhpCsFixerCustomFixers\Fixer\PhpdocVarAnnotationToAssertFixer; use PhpCsFixerCustomFixers\Fixer\PromotedConstructorPropertyFixer; use PhpCsFixerCustomFixers\Fixer\ReadonlyPromotedPropertiesFixer; @@ -36,15 +37,18 @@ public static function isUnwanted(string $name): bool 'not_operator_with_space', 'not_operator_with_successor_space', 'octal_notation', + 'php_unit_attributes', 'php_unit_internal_class', 'php_unit_size_class', 'php_unit_strict', 'php_unit_test_class_requires_covers', 'phpdoc_summary', 'phpdoc_to_property_type', + 'phpdoc_to_return_type', 'single_line_comment_spacing', 'single_line_throw', 'strict_param', + 'string_implicit_backslashes', 'void_return', ConstructorEmptyBracesFixer::name(), DeclareAfterOpeningTagFixer::name(), @@ -53,6 +57,7 @@ public static function isUnwanted(string $name): bool NoNullableBooleanTypeFixer::name(), NoReferenceInFunctionDefinitionFixer::name(), PhpdocOnlyAllowedAnnotationsFixer::name(), + PhpdocTagNoNamedArgumentsFixer::name(), PhpdocVarAnnotationToAssertFixer::name(), PromotedConstructorPropertyFixer::name(), ReadonlyPromotedPropertiesFixer::name(), From 882f902bf89f34b93f930e9d077646646a54eb3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Stasicki?= Date: Thu, 12 Jun 2025 16:22:29 +0200 Subject: [PATCH 3/6] Replace php-cs-fixer/shim with friendsofphp/php-cs-fixer --- composer.json | 6 +-- src/Unwanted.php | 99 +++++++++++++++++++++++++++--------------------- 2 files changed, 58 insertions(+), 47 deletions(-) diff --git a/composer.json b/composer.json index 4a8431c..db6d596 100644 --- a/composer.json +++ b/composer.json @@ -6,7 +6,7 @@ "require": { "php": "^7.4 || ^8.0", "kubawerlos/php-cs-fixer-custom-fixers": "^3.16.2", - "php-cs-fixer/shim": "^3.22" + "friendsofphp/php-cs-fixer": "^3.22" }, "require-dev": { "phpunit/phpunit": "^9.6.11", @@ -28,10 +28,8 @@ ], "verify": [ "php-cs-fixer fix -vvv --diff --dry-run", - "mkdir -p ./var", - "@composer require friendsofphp/php-cs-fixer --no-interaction --working-dir=./var", "psalm --no-progress --shepherd", - "phpunit --bootstrap=./var/vendor/autoload.php --no-configuration ./tests" + "phpunit --no-configuration ./tests" ] } } diff --git a/src/Unwanted.php b/src/Unwanted.php index 82b4a77..3563f06 100644 --- a/src/Unwanted.php +++ b/src/Unwanted.php @@ -4,6 +4,7 @@ namespace Tpay\CodingStandards; +use PhpCsFixerCustomFixers\Fixer\AbstractFixer; use PhpCsFixerCustomFixers\Fixer\ConstructorEmptyBracesFixer; use PhpCsFixerCustomFixers\Fixer\DeclareAfterOpeningTagFixer; use PhpCsFixerCustomFixers\Fixer\EmptyFunctionBodyFixer; @@ -11,59 +12,71 @@ use PhpCsFixerCustomFixers\Fixer\NoNullableBooleanTypeFixer; use PhpCsFixerCustomFixers\Fixer\NoReferenceInFunctionDefinitionFixer; use PhpCsFixerCustomFixers\Fixer\PhpdocOnlyAllowedAnnotationsFixer; -use PhpCsFixerCustomFixers\Fixer\PhpdocTagNoNamedArgumentsFixer; use PhpCsFixerCustomFixers\Fixer\PhpdocVarAnnotationToAssertFixer; use PhpCsFixerCustomFixers\Fixer\PromotedConstructorPropertyFixer; use PhpCsFixerCustomFixers\Fixer\ReadonlyPromotedPropertiesFixer; -use PhpCsFixerCustomFixers\Fixer\TypedClassConstantFixer; final class Unwanted { public static function isUnwanted(string $name): bool { + /** @var list $unwanted */ + $unwanted = [ + 'braces', + 'combine_consecutive_issets', + 'combine_consecutive_unsets', + 'date_time_immutable', + 'final_class', + 'general_phpdoc_annotation_remove', + 'group_import', + 'heredoc_indentation', + 'mb_str_functions', + 'no_blank_lines_before_namespace', + 'not_operator_with_space', + 'not_operator_with_successor_space', + 'octal_notation', + 'php_unit_attributes', + 'php_unit_internal_class', + 'php_unit_size_class', + 'php_unit_strict', + 'php_unit_test_class_requires_covers', + 'phpdoc_summary', + 'phpdoc_to_property_type', + 'phpdoc_to_return_type', + 'single_line_comment_spacing', + 'single_line_throw', + 'strict_param', + 'string_implicit_backslashes', + 'void_return', + + ConstructorEmptyBracesFixer::name(), + DeclareAfterOpeningTagFixer::name(), + EmptyFunctionBodyFixer::name(), + NoImportFromGlobalNamespaceFixer::name(), + NoNullableBooleanTypeFixer::name(), + NoReferenceInFunctionDefinitionFixer::name(), + PhpdocOnlyAllowedAnnotationsFixer::name(), + PhpdocVarAnnotationToAssertFixer::name(), + PromotedConstructorPropertyFixer::name(), + ReadonlyPromotedPropertiesFixer::name(), + ]; + + $fixersRequiredIfExists = [ + 'PhpCsFixerCustomFixers\\Fixer\\PhpdocTagNoNamedArgumentsFixer', + 'PhpCsFixerCustomFixers\\Fixer\\TypedClassConstantFixer', + ]; + + while ($fixerClass = array_shift($fixersRequiredIfExists)) { + if (class_exists($fixerClass) && is_a($fixerClass, AbstractFixer::class, true)) { + $fixerName = $fixerClass::name(); + $unwanted[] = $fixerName; + } + } + return in_array( $name, - [ - 'braces', - 'combine_consecutive_issets', - 'combine_consecutive_unsets', - 'date_time_immutable', - 'final_class', - 'general_phpdoc_annotation_remove', - 'group_import', - 'heredoc_indentation', - 'mb_str_functions', - 'no_blank_lines_before_namespace', - 'not_operator_with_space', - 'not_operator_with_successor_space', - 'octal_notation', - 'php_unit_attributes', - 'php_unit_internal_class', - 'php_unit_size_class', - 'php_unit_strict', - 'php_unit_test_class_requires_covers', - 'phpdoc_summary', - 'phpdoc_to_property_type', - 'phpdoc_to_return_type', - 'single_line_comment_spacing', - 'single_line_throw', - 'strict_param', - 'string_implicit_backslashes', - 'void_return', - ConstructorEmptyBracesFixer::name(), - DeclareAfterOpeningTagFixer::name(), - EmptyFunctionBodyFixer::name(), - NoImportFromGlobalNamespaceFixer::name(), - NoNullableBooleanTypeFixer::name(), - NoReferenceInFunctionDefinitionFixer::name(), - PhpdocOnlyAllowedAnnotationsFixer::name(), - PhpdocTagNoNamedArgumentsFixer::name(), - PhpdocVarAnnotationToAssertFixer::name(), - PromotedConstructorPropertyFixer::name(), - ReadonlyPromotedPropertiesFixer::name(), - TypedClassConstantFixer::name(), - ], - true, + $unwanted, + true ); } } From 7805efded8ccd8356cbd6d07eb7e14bb8bbbd479 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Stasicki?= Date: Thu, 12 Jun 2025 16:27:56 +0200 Subject: [PATCH 4/6] Update Psalm autoload path to vendor/autoload.php --- psalm.xml | 2 +- src/Unwanted.php | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/psalm.xml b/psalm.xml index cb48cdf..d00d7aa 100644 --- a/psalm.xml +++ b/psalm.xml @@ -6,7 +6,7 @@ xsi:schemaLocation='https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd' findUnusedBaselineEntry='true' findUnusedCode='false' - autoloader='./var/vendor/autoload.php' + autoloader='vendor/autoload.php' > diff --git a/src/Unwanted.php b/src/Unwanted.php index 3563f06..ae374f7 100644 --- a/src/Unwanted.php +++ b/src/Unwanted.php @@ -61,14 +61,14 @@ public static function isUnwanted(string $name): bool ReadonlyPromotedPropertiesFixer::name(), ]; - $fixersRequiredIfExists = [ + $unwantedIfExists = [ 'PhpCsFixerCustomFixers\\Fixer\\PhpdocTagNoNamedArgumentsFixer', 'PhpCsFixerCustomFixers\\Fixer\\TypedClassConstantFixer', ]; - while ($fixerClass = array_shift($fixersRequiredIfExists)) { - if (class_exists($fixerClass) && is_a($fixerClass, AbstractFixer::class, true)) { - $fixerName = $fixerClass::name(); + while ($class = array_shift($unwantedIfExists)) { + if (class_exists($class) && is_a($class, AbstractFixer::class, true)) { + $fixerName = $class::name(); $unwanted[] = $fixerName; } } From 9148265e2401ce697705b300e53d031f293bccda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Stasicki?= Date: Thu, 12 Jun 2025 16:40:25 +0200 Subject: [PATCH 5/6] Replace all name() calls with hardcoded fixer names --- src/Unwanted.php | 105 +++++++++++++++++------------------------------ 1 file changed, 38 insertions(+), 67 deletions(-) diff --git a/src/Unwanted.php b/src/Unwanted.php index ae374f7..e91883b 100644 --- a/src/Unwanted.php +++ b/src/Unwanted.php @@ -4,79 +4,50 @@ namespace Tpay\CodingStandards; -use PhpCsFixerCustomFixers\Fixer\AbstractFixer; -use PhpCsFixerCustomFixers\Fixer\ConstructorEmptyBracesFixer; -use PhpCsFixerCustomFixers\Fixer\DeclareAfterOpeningTagFixer; -use PhpCsFixerCustomFixers\Fixer\EmptyFunctionBodyFixer; -use PhpCsFixerCustomFixers\Fixer\NoImportFromGlobalNamespaceFixer; -use PhpCsFixerCustomFixers\Fixer\NoNullableBooleanTypeFixer; -use PhpCsFixerCustomFixers\Fixer\NoReferenceInFunctionDefinitionFixer; -use PhpCsFixerCustomFixers\Fixer\PhpdocOnlyAllowedAnnotationsFixer; -use PhpCsFixerCustomFixers\Fixer\PhpdocVarAnnotationToAssertFixer; -use PhpCsFixerCustomFixers\Fixer\PromotedConstructorPropertyFixer; -use PhpCsFixerCustomFixers\Fixer\ReadonlyPromotedPropertiesFixer; - final class Unwanted { public static function isUnwanted(string $name): bool { - /** @var list $unwanted */ - $unwanted = [ - 'braces', - 'combine_consecutive_issets', - 'combine_consecutive_unsets', - 'date_time_immutable', - 'final_class', - 'general_phpdoc_annotation_remove', - 'group_import', - 'heredoc_indentation', - 'mb_str_functions', - 'no_blank_lines_before_namespace', - 'not_operator_with_space', - 'not_operator_with_successor_space', - 'octal_notation', - 'php_unit_attributes', - 'php_unit_internal_class', - 'php_unit_size_class', - 'php_unit_strict', - 'php_unit_test_class_requires_covers', - 'phpdoc_summary', - 'phpdoc_to_property_type', - 'phpdoc_to_return_type', - 'single_line_comment_spacing', - 'single_line_throw', - 'strict_param', - 'string_implicit_backslashes', - 'void_return', - - ConstructorEmptyBracesFixer::name(), - DeclareAfterOpeningTagFixer::name(), - EmptyFunctionBodyFixer::name(), - NoImportFromGlobalNamespaceFixer::name(), - NoNullableBooleanTypeFixer::name(), - NoReferenceInFunctionDefinitionFixer::name(), - PhpdocOnlyAllowedAnnotationsFixer::name(), - PhpdocVarAnnotationToAssertFixer::name(), - PromotedConstructorPropertyFixer::name(), - ReadonlyPromotedPropertiesFixer::name(), - ]; - - $unwantedIfExists = [ - 'PhpCsFixerCustomFixers\\Fixer\\PhpdocTagNoNamedArgumentsFixer', - 'PhpCsFixerCustomFixers\\Fixer\\TypedClassConstantFixer', - ]; - - while ($class = array_shift($unwantedIfExists)) { - if (class_exists($class) && is_a($class, AbstractFixer::class, true)) { - $fixerName = $class::name(); - $unwanted[] = $fixerName; - } - } - return in_array( $name, - $unwanted, - true + [ + 'braces', + 'combine_consecutive_issets', + 'combine_consecutive_unsets', + 'date_time_immutable', + 'final_class', + 'general_phpdoc_annotation_remove', + 'group_import', + 'heredoc_indentation', + 'mb_str_functions', + 'no_blank_lines_before_namespace', + 'not_operator_with_space', + 'not_operator_with_successor_space', + 'octal_notation', + 'php_unit_internal_class', + 'php_unit_size_class', + 'php_unit_strict', + 'php_unit_test_class_requires_covers', + 'phpdoc_summary', + 'phpdoc_to_property_type', + 'single_line_comment_spacing', + 'single_line_throw', + 'strict_param', + 'void_return', + 'PhpCsFixerCustomFixers/constructor_empty_braces', + 'PhpCsFixerCustomFixers/declare_after_opening_tag', + 'PhpCsFixerCustomFixers/empty_function_body', + 'PhpCsFixerCustomFixers/no_import_from_global_namespace', + 'PhpCsFixerCustomFixers/no_nullable_boolean_type', + 'PhpCsFixerCustomFixers/no_reference_in_function_definition', + 'PhpCsFixerCustomFixers/phpdoc_only_allowed_annotations', + 'PhpCsFixerCustomFixers/phpdoc_var_annotation_to_assert', + 'PhpCsFixerCustomFixers/promoted_constructor_property', + 'PhpCsFixerCustomFixers/readonly_promoted_properties', + 'PhpCsFixerCustomFixers/phpdoc_tag_no_named_arguments', + 'PhpCsFixerCustomFixers/typed_class_constant', + ], + true, ); } } From 6cce98fec5591ab3690cdbdd042d0b9825ff4377 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Stasicki?= Date: Thu, 12 Jun 2025 16:46:01 +0200 Subject: [PATCH 6/6] Add fixers for backward compatibility --- src/Unwanted.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Unwanted.php b/src/Unwanted.php index e91883b..56a87b0 100644 --- a/src/Unwanted.php +++ b/src/Unwanted.php @@ -24,14 +24,17 @@ public static function isUnwanted(string $name): bool 'not_operator_with_space', 'not_operator_with_successor_space', 'octal_notation', + 'php_unit_attributes', 'php_unit_internal_class', 'php_unit_size_class', 'php_unit_strict', 'php_unit_test_class_requires_covers', 'phpdoc_summary', 'phpdoc_to_property_type', + 'phpdoc_to_return_type', 'single_line_comment_spacing', 'single_line_throw', + 'string_implicit_backslashes', 'strict_param', 'void_return', 'PhpCsFixerCustomFixers/constructor_empty_braces',