Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Codebase to remaining events #8961

Merged
merged 1 commit into from Dec 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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