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

Remove unnecessary null type from initialized_methods Context property #10610

Merged
merged 2 commits into from
Jan 28, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/Psalm/Context.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ final class Context
/**
* A set of references that might still be in scope from a scope likely to cause confusion. This applies
* to references set inside a loop or if statement, since it's easy to forget about PHP's weird scope
* rules, and assinging to a reference will change the referenced variable rather than shadowing it.
* rules, and assigning to a reference will change the referenced variable rather than shadowing it.
*
* @var array<string, CodeLocation>
*/
Expand All @@ -112,7 +112,7 @@ final class Context
public bool $inside_unset = false;

/**
* Whether or not we're inside an class_exists call, where
* Whether or not we're inside a class_exists call, where
* we don't care about possibly undefined classes
*/
public bool $inside_class_exists = false;
Expand Down Expand Up @@ -207,9 +207,9 @@ final class Context
/**
* Stored to prevent re-analysing methods when checking for initialised properties
*
* @var array<string, bool>|null
* @var array<string, bool>
*/
public ?array $initialized_methods = null;
public array $initialized_methods = [];

/**
* @var array<string, Union>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,6 @@ public static function analyze(
}

if (!isset($context->initialized_methods[(string) $appearing_method_id])) {
if ($context->initialized_methods === null) {
$context->initialized_methods = [];
}

$context->initialized_methods[(string) $appearing_method_id] = true;

$file_analyzer->getMethodMutations($appearing_method_id, $context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,6 @@ public static function collectSpecialInformation(
return;
}

if ($context->initialized_methods === null) {
$context->initialized_methods = [];
}

$context->initialized_methods[(string) $method_id] = true;
}

Expand Down Expand Up @@ -193,10 +189,6 @@ public static function collectSpecialInformation(
return;
}

if ($context->initialized_methods === null) {
$context->initialized_methods = [];
}

$context->initialized_methods[(string) $declaring_method_id] = true;

$method_storage = $codebase->methods->getStorage($declaring_method_id);
Expand Down
3 changes: 2 additions & 1 deletion tests/Config/ConfigFileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -285,8 +285,9 @@ protected static function compareContentWithTemplateAndTrailingLineEnding(string
$passed = false;

foreach ([PHP_EOL, "\n", "\r", "\r\n"] as $eol) {
if (!$passed && $contents === ($expected_template . $eol)) {
if ($contents === ($expected_template . $eol)) {
$passed = true;
break;
}
}

Expand Down