Skip to content

Commit b0020f7

Browse files
committed
Add support for non-falsy-string
1 parent ace4950 commit b0020f7

4 files changed

Lines changed: 72 additions & 0 deletions

File tree

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+
}

src/TypeResolver.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
use phpDocumentor\Reflection\PseudoTypes\NonEmptyList;
4545
use phpDocumentor\Reflection\PseudoTypes\NonEmptyLowercaseString;
4646
use phpDocumentor\Reflection\PseudoTypes\NonEmptyString;
47+
use phpDocumentor\Reflection\PseudoTypes\NonFalsyString;
4748
use phpDocumentor\Reflection\PseudoTypes\Numeric_;
4849
use phpDocumentor\Reflection\PseudoTypes\NumericString;
4950
use phpDocumentor\Reflection\PseudoTypes\ObjectShape;
@@ -179,6 +180,7 @@ final class TypeResolver
179180
'never' => Never_::class,
180181
'list' => List_::class,
181182
'non-empty-list' => NonEmptyList::class,
183+
'non-falsy-string' => NonFalsyString::class,
182184
];
183185

184186
/**
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+
}

tests/unit/TypeResolverTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
use phpDocumentor\Reflection\PseudoTypes\NonEmptyList;
4545
use phpDocumentor\Reflection\PseudoTypes\NonEmptyLowercaseString;
4646
use phpDocumentor\Reflection\PseudoTypes\NonEmptyString;
47+
use phpDocumentor\Reflection\PseudoTypes\NonFalsyString;
4748
use phpDocumentor\Reflection\PseudoTypes\Numeric_;
4849
use phpDocumentor\Reflection\PseudoTypes\NumericString;
4950
use phpDocumentor\Reflection\PseudoTypes\ObjectShape;
@@ -675,6 +676,7 @@ public function provideKeywords(): array
675676
['list', List_::class],
676677
['non-empty-list', NonEmptyList::class],
677678
['non-empty-array', NonEmptyArray::class],
679+
['non-falsy-string', NonFalsyString::class],
678680
];
679681
}
680682

0 commit comments

Comments
 (0)