From 661c7b363ef21cedc4ea4095bbfb9380d925a8cc Mon Sep 17 00:00:00 2001 From: kkmuffme <11071985+kkmuffme@users.noreply.github.com> Date: Thu, 15 Sep 2022 19:49:36 +0200 Subject: [PATCH] ignore nullable issues for $argv/$argc --- .../Expression/Fetch/VariableFetchAnalyzer.php | 15 ++++++++++----- tests/Internal/CliUtilsTest.php | 2 +- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/VariableFetchAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/VariableFetchAnalyzer.php index 8b3f8de7a7a..a61010467a3 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/VariableFetchAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/VariableFetchAnalyzer.php @@ -29,7 +29,6 @@ use Psalm\Type\Atomic\TNonEmptyArray; use Psalm\Type\Atomic\TNonEmptyList; use Psalm\Type\Atomic\TNonEmptyString; -use Psalm\Type\Atomic\TNull; use Psalm\Type\Atomic\TString; use Psalm\Type\TaintKindGroup; use Psalm\Type\Union; @@ -541,18 +540,24 @@ public static function getGlobalType(string $var_id, int $codebase_analysis_php_ if ($var_id === '$argv') { // only in CLI, null otherwise - return new Union([ + $argv_nullable = new Union([ new TNonEmptyList(Type::getString()), - new TNull() + // new TNull() ]); + $argv_nullable->possibly_undefined = true; + $argv_nullable->ignore_nullable_issues = true; + return $argv_nullable; } if ($var_id === '$argc') { // only in CLI, null otherwise - return new Union([ + $argc_nullable = new Union([ new TIntRange(1, null), - new TNull() + // new TNull() ]); + $argc_nullable->possibly_undefined = true; + $argc_nullable->ignore_nullable_issues = true; + return $argc_nullable; } if (!self::isSuperGlobal($var_id)) { diff --git a/tests/Internal/CliUtilsTest.php b/tests/Internal/CliUtilsTest.php index a2bfe9cb6fc..f6f6ab0511e 100644 --- a/tests/Internal/CliUtilsTest.php +++ b/tests/Internal/CliUtilsTest.php @@ -19,7 +19,7 @@ class CliUtilsTest extends TestCase protected function setUp(): void { global $argv; - $this->argv = $argv ?? []; + $this->argv = $argv; } protected function tearDown(): void