Skip to content

Commit fe34f86

Browse files
committed
Add support for truthy-string
1 parent b0020f7 commit fe34f86

4 files changed

Lines changed: 72 additions & 0 deletions

File tree

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: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
use phpDocumentor\Reflection\PseudoTypes\StringValue;
6060
use phpDocumentor\Reflection\PseudoTypes\TraitString;
6161
use phpDocumentor\Reflection\PseudoTypes\True_;
62+
use phpDocumentor\Reflection\PseudoTypes\TruthyString;
6263
use phpDocumentor\Reflection\PseudoTypes\ValueOf;
6364
use phpDocumentor\Reflection\Types\AggregatedType;
6465
use phpDocumentor\Reflection\Types\Array_;
@@ -181,6 +182,7 @@ final class TypeResolver
181182
'list' => List_::class,
182183
'non-empty-list' => NonEmptyList::class,
183184
'non-falsy-string' => NonFalsyString::class,
185+
'truthy-string' => TruthyString::class,
184186
];
185187

186188
/**
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 TruthyStringTest extends TestCase
20+
{
21+
public function testCreate(): void
22+
{
23+
$type = new TruthyString();
24+
25+
$this->assertEquals(new String_(), $type->underlyingType());
26+
}
27+
28+
public function testToString(): void
29+
{
30+
$this->assertSame('truthy-string', (string) (new TruthyString()));
31+
}
32+
}

tests/unit/TypeResolverTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
use phpDocumentor\Reflection\PseudoTypes\StringValue;
6060
use phpDocumentor\Reflection\PseudoTypes\TraitString;
6161
use phpDocumentor\Reflection\PseudoTypes\True_;
62+
use phpDocumentor\Reflection\PseudoTypes\TruthyString;
6263
use phpDocumentor\Reflection\PseudoTypes\ValueOf;
6364
use phpDocumentor\Reflection\Types\Array_;
6465
use phpDocumentor\Reflection\Types\Boolean;
@@ -677,6 +678,7 @@ public function provideKeywords(): array
677678
['non-empty-list', NonEmptyList::class],
678679
['non-empty-array', NonEmptyArray::class],
679680
['non-falsy-string', NonFalsyString::class],
681+
['truthy-string', TruthyString::class],
680682
];
681683
}
682684

0 commit comments

Comments
 (0)