CLAUDE.md
website/errors/CLAUDE.mdCLAUDE.md
Quality
77/100
Scores the file, not the repository.Length
1,089 words
18 headings · 4 code blocksRepository
14k
— · pushed 0 days agoLast changed
3 days ago
First indexed 3 days ago.1# PHPStan Error Identifier Documentation23This directory contains markdown documentation files for PHPStan error identifiers. Each file explains what a specific error means, shows a triggering code example, and offers ways to fix it.45## How these files are generated67Files are generated by a GitHub Actions workflow (`.github/workflows/generate-error-docs.md`) that uses Claude to:891. Read `website/src/errorsIdentifiers.json` which maps each identifier to its rule classes and source code locations102. Pick undocumented identifiers (ones without a corresponding `.md` file here)113. Clone referenced PHPStan repositories (`phpstan-src`, `phpstan-strict-rules`, `phpstan-doctrine`, etc.)124. Research each identifier by reading rule source code and test fixtures135. Generate a markdown file for each identifier1415## File format1617Each file follows this exact structure:1819```markdown20---21title: "<identifier>"22shortDescription: "One sentence describing when this error is reported."23ignorable: true24---2526## Code example2728` ``php29<?php declare(strict_types = 1);3031// Minimal PHP code that triggers this error32` ``3334## Why is it reported?3536Explanation from PHP language perspective.3738## How to fix it3940Ways to fix the error.41```4243### Frontmatter4445- `title`: The error identifier (e.g., `"property.notFound"`)46- `shortDescription`: One sentence (ending with a period) describing when the error is reported. Written from a user's perspective — what code pattern causes PHPStan to report this error. Examples: `"Accessing a private property from outside the declaring class."`, `"Loose comparison using == will always evaluate to true."`, `"Pure function uses print, which produces output as a side effect."`47- `ignorable`: `true` for most identifiers. Set to `false` for identifiers that use `->nonIgnorable()` in the rule builder chain, or that start with `phpstan.` or `phpstanPlayground.`4849### Code example5051- Must be valid PHP that triggers the identifier52- Starts with `<?php declare(strict_types = 1);`53- Uses `php` language tag54- Keep it minimal — remove unrelated classes, simplify names55- Prefer real code from test fixtures when possible5657### "Why is it reported?" section5859- Explain PHP language semantics, not PHPStan internals60- PHPStan points to code that causes crashes, doesn't execute at all, or doesn't do what the developer probably intended61- Be concise and technically precise62- List multiple reasons if applicable63- If the rule's `->tip()` links to a blog post on phpstan.org, mention it: `Learn more: [Blog post title](/blog/post-slug)`6465### "How to fix it" section6667- Offer multiple ways to fix when applicable68- Use `diff-php` syntax for code changes69- Prefer fixes in this order:70 1. Fix the actual bug71 2. Narrow the type using native PHP type declarations72 3. Narrow the type using PHPDoc types (`@param`, `@return`, `@var` on properties)73 4. Use [type narrowing](/writing-php-code/narrowing-types) in the function body74 5. Configure PHPStan if the rule is configurable75- When the error involves a PHP language feature only available in newer PHP versions, mention the PHPDoc-based alternative that works on older versions too. For example: native return type `never` (PHP 8.1+) can be replaced with `@return never`, native union types (PHP 8.0+) can be expressed as PHPDoc union types, native intersection types (PHP 8.1+) can be expressed as PHPDoc intersection types, standalone types like `true`/`false`/`null` (PHP 8.2+) can be written in PHPDoc. Link to [PHPDoc Basics](/writing-php-code/phpdocs-basics) and [PHPDoc Types](/writing-php-code/phpdoc-types) where relevant.76- Every time a configuration parameter is mentioned, link it to the correct documentation page. Consult `website/src/config-reference.md` to find the right anchor — parameters that have their own `###` heading (like `phpVersion`) link to `/config-reference#phpversion`. Parameters that only appear as "Related config keys" link to the user guide page referenced there (e.g., `reportUnmatchedIgnoredErrors` links to `/user-guide/ignoring-errors#reporting-unused-ignores`, `scanFiles` links to `/user-guide/discovering-symbols#third-party-code-outside-of-composer-dependencies`).77- Show code fixes. Use `diff-php` syntax when showing changes:7879```markdown80```diff-php81- $value = $this->getValue();82+ $value = (string) $this->getValue();83```84```8586### Do NOT8788- Suggest using `assert()` for type narrowing89- Suggest throwing an exception to narrow types90- Suggest using inline `@var` PHPDoc tag91- Suggest ignoring the error (the detail page already covers that)92- Use emojis or first person9394## Identifier prefix reference9596Some prefixes are non-obvious because they come from `ClassNameUsageLocation`:9798| Prefix | PHP Feature |99|--------|-------------|100| `assert` | `@phpstan-assert` PHPDoc tag (NOT `assert()` function) |101| `attribute` | PHP 8.0+ attributes `#[AttributeName]` |102| `catch` | `catch (ExceptionClass $e)` blocks |103| `classConstant` | `ClassName::CONSTANT` access |104| `instanceof` | `$x instanceof ClassName` expressions |105| `methodTag` | `@method` PHPDoc tag |106| `mixin` | `@mixin` PHPDoc tag |107| `new` | `new ClassName()` instantiation |108| `parameter` | Native type declaration on function/method parameter |109| `property` | Native type declaration on class property (e.g., `private Foo $bar`) |110| `propertyTag` | `@property` PHPDoc tag |111| `requireExtends` | `@phpstan-require-extends` PHPDoc tag |112| `requireImplements` | `@phpstan-require-implements` PHPDoc tag |113| `return` | Native return type declaration |114| `sealed` | `@phpstan-sealed` PHPDoc tag |115| `selfOut` | `@phpstan-self-out` PHPDoc tag |116| `staticMethod` | `ClassName::method()` static method calls |117| `staticProperty` | `ClassName::$property` static property access |118| `traitUse` | `use TraitName` in a class body |119| `typeAlias` | PHPStan type alias references |120| `varTag` | `@var` PHPDoc tag |121122### Prefixes with special identifier format123124| Prefix pattern | PHP Feature |125|----------------|-------------|126| `class.extends*` | `class Foo extends ParentClass` |127| `class.implements*` | `class Foo implements Interface` |128| `enum.implements*` | `enum Foo implements Interface` |129| `interface.extends*` | `interface Foo extends OtherInterface` |130| `generics.*Bound` | `@template T of BoundClass` bound constraint |131| `generics.*Default` | `@template T = DefaultClass` default value |132133## Tone and style134135- Concise, technically precise, no filler words136- Match existing phpstan.org documentation style137- Direct and practical138- For extension-specific identifiers (phpstan-doctrine, phpstan-symfony, etc.), mention which extension package provides the rule139140## Example141142For `website/errors/deadCode.unreachable.md`:143144```markdown145---146title: "deadCode.unreachable"147shortDescription: "Code after a return, throw, or other terminating statement can never be executed."148ignorable: true149---150151## Code example152153` ``php154<?php declare(strict_types = 1);155156function doFoo(): int157{158 return 1;159 echo 'unreachable';160}161` ``162163## Why is it reported?164165The statement after `return` can never be executed. The `return` statement unconditionally transfers control out of the function, making any code following it in the same block dead code. This usually indicates a logic error or leftover code from refactoring.166167## How to fix it168169Remove the unreachable code:170171` ``diff-php172 function doFoo(): int173 {174 return 1;175- echo 'unreachable';176 }177` ``178179If the code should execute, restructure the logic so it runs before the return:180181` ``diff-php182 function doFoo(): int183 {184+ echo 'this should run';185 return 1;186- echo 'unreachable';187 }188` ``189```190
Also in phpstan/phpstan
Diff this repo’s formatsOne repository carrying more than one format is the comparison this product exists for: does anyone actually write different content in each file, or is one a copy of the other?
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| phpstan/phpstanCLAUDE.md · 14k | CLAUDE.md | buildarchgitdeployment | 82/100 | 3 days ago | |
| phpstan/phpstanwebsite/CLAUDE.md · 14k | CLAUDE.md | buildtestlint-formatarch+2 | 89/100 | 3 days ago | |
| phpstan/phpstanwebsite/infra/CLAUDE.md · 14k | CLAUDE.md | teststylearchdeployment | 94/100 | 3 days ago | |
| phpstan/phpstanwebsite/src/_posts/CLAUDE.md · 14k | CLAUDE.md | lint-formatstylearchtypes+1 | 74/100 | 3 days ago |
Similar configs
Same format, overlapping stack, ranked by quality.
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| Adit-Jain-srm/NightmareNetCLAUDE.md · 45 | CLAUDE.md | buildtestlint-formatstyle+6 | 100/100 | 3 days ago | |
| nimbalyst/nimbalystpackages/android/CLAUDE.md · 1.4k | CLAUDE.md | setupbuildstylearch+2 | 100/100 | 3 days ago | |
| stacklok/toolhiveCLAUDE.md · 2.0k | CLAUDE.md | buildteststylearch+4 | 100/100 | 3 days ago | |
| dotCMS/corecore-web/CLAUDE.md · 949 | CLAUDE.md | teststylearchtesting-strategy+3 | 100/100 | 3 days ago | |
| microsoft/playwrightCLAUDE.md · 94k | CLAUDE.md | buildtestlint-formatstyle+7 | 100/100 | 3 days ago | |
| filamentphp/filamentCLAUDE.md · 32k | CLAUDE.md | buildtestlint-formatstyle+7 | 100/100 | 3 days ago | |
| livewire/livewireCLAUDE.md · 24k | CLAUDE.md | setupbuildteststyle+4 | 100/100 | 3 days ago | |
| bagisto/bagistoCLAUDE.md · 28k | CLAUDE.md | setupbuildteststyle+5 | 100/100 | 3 days ago |
