Skip to content

Commit 837c1dd

Browse files
committed
Add support for non-zero-int
1 parent 88688cc commit 837c1dd

File tree

4 files changed

+75
-0
lines changed

4 files changed

+75
-0
lines changed

src/PseudoTypes/NonZeroInteger.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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\PseudoTypes;
15+
16+
use phpDocumentor\Reflection\PseudoType;
17+
use phpDocumentor\Reflection\Type;
18+
use phpDocumentor\Reflection\Types\Integer;
19+
20+
/**
21+
* Value Object representing the type 'non-zero-int'.
22+
*
23+
* @psalm-immutable
24+
*/
25+
final class NonZeroInteger extends Integer implements PseudoType
26+
{
27+
public function underlyingType(): Type
28+
{
29+
return new Integer();
30+
}
31+
32+
/**
33+
* Returns a rendered output of the Type as it would be used in a DocBlock.
34+
*/
35+
public function __toString(): string
36+
{
37+
return 'non-zero-int';
38+
}
39+
}

src/TypeResolver.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
use phpDocumentor\Reflection\PseudoTypes\NonFalsyString;
4848
use phpDocumentor\Reflection\PseudoTypes\NonNegativeInteger;
4949
use phpDocumentor\Reflection\PseudoTypes\NonPositiveInteger;
50+
use phpDocumentor\Reflection\PseudoTypes\NonZeroInteger;
5051
use phpDocumentor\Reflection\PseudoTypes\Numeric_;
5152
use phpDocumentor\Reflection\PseudoTypes\NumericString;
5253
use phpDocumentor\Reflection\PseudoTypes\ObjectShape;
@@ -187,6 +188,7 @@ final class TypeResolver
187188
'truthy-string' => TruthyString::class,
188189
'non-positive-int' => NonPositiveInteger::class,
189190
'non-negative-int' => NonNegativeInteger::class,
191+
'non-zero-int' => NonZeroInteger::class,
190192
];
191193

192194
/**
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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\PseudoTypes;
15+
16+
use phpDocumentor\Reflection\Types\Integer;
17+
use PHPUnit\Framework\TestCase;
18+
19+
final class NonZeroIntegerTest extends TestCase
20+
{
21+
public function testCreate(): void
22+
{
23+
$type = new NonZeroInteger();
24+
25+
$this->assertEquals(new Integer(), $type->underlyingType());
26+
}
27+
28+
public function testToString(): void
29+
{
30+
$this->assertSame('non-zero-int', (string) (new NonZeroInteger()));
31+
}
32+
}

tests/unit/TypeResolverTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
use phpDocumentor\Reflection\PseudoTypes\NonFalsyString;
4848
use phpDocumentor\Reflection\PseudoTypes\NonNegativeInteger;
4949
use phpDocumentor\Reflection\PseudoTypes\NonPositiveInteger;
50+
use phpDocumentor\Reflection\PseudoTypes\NonZeroInteger;
5051
use phpDocumentor\Reflection\PseudoTypes\Numeric_;
5152
use phpDocumentor\Reflection\PseudoTypes\NumericString;
5253
use phpDocumentor\Reflection\PseudoTypes\ObjectShape;
@@ -683,6 +684,7 @@ public function provideKeywords(): array
683684
['truthy-string', TruthyString::class],
684685
['non-positive-int', NonPositiveInteger::class],
685686
['non-negative-int', NonNegativeInteger::class],
687+
['non-zero-int', NonZeroInteger::class],
686688
];
687689
}
688690

0 commit comments

Comments
 (0)