Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEATURE] Allow to intercept adding issue in IssueBuffer
This change introduces new `BeforeAddIssueEvent` which is invoked from `IssueBuffer::add`, which allows to collect and intercept code issue in a generic way. Resolves: #7528
- Loading branch information
Showing
6 changed files
with
133 additions
and
0 deletions.
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
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,21 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Psalm\Plugin\EventHandler; | ||
|
||
use Psalm\Plugin\EventHandler\Event\BeforeAddIssueEvent; | ||
|
||
interface BeforeAddIssueInterface | ||
{ | ||
/** | ||
* Called before adding a code issue. | ||
* | ||
* @param BeforeAddIssueEvent $event | ||
* @return null|bool $event How and whether to continue: | ||
* + `null` continues with next event handler | ||
* + `true` stops event handling & keeps issue | ||
* + `false` stops event handling & ignores issue | ||
*/ | ||
public static function beforeAddIssue(BeforeAddIssueEvent $event): ?bool; | ||
} |
36 changes: 36 additions & 0 deletions
36
src/Psalm/Plugin/EventHandler/Event/BeforeAddIssueEvent.php
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,36 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Psalm\Plugin\EventHandler\Event; | ||
|
||
use Psalm\Issue\CodeIssue; | ||
|
||
class BeforeAddIssueEvent | ||
{ | ||
/** | ||
* @var CodeIssue | ||
*/ | ||
private CodeIssue $issue; | ||
|
||
/** | ||
* @var bool | ||
*/ | ||
private bool $fixable; | ||
|
||
public function __construct(CodeIssue $issue, bool $fixable) | ||
{ | ||
$this->issue = $issue; | ||
$this->fixable = $fixable; | ||
} | ||
|
||
public function getIssue(): CodeIssue | ||
{ | ||
return $this->issue; | ||
} | ||
|
||
public function isFixable(): bool | ||
{ | ||
return $this->fixable; | ||
} | ||
} |
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