generated from psalm/psalm-plugin-skeleton
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
36 additions
and
23 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Marartner\PsalmNoEmpty\Hooks; | ||
|
||
use Marartner\PsalmNoEmpty\Issue\UsedEmptyConstruct; | ||
use PhpParser\Node\Expr; | ||
use Psalm\Codebase; | ||
use Psalm\CodeLocation; | ||
use Psalm\Context; | ||
use Psalm\IssueBuffer; | ||
use Psalm\Plugin\Hook\AfterExpressionAnalysisInterface; | ||
use Psalm\StatementsSource; | ||
|
||
final class UsedEmptyHook implements AfterExpressionAnalysisInterface | ||
{ | ||
public static function afterExpressionAnalysis(Expr $expr, Context $context, StatementsSource $statements_source, Codebase $codebase, array &$file_replacements = []): ?bool | ||
{ | ||
if ($expr instanceof Expr\Empty_) { | ||
IssueBuffer::accepts( | ||
new UsedEmptyConstruct( | ||
'Do not use the empty() construct', | ||
new CodeLocation($statements_source->getSource(), $expr) | ||
), | ||
$statements_source->getSuppressedIssues() | ||
); | ||
} | ||
return null; | ||
} | ||
} |
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 |
---|---|---|
@@ -1,36 +1,20 @@ | ||
<?php | ||
<?php declare(strict_types=1); | ||
|
||
namespace Marartner\PsalmNoEmpty; | ||
|
||
use Marartner\PsalmNoEmpty\Issue\UsedEmptyConstruct; | ||
use PhpParser\Node\Expr; | ||
use Psalm\Codebase; | ||
use Psalm\CodeLocation; | ||
use Psalm\Context; | ||
use Psalm\IssueBuffer; | ||
use Psalm\Plugin\Hook\AfterExpressionAnalysisInterface; | ||
use Psalm\StatementsSource; | ||
use Marartner\PsalmNoEmpty\Hooks\UsedEmptyHook; | ||
use SimpleXMLElement; | ||
use Psalm\Plugin\PluginEntryPointInterface; | ||
use Psalm\Plugin\RegistrationInterface; | ||
use function class_exists; | ||
|
||
class Plugin implements PluginEntryPointInterface, AfterExpressionAnalysisInterface | ||
class Plugin implements PluginEntryPointInterface | ||
{ | ||
public function __invoke(RegistrationInterface $registration, ?SimpleXMLElement $config = null): void | ||
{ | ||
// TODO: Implement __invoke() method. | ||
} | ||
|
||
public static function afterExpressionAnalysis(Expr $expr, Context $context, StatementsSource $statements_source, Codebase $codebase, array &$file_replacements = []): ?bool | ||
{ | ||
if ($expr instanceof Expr\Empty_) { | ||
IssueBuffer::accepts( | ||
new UsedEmptyConstruct( | ||
'Do not use the empty() construct', | ||
new CodeLocation($statements_source->getSource(), $expr) | ||
), | ||
$statements_source->getSuppressedIssues() | ||
); | ||
if(class_exists(UsedEmptyHook::class)){ | ||
$registration->registerHooksFromClass(UsedEmptyHook::class); | ||
} | ||
} | ||
} | ||
|