Skip to content

Released PHPStan Rules 14.11

Latest

Choose a tag to compare

@TomasVotruba TomasVotruba released this 09 Jun 21:56
· 1 commit to main since this release

What's Changed

Merged symplify/phpstan-extensions into this package (#270)

symplify/phpstan-extensions had only a few classes, so it now lives here. This brings:

  • Return type extensions (in config/phpstan-extensions.neon, all opt-in, off by default):
    • Symfony Container::get($id) resolved to the $id type, and Finder SplFileInfo::getRealPath() resolved to string
    • Laravel Container::make($id) resolved to the $id type
    • Native getcwd() / dirname() / realpath() resolved to string
  • SymplifyErrorFormatter — a compact error formatter, usable via errorFormat: symplify

New rules

  • NewOverSettersRule ported from tomasvotruba/ctor — opt-in via ctor: true (#267)
  • PHPUnit mock rules merged from rector/mockstan — opt-in via mocks: true (#268)

New parameters

Parameter Default What it enables
ctor false NewOverSettersRule + its collector — flags new followed by setter calls that should be constructor arguments (#267)
mocks false PHPUnit mock rules from rector/mockstan (#268)
symfonyReturnType false Symfony Container::get() and Finder SplFileInfo::getRealPath() return type extensions (#270)
laravelReturnType false Laravel Container::make() return type extension (#270)
pathStrings false getcwd() / dirname() / realpath() always-string return type extension (#270)

Example phpstan.neon

All of the above ship in the package and are auto-loaded by phpstan/extension-installer
you only flip the parameters. The topic rule sets (Doctrine, naming, Symfony, …) stay opt-in
via includes:.

# phpstan.neon
includes:
    # opt-in topic rule sets (optional)
    - vendor/symplify/phpstan-rules/config/symplify-rules.neon
    - vendor/symplify/phpstan-rules/config/naming-rules.neon
    - vendor/symplify/phpstan-rules/config/doctrine-rules.neon
    - vendor/symplify/phpstan-rules/config/symfony-rules.neon

parameters:
    # opt-in rules
    ctor: true               # NewOverSettersRule
    mocks: true              # PHPUnit mock rules

    # opt-in return type extensions
    symfonyReturnType: true  # Container::get() + Finder SplFileInfo::getRealPath()
    laravelReturnType: true  # Container::make()
    pathStrings: true        # getcwd()/dirname()/realpath() => string

Run with the bundled error formatter:

vendor/bin/phpstan analyse --error-format symplify

Improvements

  • Bump to PHP 8.4 (#271)
  • Add CLAUDE.md with project metadata (#269)
  • Document missing PHPStan rules in README with examples
  • Remove Rector-specific rules section from README

Full Changelog: 14.10.0...14.11.0