Skip to content

Commit

Permalink
Trigger dispatch even when only legacy hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
adrienlucas committed Jan 8, 2021
1 parent d1398f2 commit 372f5c7
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 8 deletions.
Expand Up @@ -370,7 +370,7 @@ function (Assertion $assertion) use (
}
}

if ($config->eventDispatcher->after_method_checks) {
if ($config->eventDispatcher->hasAfterMethodCallAnalysisHandlers()) {
$file_manipulations = [];

$appearing_method_id = $codebase->methods->getAppearingMethodId($method_id);
Expand Down
Expand Up @@ -469,7 +469,7 @@ function (Assertion $assertion) use ($generic_params) : Assertion {
}
}

if ($config->eventDispatcher->after_method_checks) {
if ($config->eventDispatcher->hasAfterMethodCallAnalysisHandlers()) {
$file_manipulations = [];

$appearing_method_id = $codebase->methods->getAppearingMethodId($method_id);
Expand Down
18 changes: 14 additions & 4 deletions src/Psalm/Internal/EventDispatcher.php
Expand Up @@ -16,9 +16,9 @@ class EventDispatcher
*
* @var list<class-string<EventHandler\AfterMethodCallAnalysisInterface>>
*/
public $after_method_checks = [];
private $after_method_checks = [];
/** @var list<class-string<Hook\AfterMethodCallAnalysisInterface>> */
public $legacy_after_method_checks = [];
private $legacy_after_method_checks = [];

/**
* Static methods to be called after project function checks have completed
Expand Down Expand Up @@ -96,9 +96,9 @@ class EventDispatcher
*
* @var list<class-string<EventHandler\AfterClassLikeVisitInterface>>
*/
public $after_visit_classlikes = [];
private $after_visit_classlikes = [];
/** @var list<class-string<Hook\AfterClassLikeVisitInterface>> */
public $legacy_after_visit_classlikes = [];
private $legacy_after_visit_classlikes = [];

/**
* Static methods to be called after codebase has been populated
Expand Down Expand Up @@ -235,6 +235,11 @@ public function registerClass(string $class): void
}
}

public function hasAfterMethodCallAnalysisHandlers(): bool
{
return count($this->after_method_checks) || count($this->legacy_after_method_checks);
}

public function dispatchAfterMethodCallAnalysis(Event\AfterMethodCallAnalysisEvent $event): void
{
foreach ($this->after_method_checks as $handler) {
Expand Down Expand Up @@ -409,6 +414,11 @@ public function dispatchAfterClassLikeAnalysis(Event\AfterClassLikeAnalysisEvent
return null;
}

public function hasAfterClassLikeVisitHandlers(): bool
{
return count($this->after_visit_classlikes) || count($this->legacy_after_visit_classlikes);
}

public function dispatchAfterClassLikeVisit(Event\AfterClassLikeVisitEvent $event): void
{
foreach ($this->after_visit_classlikes as $handler) {
Expand Down
Expand Up @@ -51,7 +51,7 @@ public function __construct(Config $config)
$storage_dir . 'MethodStorage.php',
];

if ($config->eventDispatcher->after_visit_classlikes) {
if ($config->eventDispatcher->hasAfterClassLikeVisitHandlers()) {
$dependent_files = array_merge($dependent_files, $config->plugin_paths);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Psalm/Internal/Provider/FileStorageCacheProvider.php
Expand Up @@ -52,7 +52,7 @@ public function __construct(Config $config)
$storage_dir . 'FunctionLikeParameter.php',
];

if ($config->eventDispatcher->after_visit_classlikes) {
if ($config->eventDispatcher->hasAfterClassLikeVisitHandlers()) {
$dependent_files = array_merge($dependent_files, $config->plugin_paths);
}

Expand Down

0 comments on commit 372f5c7

Please sign in to comment.