Huge release!
Auto-fixable rules with --fix. They show up in the on-line playground too:
Stale ignoreErrors entries and @phpstan-ignore comments can be removed with --fix too:
Extensions can be registered with attributes instead of .neon file:
use PHPStan\DependencyInjection\AutowiredService;
#[AutowiredService]
class MyExtension implements DynamicMethodReturnTypeExtension
Services be migrated automatically with migrate:neon2attributes.
Major new features 🚀
- Support for auto-fixable custom rules
analysecommand now supports--fixand even--fix-ignored(looks at your ignored auto-fixable errors and fixes them too)- Auto-fixable errors are marked with 🔧 in the default table output
- Rules can change AST with
RuleErrorBuilder::fixNode()andremoveNode(). Learn more - After first round of fixes, PHPStan reanalyses the whole codebase again (which is fast thanks to the result cache) and looks if the first round of fixes produced more errors to fix. It ends after 10 rounds in case the fixes cannot agree about the final state of the code.
- This is a good fit for "coding standard rules", for example if you want to enforce final classes, named arguments etc.
- It's not a good fit for errors that have multiple possible fixes (most of PHPStan errors do), like type-related errors. PHPStan cannot know whether the accepting or accepted side should correct its type.
- Selected errors reported by PHPStan are now autofixable
- All unmatched
ignoreErrorsentries in the config file and baseline can now be removed by running PHPStan with--fix(#6906, #6907, #6909) - Works for unmatched
@phpstan-ignorecomments too backtick.deprecatedcast.uselessmethod.missingOverridemethod.overrideproperty.missingOverrideproperty.overridephpunit.assertCountphpunit.assertEmptyphpunit.assertEqualsphpunit.assertFalsephpunit.assertNullphpunit.assertTruephpunit.dataProviderStatic
- All unmatched
- Extensions can be registered with attributes on PHP 8.0+ (#6918), #15114
- Instead of registering services in neon file, you can now use PHP attributes above classes to register them
#[AutowiredService],#[NonAutowiredService],#[AutowiredParameter],#[RegisteredRule],#[RegisteredCollector],#[Conditional],#[GenerateFactory],#[ExtensionInterface]- [Learn mor
