Skip to content

Commit

Permalink
Merge pull request #4 from kkmuffme/allow-from-docblock-configurable
Browse files Browse the repository at this point in the history
configurable: allow fixes for types from docblock
  • Loading branch information
orklah committed Apr 28, 2024
2 parents 81c2487 + 352b74c commit b12333a
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/Hooks/NotEmptyHooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use PhpParser\Node\Expr\BooleanNot;
use PhpParser\Node\Expr\Empty_;
use PhpParser\Node\Expr\Variable;
use Psalm\Config;
use Psalm\FileManipulation;
use Psalm\Plugin\EventHandler\AfterExpressionAnalysisInterface;
use Psalm\Plugin\EventHandler\Event\AfterExpressionAnalysisEvent;
Expand Down Expand Up @@ -51,8 +52,24 @@ public static function afterExpressionAnalysis(AfterExpressionAnalysisEvent $eve
}

if ($type->from_docblock) {
//TODO: maybe add an issue in non alter mode
return null;
$allow_docblock = false;
$config = Config::getInstance();
foreach ($config->getPluginClasses() as $plugin) {
if ($plugin['class'] !== 'Orklah\NotEmpty\Plugin') {
continue;
}

if (isset($plugin['config']->fromDocblock['value']) && (string) $plugin['config']->fromDocblock['value'] === 'true') {
$allow_docblock = true;
}

break;
}

if ($allow_docblock === false) {
//TODO: maybe add an issue in non alter mode
return null;
}
}

if (!is_string($expr->expr->name)) {
Expand Down

0 comments on commit b12333a

Please sign in to comment.