Chore: Add Rector with safe rule bucket and CI refactor check#247
Chore: Add Rector with safe rule bucket and CI refactor check#247
Conversation
Introduces Rector for automated refactoring, wired up via: - rector.php config targeting src/ and tests/ with PHP 8.3 level set plus CODE_QUALITY, DEAD_CODE, EARLY_RETURN, and INSTANCEOF sets. Rules with BC risk or behavioural shifts (readonly, explicit bool compare, empty() rewrites, type-hint additions, random_int swaps) are explicitly skipped. - composer refactor / refactor:check scripts. - Checks / Refactor CI job running rector in dry-run. - Safe-bucket refactor applied across the codebase: strict_types declarations, #[\Override] attributes, str_contains / str_starts_with, null-coalescing, match over switch where safe, dead code removal, and docblock cleanup.
k6 benchmark
|
Greptile SummaryThis PR introduces Rector with a conservative PHP 8.3 rule set and applies the resulting safe refactors across Confidence Score: 5/5Safe to merge — all changes are mechanical refactors with no logic or BC impact. All findings are P2 style/completeness issues. No logic bugs, security issues, or BC breaks were found. PHPStan level 7 and the unit suite both pass. No files require special attention; the partial declare(strict_types=1) coverage is a minor follow-up item. Important Files Changed
|
Summary
rector.php) targetingsrc/andtests/, using PHP 8.3 level set plusCODE_QUALITY,DEAD_CODE,EARLY_RETURN, andINSTANCEOFrule sets. Rules with BC or behavioural risk are explicitly skipped — see config for the full list and rationale.composer refactor(apply) andcomposer refactor:check(dry-run) scripts.Checks / RefactorCI job that runs rector in dry-run on PHP 8.3.declare(strict_types=1),#[\Override],str_contains/str_starts_with, null-coalescing,match(where safe), dead-code removal, docblock cleanup.Skipped rules (worth revisiting in follow-ups)
ReadOnlyPropertyRector/ReadOnlyClassRector— BC break for library consumers.ExplicitBoolCompareRector,SimplifyEmptyCheckOnEmptyArrayRector,DisallowedEmptyRuleFixerRector— change truthy/empty semantics for"0",null,"".TypedPropertyFromAssignsRector,TypedPropertyFromStrictConstructorRector,ParamTypeByParentCallTypeRector,NullToStrictStringFuncCallArgRector— can throwTypeErroron previously-working callers.ClassPropertyAssignToConstructorPromotionRector,RestoreDefaultNullToNullableTypePropertyRector— shape/reflection changes.RandomFunctionRector— different distribution and failure mode.RecastingRemovalRector,FlipTypeControlToUseExclusiveTypeRector,SwitchNegatedTernaryRector,StringClassNameToClassConstantRector— subtle casting / control-flow shifts; apply manually.Test plan
composer formatcleancomposer analyze(PHPStan level 7) cleancomposer testunit suite passes (84 tests, 248 assertions)Checks / Refactorjob green