Skip to content

Commit 21e2f91

Browse files
committed
add support for "int<min,max>", "negative-int" and "numeric" v2
Thanks @orklah
1 parent 0e49057 commit 21e2f91

File tree

5 files changed

+64
-4
lines changed

5 files changed

+64
-4
lines changed

src/PseudoTypes/IntegerRange.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
use phpDocumentor\Reflection\Types\Integer;
1919

2020
/**
21-
* Value Object representing the type 'string'.
21+
* Value Object representing the type 'int'.
2222
*
2323
* @psalm-immutable
2424
*/

src/PseudoTypes/NegativeInteger.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
use phpDocumentor\Reflection\Types\Integer;
1919

2020
/**
21-
* Value Object representing the type 'string'.
21+
* Value Object representing the type 'int'.
2222
*
2323
* @psalm-immutable
2424
*/

src/PseudoTypes/PositiveInteger.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
use phpDocumentor\Reflection\Types\Integer;
1919

2020
/**
21-
* Value Object representing the type 'string'.
21+
* Value Object representing the type 'int'.
2222
*
2323
* @psalm-immutable
2424
*/

src/Types/Numeric_.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,27 @@
1313

1414
namespace phpDocumentor\Reflection\Types;
1515

16+
use phpDocumentor\Reflection\PseudoType;
17+
use phpDocumentor\Reflection\PseudoTypes\NumericString;
1618
use phpDocumentor\Reflection\Type;
1719

1820
/**
1921
* Value Object representing the 'numeric' pseudo-type, which is either a numeric-string, integer or float.
2022
*
2123
* @psalm-immutable
2224
*/
23-
final class Numeric_ implements Type
25+
final class Numeric_ extends AggregatedType implements PseudoType
2426
{
27+
public function __construct()
28+
{
29+
parent::__construct([new NumericString(), new Integer(), new Float_()], '|');
30+
}
31+
32+
public function underlyingType(): Type
33+
{
34+
return new Compound([new NumericString(), new Integer(), new Float_()]);
35+
}
36+
2537
/**
2638
* Returns a rendered output of the Type as it would be used in a DocBlock.
2739
*/

tests/unit/NumericResolverTest.php

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* This file is part of phpDocumentor.
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*
11+
* @link http://phpdoc.org
12+
*/
13+
14+
namespace phpDocumentor\Reflection;
15+
16+
use phpDocumentor\Reflection\PseudoTypes\NumericString;
17+
use phpDocumentor\Reflection\Types\Context;
18+
use phpDocumentor\Reflection\Types\Numeric_;
19+
use phpDocumentor\Reflection\Types\String_;
20+
use PHPUnit\Framework\TestCase;
21+
22+
/**
23+
* @covers ::<private>
24+
* @coversDefaultClass \phpDocumentor\Reflection\TypeResolver
25+
*/
26+
class NumericResolverTest extends TestCase
27+
{
28+
/**
29+
* @uses \phpDocumentor\Reflection\Types\Context
30+
* @uses \phpDocumentor\Reflection\Types\Compound
31+
* @uses \phpDocumentor\Reflection\Types\Collection
32+
* @uses \phpDocumentor\Reflection\Types\String_
33+
*
34+
* @covers ::__construct
35+
* @covers ::resolve
36+
*/
37+
public function testResolvingIntRange(): void
38+
{
39+
$fixture = new TypeResolver();
40+
41+
$resolvedType = $fixture->resolve('numeric', new Context(''));
42+
43+
$this->assertInstanceOf(Numeric_::class, $resolvedType);
44+
$this->assertSame('numeric', (string) $resolvedType);
45+
$this->assertSame(false, $resolvedType->underlyingType()->contains(new String_()));
46+
$this->assertSame(true, $resolvedType->underlyingType()->contains(new NumericString()));
47+
}
48+
}

0 commit comments

Comments
 (0)