Download the PHP package techno-artisan/phpstan-strict-rules without Composer
On this page you can find all versions of the php package techno-artisan/phpstan-strict-rules. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download techno-artisan/phpstan-strict-rules
More information about techno-artisan/phpstan-strict-rules
Files in techno-artisan/phpstan-strict-rules
Package phpstan-strict-rules
Short Description Additional strict rules for PHPStan.
License MIT
Informations about the package phpstan-strict-rules
techno-artisan/phpstan-strict-rules
Uncompromising, purely-syntactic PHPStan rules — because loose semantics hide bugs.
A small set of additional, deliberately strict rules for PHPStan.
Every line below passes vanilla PHPStan at level: max — and is reported here:
Why this package?
- Purely syntactic. The rules inspect the AST, not inferred types — so they fire predictably on every occurrence, with no type-inference guesswork.
- Uncompromising. No configuration, no opt-outs: a construct is either allowed or it isn't.
- One thesis. Loose semantics hide bugs — loose
empty(), loose array searches and loose==comparisons are all reported, alongside untyped class constants. - Strict with itself. Enforced in CI: 100 % line coverage, 100 % mutation score
(MSI), and the suite runs against both the lowest and highest supported PHPStan
^2.2release. A rule that isn't bulletproof doesn't ship. See Quality.
Relationship to phpstan/phpstan-strict-rules
phpstan/phpstan-strict-rules is
broader and excellent — if you don't already use it, you probably should. Three of the
four rules here overlap with rules it enables by default:
| Construct | phpstan-strict-rules | this package |
|---|---|---|
empty() |
bans all (DisallowedEmptyRule) |
bans all |
== / != / <> |
bans all (DisallowedLooseComparisonRule) |
bans all |
in_array / array_search / array_keys w/o $strict |
type-aware, plus base64_decode (StrictFunctionCallsRule) |
purely syntactic — requires the literal true |
| Untyped class constants | — (no equivalent) | TypedClassConstantRule |
What this package adds on top:
TypedClassConstantRule— strict-rules has no equivalent.- A purely syntactic loose-array-search check. Because it never consults inferred
types, it also flags
in_array($x, $list, $flag)when$flagis only inferred to betrue— predictable, no guesswork. (strict-rules is type-aware and additionally coversbase64_decode.)
The empty() and == rules are included so this package stands on its own. If you run
both packages, those two report the same lines twice — disable them on one side:
(or ignore the technoArtisan.* identifiers from this package instead).
Installation
Usage
If you use phpstan/extension-installer,
the rules are registered automatically — nothing else to do.
Otherwise, include the rule set manually in your phpstan.neon:
Rules
| Rule | Reports | Identifier |
|---|---|---|
TypedClassConstantRule |
Class constants declared without a native type | technoArtisan.typedClassConstant |
DisallowEmptyConstructRule |
The empty() language construct |
technoArtisan.disallowedEmpty |
DisallowLooseInArrayRule |
in_array() / array_search() / array_keys() without $strict |
technoArtisan.looseInArray |
DisallowLooseComparisonRule |
The ==, != and <> operators |
technoArtisan.looseComparison |
Typed class constants — TypedClassConstantRule
A class constant without a native type leaves its type implicit. Declare it.
Identifier: technoArtisan.typedClassConstant
Loose empty() — DisallowEmptyConstructRule
empty() treats 0, 0.0, "0", "", [], null and false alike, so it
silently swallows values you may care about. Use an explicit strict check.
Identifier: technoArtisan.disallowedEmpty
Loose array search — DisallowLooseInArrayRule
in_array(), array_search() and array_keys() compare loosely unless you pass
true as the $strict argument, so they coerce types and hide bugs.
Identifier: technoArtisan.looseInArray
Loose comparison — DisallowLooseComparisonRule
==, != and <> coerce their operands' types and hide bugs. Use === / !==.
Identifier: technoArtisan.looseComparison
Ignoring a rule
Every error carries a stable identifier (shown above), so you can suppress a single occurrence with an ignore comment:
…or ignore it project-wide via ignoreErrors in phpstan.neon or a generated
baseline. Because the rules are uncompromising by design, prefer fixing the code
over ignoring it.
Requirements
- PHP
^8.5 - PHPStan
^2.2
Quality
This package is strict with itself. Every release is gated in CI:
- 100 % line coverage of
src/, enforced bycomposer coverage:check. - 100 % mutation score (MSI) via Infection — covered-MSI is 100 % too. A rule whose tests don't kill every mutant doesn't ship.
- lowest + highest matrix — the suite runs against both the oldest and newest
supported PHPStan
^2.2release, so the rules can't quietly break on either end. - Config hygiene —
composer.jsonstays normalized andrules.neon/phpstan.neonare lint-clean.
These same gates run locally — see Development.
Development
License
MIT — see LICENSE.