Skip to content

Commit

Permalink
[PropertyInfo] Add missing type resolver for PHPStan non-*-int
Browse files Browse the repository at this point in the history
  • Loading branch information
wuchen90 committed Dec 12, 2024
1 parent c78a9ec commit 1248b8c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,9 @@ public static function pseudoTypesProvider(): array
['literalString', [new Type(Type::BUILTIN_TYPE_STRING, false, null)]],
['positiveInt', [new Type(Type::BUILTIN_TYPE_INT, false, null)]],
['negativeInt', [new Type(Type::BUILTIN_TYPE_INT, false, null)]],
['nonPositiveInt', [new Type(Type::BUILTIN_TYPE_INT, false, null)]],
['nonNegativeInt', [new Type(Type::BUILTIN_TYPE_INT, false, null)]],
['nonZeroInt', [new Type(Type::BUILTIN_TYPE_INT, false, null)]],
['nonEmptyArray', [new Type(Type::BUILTIN_TYPE_ARRAY, false, null, true)]],
['nonEmptyList', [new Type(Type::BUILTIN_TYPE_ARRAY, false, null, true, new Type(Type::BUILTIN_TYPE_INT))]],
['scalar', [new Type(Type::BUILTIN_TYPE_INT), new Type(Type::BUILTIN_TYPE_FLOAT), new Type(Type::BUILTIN_TYPE_STRING), new Type(Type::BUILTIN_TYPE_BOOL)]],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@ class PhpStanPseudoTypesDummy extends PseudoTypesDummy
/** @var negative-int */
public $negativeInt;

/** @var non-positive-int */
public $nonPositiveInt;

/** @var non-negative-int */
public $nonNegativeInt;

/** @var non-zero-int */
public $nonZeroInt;

/** @var non-empty-array */
public $nonEmptyArray;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,10 @@ private function extractTypes(TypeNode $node, NameScope $nameScope): array
return match ($node->name) {
'integer',
'positive-int',
'negative-int' => [new Type(Type::BUILTIN_TYPE_INT)],
'negative-int',
'non-positive-int',
'non-negative-int',
'non-zero-int' => [new Type(Type::BUILTIN_TYPE_INT)],
'double' => [new Type(Type::BUILTIN_TYPE_FLOAT)],
'list',
'non-empty-list' => [new Type(Type::BUILTIN_TYPE_ARRAY, false, null, true, new Type(Type::BUILTIN_TYPE_INT))],
Expand Down

0 comments on commit 1248b8c

Please sign in to comment.