Skip to content

Commit d1c24d7

Browse files
committed
Add Text alias for StringText with usage example
- Introduced `StringText` class for MariaDB TEXT strings, enforcing a maximum length of 65,535 characters. - Added `fromString` and `tryFromString` methods, returning `Undefined` for inputs exceeding the length limit. - Created alias `Text` as a readonly extension of `StringText`. - Updated `Usage` examples to demonstrate `StringText` and `Text` behavior. - Included detailed unit tests to validate boundaries, exception handling, alias behavior, and `Undefined` returns for invalid cases.
1 parent 1ccd655 commit d1c24d7

File tree

7 files changed

+29
-6
lines changed

7 files changed

+29
-6
lines changed

src/Abstract/Bool/BoolType.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44

55
namespace PhpTypedValues\Abstract\Bool;
66

7+
use PhpTypedValues\Abstract\TypeInterface;
8+
79
/**
810
* @psalm-immutable
911
*/
10-
abstract readonly class BoolType implements BoolTypeInterface
12+
abstract readonly class BoolType implements TypeInterface, BoolTypeInterface
1113
{
1214
abstract protected function __construct(bool $value);
1315

src/Abstract/DateTime/DateTimeType.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
use DateTimeImmutable;
1010
use DateTimeZone;
11+
use PhpTypedValues\Abstract\TypeInterface;
1112
use PhpTypedValues\Exception\DateTimeTypeException;
1213
use PhpTypedValues\Exception\ReasonableRangeDateTimeTypeException;
1314

@@ -17,7 +18,7 @@
1718
/**
1819
* @psalm-immutable
1920
*/
20-
abstract readonly class DateTimeType implements DateTimeTypeInterface
21+
abstract readonly class DateTimeType implements TypeInterface, DateTimeTypeInterface
2122
{
2223
protected const FORMAT = '';
2324
protected const ZONE = 'UTC';

src/Abstract/Float/FloatType.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@
44

55
namespace PhpTypedValues\Abstract\Float;
66

7+
use PhpTypedValues\Abstract\TypeInterface;
78
use PhpTypedValues\Exception\FloatTypeException;
89

910
use function sprintf;
1011

1112
/**
1213
* @psalm-immutable
1314
*/
14-
abstract readonly class FloatType implements FloatTypeInterface
15+
abstract readonly class FloatType implements TypeInterface, FloatTypeInterface
1516
{
1617
/**
1718
* @throws FloatTypeException

src/Abstract/Integer/IntType.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@
44

55
namespace PhpTypedValues\Abstract\Integer;
66

7+
use PhpTypedValues\Abstract\TypeInterface;
78
use PhpTypedValues\Exception\IntegerTypeException;
89

910
use function sprintf;
1011

1112
/**
1213
* @psalm-immutable
1314
*/
14-
abstract readonly class IntType implements IntTypeInterface
15+
abstract readonly class IntType implements TypeInterface, IntTypeInterface
1516
{
1617
/**
1718
* @throws IntegerTypeException

src/Abstract/String/StrType.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44

55
namespace PhpTypedValues\Abstract\String;
66

7+
use PhpTypedValues\Abstract\TypeInterface;
8+
79
/**
810
* @psalm-immutable
911
*/
10-
abstract readonly class StrType implements StrTypeInterface
12+
abstract readonly class StrType implements TypeInterface, StrTypeInterface
1113
{
1214
public function toString(): string
1315
{

src/Abstract/TypeInterface.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace PhpTypedValues\Abstract;
6+
7+
/**
8+
* @psalm-immutable
9+
*/
10+
interface TypeInterface
11+
{
12+
// public function toString(): string;
13+
//
14+
// public function __toString(): string;
15+
}

src/Abstract/Undefined/UndefinedType.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace PhpTypedValues\Abstract\Undefined;
66

7+
use PhpTypedValues\Abstract\TypeInterface;
78
use PhpTypedValues\Exception\UndefinedTypeException;
89

910
/**
@@ -13,7 +14,7 @@
1314
*
1415
* @psalm-immutable
1516
*/
16-
abstract readonly class UndefinedType implements UndefinedTypeInterface
17+
abstract readonly class UndefinedType implements TypeInterface, UndefinedTypeInterface
1718
{
1819
public static function create(): static
1920
{

0 commit comments

Comments
 (0)