Skip to content

Commit

Permalink
Merge pull request #8961 from jack-worman/Add_Codebase_to_remaining_e…
Browse files Browse the repository at this point in the history
…vents
  • Loading branch information
weirdan committed Dec 21, 2022
2 parents 91081f7 + b2ccf24 commit 96f8902
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 11 deletions.
10 changes: 5 additions & 5 deletions src/Psalm/IssueBuffer.php
Expand Up @@ -254,24 +254,24 @@ public static function isSuppressed(CodeIssue $e, array $suppressed_issues = [])
public static function add(CodeIssue $e, bool $is_fixable = false): bool
{
$config = Config::getInstance();
$project_analyzer = ProjectAnalyzer::getInstance();
$codebase = $project_analyzer->getCodebase();

$event = new BeforeAddIssueEvent($e, $is_fixable);
$event = new BeforeAddIssueEvent($e, $is_fixable, $codebase);
if ($config->eventDispatcher->dispatchBeforeAddIssue($event) === false) {
return false;
};
}

$fqcn_parts = explode('\\', get_class($e));
$issue_type = array_pop($fqcn_parts);

$project_analyzer = ProjectAnalyzer::getInstance();

if (!$project_analyzer->show_issues) {
return false;
}

$is_tainted = strpos($issue_type, 'Tainted') === 0;

if ($project_analyzer->getCodebase()->taint_flow_graph && !$is_tainted) {
if ($codebase->taint_flow_graph && !$is_tainted) {
return false;
}

Expand Down
11 changes: 9 additions & 2 deletions src/Psalm/Plugin/EventHandler/Event/BeforeAddIssueEvent.php
Expand Up @@ -4,19 +4,21 @@

namespace Psalm\Plugin\EventHandler\Event;

use Psalm\Codebase;
use Psalm\Issue\CodeIssue;

final class BeforeAddIssueEvent
{
private CodeIssue $issue;

private bool $fixable;
private Codebase $codebase;

/** @internal */
public function __construct(CodeIssue $issue, bool $fixable)
public function __construct(CodeIssue $issue, bool $fixable, Codebase $codebase)
{
$this->issue = $issue;
$this->fixable = $fixable;
$this->codebase = $codebase;
}

public function getIssue(): CodeIssue
Expand All @@ -28,4 +30,9 @@ public function isFixable(): bool
{
return $this->fixable;
}

public function getCodebase(): Codebase
{
return $this->codebase;
}
}
11 changes: 10 additions & 1 deletion src/Psalm/Plugin/EventHandler/Event/StringInterpreterEvent.php
Expand Up @@ -2,23 +2,32 @@

namespace Psalm\Plugin\EventHandler\Event;

use Psalm\Codebase;

final class StringInterpreterEvent
{
private string $value;
private Codebase $codebase;

/**
* Called after a statement has been checked
*
* @psalm-external-mutation-free
* @internal
*/
public function __construct(string $value)
public function __construct(string $value, Codebase $codebase)
{
$this->value = $value;
$this->codebase = $codebase;
}

public function getValue(): string
{
return $this->value;
}

public function getCodebase(): Codebase
{
return $this->codebase;
}
}
3 changes: 2 additions & 1 deletion src/Psalm/Type.php
Expand Up @@ -4,6 +4,7 @@

use InvalidArgumentException;
use LogicException;
use Psalm\Internal\Analyzer\ProjectAnalyzer;
use Psalm\Internal\Type\Comparator\AtomicTypeComparator;
use Psalm\Internal\Type\Comparator\UnionTypeComparator;
use Psalm\Internal\Type\TypeCombiner;
Expand Down Expand Up @@ -256,7 +257,7 @@ public static function getString(?string $value = null): Union
if ($value !== null) {
$config = Config::getInstance();

$event = new StringInterpreterEvent($value);
$event = new StringInterpreterEvent($value, ProjectAnalyzer::getInstance()->getCodebase());

$type = $config->eventDispatcher->dispatchStringInterpreter($event);

Expand Down
4 changes: 2 additions & 2 deletions tests/StubTest.php
Expand Up @@ -418,9 +418,9 @@ function bar(array $a) {}
'$c2===' => "'hello'",

'$d1===' => "5",
'$d2===' => "'hello'"
'$d2===' => "'hello'",
],
$context
$context,
);
}

Expand Down

0 comments on commit 96f8902

Please sign in to comment.