Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add non-negative-int and non-positive-int #1803

Merged
merged 1 commit into from
Oct 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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);
}

}