Skip to content

Commit

Permalink
Add non-negative-int and non-positive-int
Browse files Browse the repository at this point in the history
  • Loading branch information
rvanvelzen authored and ondrejmirtes committed Oct 8, 2022
1 parent 1c01253 commit 49cd131
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/PhpDoc/TypeNodeResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,12 @@ private function resolveIdentifierTypeNode(IdentifierTypeNode $typeNode, NameSco
case 'negative-int':
return IntegerRangeType::fromInterval(null, -1);

case 'non-positive-int':
return IntegerRangeType::fromInterval(null, 0);

case 'non-negative-int':
return IntegerRangeType::fromInterval(0, null);

case 'string':
return new StringType();

Expand Down
1 change: 1 addition & 0 deletions tests/PHPStan/Analyser/NodeScopeResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1062,6 +1062,7 @@ public function dataFileAsserts(): iterable
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-8008.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/assert-class-type.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-5552.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/extra-extra-int-types.php');
}

/**
Expand Down
23 changes: 23 additions & 0 deletions tests/PHPStan/Analyser/data/extra-extra-int-types.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace ExtraExtraIntTypes;

use function PHPStan\Testing\assertType;

class Foo
{

/**
* @param non-positive-int $nonPositiveInt
* @param non-negative-int $nonNegativeInt
*/
public function doFoo(
int $nonPositiveInt,
int $nonNegativeInt,
): void
{
assertType('int<min, 0>', $nonPositiveInt);
assertType('int<0, max>', $nonNegativeInt);
}

}

0 comments on commit 49cd131

Please sign in to comment.