Skip to content

Commit 936bce1

Browse files
authored
Merge pull request #271 from mspirkov/new-types
Add support for more pseudo-types
2 parents ace4950 + 965a996 commit 936bce1

15 files changed

+384
-2
lines changed

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 'int'.
21+
* Value Object representing the type 'negative-int'.
2222
*
2323
* @psalm-immutable
2424
*/

src/PseudoTypes/NonFalsyString.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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\String_;
19+
20+
/**
21+
* Value Object representing the type 'non-falsy-string'.
22+
*
23+
* @psalm-immutable
24+
*/
25+
final class NonFalsyString extends String_ implements PseudoType
26+
{
27+
public function underlyingType(): Type
28+
{
29+
return new String_();
30+
}
31+
32+
public function __toString(): string
33+
{
34+
return 'non-falsy-string';
35+
}
36+
}
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-negative-int'.
22+
*
23+
* @psalm-immutable
24+
*/
25+
final class NonNegativeInteger 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-negative-int';
38+
}
39+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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-positive-int'.
22+
*
23+
* @psalm-immutable
24+
*/
25+
final class NonPositiveInteger extends Integer implements PseudoType
26+
{
27+
public function underlyingType(): Type
28+
{
29+
return new Integer();
30+
}
31+
32+
public function __toString(): string
33+
{
34+
return 'non-positive-int';
35+
}
36+
}

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/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 'int'.
21+
* Value Object representing the type 'positive-int'.
2222
*
2323
* @psalm-immutable
2424
*/

src/PseudoTypes/TruthyString.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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\String_;
19+
20+
/**
21+
* Value Object representing the type 'truthy-string'.
22+
*
23+
* @psalm-immutable
24+
*/
25+
final class TruthyString extends String_ implements PseudoType
26+
{
27+
public function underlyingType(): Type
28+
{
29+
return new String_();
30+
}
31+
32+
public function __toString(): string
33+
{
34+
return 'truthy-string';
35+
}
36+
}

src/TypeResolver.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@
4444
use phpDocumentor\Reflection\PseudoTypes\NonEmptyList;
4545
use phpDocumentor\Reflection\PseudoTypes\NonEmptyLowercaseString;
4646
use phpDocumentor\Reflection\PseudoTypes\NonEmptyString;
47+
use phpDocumentor\Reflection\PseudoTypes\NonFalsyString;
48+
use phpDocumentor\Reflection\PseudoTypes\NonNegativeInteger;
49+
use phpDocumentor\Reflection\PseudoTypes\NonPositiveInteger;
50+
use phpDocumentor\Reflection\PseudoTypes\NonZeroInteger;
4751
use phpDocumentor\Reflection\PseudoTypes\Numeric_;
4852
use phpDocumentor\Reflection\PseudoTypes\NumericString;
4953
use phpDocumentor\Reflection\PseudoTypes\ObjectShape;
@@ -58,6 +62,7 @@
5862
use phpDocumentor\Reflection\PseudoTypes\StringValue;
5963
use phpDocumentor\Reflection\PseudoTypes\TraitString;
6064
use phpDocumentor\Reflection\PseudoTypes\True_;
65+
use phpDocumentor\Reflection\PseudoTypes\TruthyString;
6166
use phpDocumentor\Reflection\PseudoTypes\ValueOf;
6267
use phpDocumentor\Reflection\Types\AggregatedType;
6368
use phpDocumentor\Reflection\Types\Array_;
@@ -179,6 +184,11 @@ final class TypeResolver
179184
'never' => Never_::class,
180185
'list' => List_::class,
181186
'non-empty-list' => NonEmptyList::class,
187+
'non-falsy-string' => NonFalsyString::class,
188+
'truthy-string' => TruthyString::class,
189+
'non-positive-int' => NonPositiveInteger::class,
190+
'non-negative-int' => NonNegativeInteger::class,
191+
'non-zero-int' => NonZeroInteger::class,
182192
];
183193

184194
/**
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\String_;
17+
use PHPUnit\Framework\TestCase;
18+
19+
final class NonFalsyStringTest extends TestCase
20+
{
21+
public function testCreate(): void
22+
{
23+
$type = new NonFalsyString();
24+
25+
$this->assertEquals(new String_(), $type->underlyingType());
26+
}
27+
28+
public function testToString(): void
29+
{
30+
$this->assertSame('non-falsy-string', (string) (new NonFalsyString()));
31+
}
32+
}
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 NonNegativeIntegerTest extends TestCase
20+
{
21+
public function testCreate(): void
22+
{
23+
$type = new NonNegativeInteger();
24+
25+
$this->assertEquals(new Integer(), $type->underlyingType());
26+
}
27+
28+
public function testToString(): void
29+
{
30+
$this->assertSame('non-negative-int', (string) (new NonNegativeInteger()));
31+
}
32+
}

0 commit comments

Comments
 (0)