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 19, 2022
1 parent b701c70 commit e2e6265
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
Expand Up @@ -541,18 +541,28 @@ 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()
]);
// use TNull explicitly instead of this
// as it will cause weird errors due to ignore_nullable_issues true
// e.g. InvalidPropertyAssignmentValue
// $this->argv 'list<string>' cannot be assigned type 'non-empty-list<string>'
// $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()
]);
// $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 e2e6265

Please sign in to comment.