Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 49cd131

Browse files
Richard van Velzenondrejmirtes
Richard van Velzen
authored andcommitted
Add non-negative-int and non-positive-int
1 parent 1c01253 commit 49cd131

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

‎src/PhpDoc/TypeNodeResolver.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,12 @@ private function resolveIdentifierTypeNode(IdentifierTypeNode $typeNode, NameSco
182182
case 'negative-int':
183183
return IntegerRangeType::fromInterval(null, -1);
184184

185+
case 'non-positive-int':
186+
return IntegerRangeType::fromInterval(null, 0);
187+
188+
case 'non-negative-int':
189+
return IntegerRangeType::fromInterval(0, null);
190+
185191
case 'string':
186192
return new StringType();
187193

‎tests/PHPStan/Analyser/NodeScopeResolverTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1062,6 +1062,7 @@ public function dataFileAsserts(): iterable
10621062
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-8008.php');
10631063
yield from $this->gatherAssertTypes(__DIR__ . '/data/assert-class-type.php');
10641064
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-5552.php');
1065+
yield from $this->gatherAssertTypes(__DIR__ . '/data/extra-extra-int-types.php');
10651066
}
10661067

10671068
/**
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
namespace ExtraExtraIntTypes;
4+
5+
use function PHPStan\Testing\assertType;
6+
7+
class Foo
8+
{
9+
10+
/**
11+
* @param non-positive-int $nonPositiveInt
12+
* @param non-negative-int $nonNegativeInt
13+
*/
14+
public function doFoo(
15+
int $nonPositiveInt,
16+
int $nonNegativeInt,
17+
): void
18+
{
19+
assertType('int<min, 0>', $nonPositiveInt);
20+
assertType('int<0, max>', $nonNegativeInt);
21+
}
22+
23+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /