Skip to content

Commit

Permalink
ignore nullable issues for $argv/$argc
Browse files Browse the repository at this point in the history
  • Loading branch information
kkmuffme committed Sep 15, 2022
1 parent b701c70 commit 26faa4b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
Expand Up @@ -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;
Expand Down Expand Up @@ -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)) {
Expand Down
4 changes: 2 additions & 2 deletions tests/Internal/CliUtilsTest.php
Expand Up @@ -12,14 +12,14 @@
class CliUtilsTest extends TestCase
{
/**
* @var array<int, string>
* @var list<string>
*/
private $argv = [];

protected function setUp(): void
{
global $argv;
$this->argv = $argv ?? [];
$this->argv = $argv;
}

protected function tearDown(): void
Expand Down

0 comments on commit 26faa4b

Please sign in to comment.