Download the PHP package steevanb/phpstan-rules without Composer
On this page you can find all versions of the php package steevanb/phpstan-rules. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download steevanb/phpstan-rules
More information about steevanb/phpstan-rules
Files in steevanb/phpstan-rules
Package phpstan-rules
Short Description PHPStan rules: unnecessary named arguments, one mirrored coverage target per test, no class constants in tests
License Apache-2.0
Informations about the package phpstan-rules
steevanb/phpstan-rules
PHPStan rules:
| Rule | Identifier(s) | Purpose |
|---|---|---|
DisallowUnnecessaryNamedArgumentsRule |
steevanb.unnecessaryNamedArguments |
A named argument that could be passed positionally is reported |
CoverageTargetRule |
steevanb.singleCoverageTarget, steevanb.mirroredCoverageTarget |
A test class covers a single class or trait, the one it mirrors |
DisallowConstantsInTestsExtension |
steevanb.disallowConstantsInTests |
A TestCase uses literal values, not constants of the tested code |
Installation
With phpstan/extension-installer, the rules are registered
automatically. Otherwise, include extension.neon in your PHPStan configuration:
Configuration
Every parameter is optional:
Rules
DisallowUnnecessaryNamedArgumentsRule
Named arguments are only useful to skip optional parameters. When the named arguments of a call could be passed positionally (they directly follow the positional arguments, in the order of the parameters), they are reported.
Method calls, nullsafe method calls, static calls, function calls, new and attributes are checked. Calls using
argument unpacking (...$arguments), first-class callables and calls whose callee can't be resolved are ignored.
CoverageTargetRule
A class declaring several #[CoversClass] / #[CoversTrait] attributes is reported: a test class covers a single
class or a single trait.
When testNamespacePrefixes and targetNamespacePrefixes are configured, the covered class must be the one the test
class mirrors: with the configuration above, App\Tests\Unit\Foo\BarTest must cover App\Tests\Foo\Bar or
App\Foo\Bar. Classes outside of testNamespacePrefixes or without the Test suffix are not checked.
DisallowConstantsInTestsExtension
Inside a PHPUnit\Framework\TestCase subclass, using a class constant of the tested code is reported: a test asserts
literal values, so that changing the value of a constant breaks the test.
Enum cases and constants declared in testsDirectories stay allowed.
Development
All the tooling runs inside a single Docker container (ghcr.io/steevanb/phpstan-rules:ci, built from docker/ci/),
through the Python wrappers of steevanb/python-devops in bin/.
Each wrapper re-runs itself in a docker run of this image, so the host needs only Python 3.10+ and Docker.
steevanb/python-devops is a private repository, declared as a vcs entry in composer.json. Composer needs a GitHub
token (classic, repo scope) in ~/.config/composer/auth.json to install it:
composer.lock is not committed, so bin/ci/start.py mounts this file in the container to install the dependencies.
CI
The GitHub Actions workflow (.github/workflows/ci.yml) runs bin/ci/start.py then bin/ci/validate.py on every
push. It needs a GHCR_TOKEN Actions secret, a classic token with the read:packages (pull
ghcr.io/steevanb/phpstan-rules:ci) and repo (install steevanb/python-devops) scopes:
https://github.com/steevanb/phpstan-rules/settings/secrets/actions