Skip to content

Commit 6a62c4e

Browse files
committed
[BE] Require RuleErrorBuilder and identifiers in custom rules
1 parent fa86d61 commit 6a62c4e

File tree

5 files changed

+25
-31
lines changed

5 files changed

+25
-31
lines changed

UPGRADING.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,28 @@ Now, `throw $e;` is represented as a `Stmt\Expression` that contains an `Expr\Th
6868

6969
See [UPGRADING](https://github.com/phpstan/phpdoc-parser/blob/2.0.x/UPGRADING.md) guide for phpstan/phpdoc-parser.
7070

71+
### Returning plain strings as errors no longer supported, use RuleErrorBuilder
72+
*
73+
Identifiers are also required in custom rules.
74+
75+
Learn more: [Using RuleErrorBuilder to enrich reported errors in custom rules](https://phpstan.org/blog/using-rule-error-builder)
76+
77+
Before:
78+
79+
```php
80+
return ['My error'];
81+
```
82+
83+
After:
84+
85+
```php
86+
return [
87+
RuleErrorBuilder::mesage('My error')
88+
->identifier('my.error')
89+
->build(),
90+
];
91+
```
92+
7193
### Changed `TypeSpecifier::create()` and `SpecifiedTypes` constructor parameters
7294

7395
[`PHPStan\Analyser\TypeSpecifier::create()`](https://apiref.phpstan.org/2.0.x/PHPStan.Analyser.TypeSpecifier.html#_create) now accepts (all parameters are required):

changelog-2.0.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,6 @@ Bleeding edge (TODO move to other sections)
8989
* BetterNoopRule - take advantage of impure points (https://github.com/phpstan/phpstan-src/commit/a6470521b65d7424f552633c1f3827704c6262c3), #10389
9090
* Run missing type check on `@param-out` (https://github.com/phpstan/phpstan-src/commit/56b20024386d983927c64dfa895ff026bed2798c)
9191
* CallToConstructorStatementWithoutSideEffectsRule - report class with no constructor (https://github.com/phpstan/phpstan-src/commit/b116d25a6e4ba6c09f59af6569d9e6f6fd20aff4)
92-
* Deprecated: returning plain strings as errors, use RuleErrorBuilder
93-
* Learn more: [Using RuleErrorBuilder to enrich reported errors in custom rules](https://phpstan.org/blog/using-rule-error-builder)
9492
* Check if required file exists ([#3294](https://github.com/phpstan/phpstan-src/pull/3294)), #3397, thanks @Bellangelo!
9593
* Check generics `@method` `@template` tags above traits (https://github.com/phpstan/phpstan-src/commit/aadbf62d3ae4517fc7a212b07130bedcef8d13ac)
9694
* Check `@mixin` PHPDoc tag above traits (https://github.com/phpstan/phpstan-src/commit/0d0de946900adf4eb3c799b1b547567536e23147)
@@ -138,6 +136,8 @@ Improvements 🔧
138136
* Analysis with zero files results in non-zero exit code (https://github.com/phpstan/phpstan-src/commit/46ff440648e62617df86aa74ba905ffa99897737), #9410
139137
* Fail build when project config uses custom extensions outside of analysed paths
140138
* This will only occur after a run that uses already present and valid result cache
139+
* Returning plain strings as errors no longer supported, use RuleErrorBuilder
140+
* Learn more: [Using RuleErrorBuilder to enrich reported errors in custom rules](https://phpstan.org/blog/using-rule-error-builder)
141141
* Require identifier in custom rules (https://github.com/phpstan/phpstan-src/commit/969e6fa31d5484d42dab902703cfc6820a983cfd)
142142

143143
Bugfixes 🐛

conf/bleedingEdge.neon

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,3 @@ parameters:
5757
explicitThrow: true
5858
absentTypeChecks: true
5959
requireFileExists: true
60-
stubFiles:
61-
- ../stubs/bleedingEdge/Rule.stub

src/Rules/Rule.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public function getNodeType(): string;
3232

3333
/**
3434
* @phpstan-param TNodeType $node
35-
* @return (string|RuleError)[] errors
35+
* @return list<IdentifierRuleError>
3636
*/
3737
public function processNode(Node $node, Scope $scope): array;
3838

stubs/bleedingEdge/Rule.stub

Lines changed: 0 additions & 26 deletions
This file was deleted.

0 commit comments

Comments
 (0)