Skip to content

Commit dbe2133

Browse files
authored
Merge pull request #308 from oleibman/TypeResolver2
Support non-decimal-int-string
2 parents b2abba8 + 2de297d commit dbe2133

5 files changed

Lines changed: 146 additions & 0 deletions

File tree

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\String_;
19+
20+
/**
21+
* Value Object representing the type 'numeric-string'.
22+
*
23+
* @psalm-immutable
24+
*/
25+
final class DecimalIntString extends String_ implements PseudoType
26+
{
27+
public function underlyingType(): Type
28+
{
29+
return new String_();
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 'decimal-int-string';
38+
}
39+
}
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\String_;
19+
20+
/**
21+
* Value Object representing the type 'numeric-string'.
22+
*
23+
* @psalm-immutable
24+
*/
25+
final class NonDecimalIntString extends String_ implements PseudoType
26+
{
27+
public function underlyingType(): Type
28+
{
29+
return new String_();
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-decimal-int-string';
38+
}
39+
}

‎src/TypeResolver.php‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
use phpDocumentor\Reflection\PseudoTypes\Conditional;
2626
use phpDocumentor\Reflection\PseudoTypes\ConditionalForParameter;
2727
use phpDocumentor\Reflection\PseudoTypes\ConstExpression;
28+
use phpDocumentor\Reflection\PseudoTypes\DecimalIntString;
2829
use phpDocumentor\Reflection\PseudoTypes\EnumString;
2930
use phpDocumentor\Reflection\PseudoTypes\False_;
3031
use phpDocumentor\Reflection\PseudoTypes\FloatValue;
@@ -44,6 +45,7 @@
4445
use phpDocumentor\Reflection\PseudoTypes\NegativeInteger;
4546
use phpDocumentor\Reflection\PseudoTypes\NeverReturn;
4647
use phpDocumentor\Reflection\PseudoTypes\NeverReturns;
48+
use phpDocumentor\Reflection\PseudoTypes\NonDecimalIntString;
4749
use phpDocumentor\Reflection\PseudoTypes\NonEmptyArray;
4850
use phpDocumentor\Reflection\PseudoTypes\NonEmptyList;
4951
use phpDocumentor\Reflection\PseudoTypes\NonEmptyLowercaseString;
@@ -155,6 +157,8 @@ final class TypeResolver
155157
'non-empty-lowercase-string' => NonEmptyLowercaseString::class,
156158
'non-empty-string' => NonEmptyString::class,
157159
'numeric-string' => NumericString::class,
160+
'non-decimal-int-string' => NonDecimalIntString::class,
161+
'decimal-int-string' => DecimalIntString::class,
158162
'numeric' => Numeric_::class,
159163
'trait-string' => TraitString::class,
160164
'enum-string' => EnumString::class,
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 DecimalIntStringTest extends TestCase
20+
{
21+
public function testCreate(): void
22+
{
23+
$type = new DecimalIntString();
24+
25+
$this->assertEquals(new String_(), $type->underlyingType());
26+
}
27+
28+
public function testToString(): void
29+
{
30+
$this->assertSame('decimal-int-string', (string) (new DecimalIntString()));
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\String_;
17+
use PHPUnit\Framework\TestCase;
18+
19+
final class NonDecimalIntStringTest extends TestCase
20+
{
21+
public function testCreate(): void
22+
{
23+
$type = new NonDecimalIntString();
24+
25+
$this->assertEquals(new String_(), $type->underlyingType());
26+
}
27+
28+
public function testToString(): void
29+
{
30+
$this->assertSame('non-decimal-int-string', (string) (new NonDecimalIntString()));
31+
}
32+
}

0 commit comments

Comments
 (0)