Skip to content

Commit 8c93f7b

Browse files
imorlandclaude
andauthored
docs: document PHPStan 2.x and Larastan 3.x upgrade changes (#503)
Adds a detailed PHPStan/Larastan section to the 2.x upgrade guide covering the version bumps, recommended level 6 increase, removed config parameters, and Larastan 3.x breaking changes (explicit relation generics, annotation renames). Updates the static-code-analysis setup guide to reflect level 6 and remove the now-invalid checkMissingIterableValueType parameter. Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 5355e42 commit 8c93f7b

2 files changed

Lines changed: 60 additions & 3 deletions

File tree

docs/extend/static-code-analysis.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,12 @@ includes:
2929
- vendor/flarum/phpstan/extension.neon
3030
3131
parameters:
32-
# The level will be increased in Flarum 2.0
33-
level: 5
32+
level: 6
3433
paths:
3534
- src
3635
- extend.php
3736
excludePaths:
3837
- *.blade.php
39-
checkMissingIterableValueType: false
4038
databaseMigrationsPath: ['migrations']
4139
```
4240

docs/extend/update-2_0.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,65 @@ Checkout this example from the mentions extension:
371371

372372
## Infrastructure
373373

374+
### PHPStan (updated from ^1.10 to ^2.1) and Larastan (updated from 2.9 to ^3.8)
375+
376+
Flarum 2.0 upgrades its static analysis tooling to PHPStan 2.x and Larastan 3.x. Extensions using `flarum/phpstan` will need to update their configuration and may need to fix newly reported errors.
377+
378+
#### flarum/phpstan dependency
379+
380+
Update your `composer.json` to require the latest `flarum/phpstan`:
381+
382+
```bash
383+
composer require --dev flarum/phpstan:^2.0
384+
```
385+
386+
#### Recommended level increase
387+
388+
Flarum core now runs PHPStan at **level 6**. We recommend all extensions do the same. Update your `phpstan.neon`:
389+
390+
```neon
391+
parameters:
392+
level: 6
393+
```
394+
395+
Level 6 checks for missing return types on all methods and properties. You may encounter new errors on your first run after increasing the level — work through them incrementally.
396+
397+
#### Removed config parameters
398+
399+
PHPStan 2.x removed several parameters that were commonly used in Flarum extension configs. Remove these from your `phpstan.neon` if present — they will cause an error if left in:
400+
401+
* `checkMissingIterableValueType` — replaced by the `missingType.iterableValue` error identifier. If you need to suppress these errors, use `ignoreErrors` with the identifier instead.
402+
* `checkGenericClassInNonGenericObjectType` — replaced by `missingType.generics`.
403+
* `checkAlwaysTrueCheckTypeFunctionCall`, `checkAlwaysTrueInstanceof`, `checkAlwaysTrueStrictComparison`, `checkAlwaysTrueLooseComparison` — these checks are now always enabled and can no longer be disabled.
404+
405+
#### Larastan 3.x: explicit relation return types required
406+
407+
Larastan 3.x no longer infers generic types for Eloquent relation methods by parsing the method body. You must now annotate return types explicitly:
408+
409+
```php
410+
// Before (Larastan 2.x would infer the generic type automatically)
411+
public function posts(): HasMany
412+
{
413+
return $this->hasMany(Post::class);
414+
}
415+
416+
// After (explicit generic annotation required)
417+
/** @return HasMany<Post, $this> */
418+
public function posts(): HasMany
419+
{
420+
return $this->hasMany(Post::class);
421+
}
422+
```
423+
424+
A [Rector rule](https://github.com/larastan/larastan/blob/3.x/UPGRADE.md) is available to automate this migration.
425+
426+
#### Larastan 3.x: template annotation renames
427+
428+
If your extension uses Larastan's template type annotations, two names have changed:
429+
430+
* `TModelClass``TModel`
431+
* `TChildModel``TDeclaringModel`
432+
374433
### Reusable GitHub Workflows
375434

376435
##### <span class="breaking">Breaking</span>

0 commit comments

Comments
 (0)