-
Notifications
You must be signed in to change notification settings - Fork 483
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This allows for more flexibility in ignoring errors. Some use cases: * Ignore `missingType.iterableValue` on controller actions: Rule: when the method is public and it has `#[Route]` attribute or the class has `#[AsController]` attribute. * Ignore `should return int but returns int|null` on `getId` for entities. Rule: class needs to have `#[Entity]` attribute. * Ignore `never returns null so it can be removed from the return type` Rule: method needs to have `#[GraphQL\Field]` attribute. * Enforce missingCheckedExceptionInThrows partially, only for specific classes.
- Loading branch information
Showing
4 changed files
with
86 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace PHPStan\Analyser; | ||
|
||
use PhpParser\Node; | ||
|
||
/** | ||
* This is the extension interface to implement if you want to ignore errors | ||
* based on the node and scope. | ||
* | ||
* To register it in the configuration file use the `phpstan.ignoreErrorExtension` service tag: | ||
* | ||
* ``` | ||
* services: | ||
* - | ||
* class: App\PHPStan\MyExtension | ||
* tags: | ||
* - phpstan.ignoreErrorExtension | ||
* ``` | ||
* | ||
* Learn more: https://phpstan.org | ||
* | ||
* @api | ||
*/ | ||
interface IgnoreErrorExtension | ||
{ | ||
|
||
public const EXTENSION_TAG = 'phpstan.ignoreErrorExtension'; | ||
|
||
public function ignore(Error $error, ?Node $node, Scope $scope): bool; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace PHPStan\Analyser; | ||
|
||
use PHPStan\DependencyInjection\Container; | ||
|
||
final class IgnoreErrorExtensionProvider | ||
{ | ||
|
||
public function __construct(private Container $container) | ||
{ | ||
} | ||
|
||
/** | ||
* @return IgnoreErrorExtension[] | ||
*/ | ||
public function getExtensions(): array | ||
{ | ||
return $this->container->getServicesByTag(IgnoreErrorExtension::EXTENSION_TAG); | ||
} | ||
|
||
} |