Skip to content

Commit 320e217

Browse files
committed
Add NonBlankStr alias for StringNonBlank with usage example
- Introduced `NonBlankStr` as a readonly alias for `StringNonBlank`. - Enhanced `Usage` examples to demonstrate `NonBlankStr` usage.
1 parent f5b4de7 commit 320e217

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/String/Alias/NonBlankStr.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace PhpTypedValues\String\Alias;
6+
7+
use PhpTypedValues\String\StringNonBlank;
8+
9+
/**
10+
* Alias of Non-blank string value.
11+
*
12+
* Example "hello", blank string like " " will fail.
13+
*
14+
* @psalm-immutable
15+
*/
16+
readonly class NonBlankStr extends StringNonBlank
17+
{
18+
}

src/Usage/String.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22

33
use PhpTypedValues\String\Alias\JsonStr;
4+
use PhpTypedValues\String\Alias\NonBlankStr;
45
use PhpTypedValues\String\Alias\NonEmptyStr;
56
use PhpTypedValues\String\Alias\Str;
67
use PhpTypedValues\String\Alias\StrType;
@@ -26,6 +27,7 @@
2627
echo StringNonEmpty::tryFromString('hi')->toString() . \PHP_EOL;
2728
echo StringStandard::tryFromString('hi')->toString() . \PHP_EOL;
2829
// NonBlank usage (valid and try*)
30+
echo NonBlankStr::fromString(' hi ')->toString() . \PHP_EOL;
2931
echo StringNonBlank::fromString(' hi ')->toString() . \PHP_EOL;
3032
$nb = StringNonBlank::tryFromString(' ');
3133
if (!($nb instanceof Undefined)) {

0 commit comments

Comments
 (0)