Skip to content

Commit 98ff3ac

Browse files
committed
Document typed value contracts and base implementations
- Added detailed API documentation to type interfaces (`IntTypeInterface`, `FloatTypeInterface`, `StrTypeInterface`, etc.) and base classes (`IntType`, `FloatType`, `StrType`, etc.). - Improved examples showcasing factory methods, formatting helpers, and validation behaviors. - Expanded `UndefinedType` to include new methods (`toInt`, `toFloat`) with exception handling. - Enhanced clarity and usability of all typed value definitions across the library.
1 parent 3cc5ad6 commit 98ff3ac

File tree

13 files changed

+145
-6
lines changed

13 files changed

+145
-6
lines changed

src/Abstract/Bool/BoolType.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,16 @@
77
use PhpTypedValues\Abstract\TypeInterface;
88

99
/**
10+
* Base implementation for boolean typed values.
11+
*
12+
* Provides common formatting helpers and factory methods for bool-backed
13+
* value objects. Concrete boolean types extend this class and add
14+
* domain-specific validation if needed.
15+
*
16+
* Example
17+
* - $v = MyBoolean::fromBool(true);
18+
* - $v->toString(); // "true"
19+
*
1020
* @psalm-immutable
1121
*/
1222
abstract readonly class BoolType implements TypeInterface, BoolTypeInterface

src/Abstract/Bool/BoolTypeInterface.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,16 @@
77
use PhpTypedValues\Undefined\Alias\Undefined;
88

99
/**
10+
* Contract for boolean typed values.
11+
*
12+
* Describes the API that all bool-backed value objects must implement,
13+
* including factories, accessors and formatting helpers.
14+
*
15+
* Example
16+
* - $v = MyBoolean::fromString('true');
17+
* - $v->value(); // true
18+
* - (string) $v; // "true"
19+
*
1020
* @psalm-immutable
1121
*/
1222
interface BoolTypeInterface

src/Abstract/DateTime/DateTimeType.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,16 @@
1616
use function sprintf;
1717

1818
/**
19+
* Base implementation for DateTime typed values.
20+
*
21+
* Provides strict parsing with detailed error aggregation, round-trip
22+
* validation against the format, timezone normalization and reasonable
23+
* timestamp range checks.
24+
*
25+
* Example
26+
* - $v = MyDateTime::fromString('2025-01-02T03:04:05+00:00');
27+
* - $v->toString(); // '2025-01-02T03:04:05+00:00'
28+
*
1929
* @psalm-immutable
2030
*/
2131
abstract readonly class DateTimeType implements TypeInterface, DateTimeTypeInterface

src/Abstract/DateTime/DateTimeTypeInterface.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,16 @@
88
use PhpTypedValues\Undefined\Alias\Undefined;
99

1010
/**
11+
* Contract for DateTime typed values.
12+
*
13+
* Declares the API for value objects backed by DateTimeImmutable, including
14+
* factories from strings and native DateTime, string formatting, and
15+
* a safe try-from factory returning Undefined on invalid input.
16+
*
17+
* Example
18+
* - $v = MyDateTime::fromDateTime(new DateTimeImmutable('2025-01-02T03:04:05+00:00'));
19+
* - $v->toString(); // '2025-01-02T03:04:05+00:00'
20+
*
1121
* @psalm-immutable
1222
*/
1323
interface DateTimeTypeInterface

src/Abstract/Float/FloatType.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,16 @@
1010
use function sprintf;
1111

1212
/**
13+
* Base implementation for float-typed values.
14+
*
15+
* Provides common validation for float strings and formatting helpers for
16+
* value objects backed by float primitives.
17+
*
18+
* Example
19+
* - $v = MyFloat::fromString('3.14');
20+
* - $v->value(); // 3.14 (float)
21+
* - (string) $v; // "3.14"
22+
*
1323
* @psalm-immutable
1424
*/
1525
abstract readonly class FloatType implements TypeInterface, FloatTypeInterface

src/Abstract/Float/FloatTypeInterface.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,15 @@
77
use PhpTypedValues\Undefined\Alias\Undefined;
88

99
/**
10+
* Contract for float-typed values.
11+
*
12+
* Declares the API for float-backed value objects, including creation from
13+
* native float or validated string, and formatting helpers.
14+
*
15+
* Example
16+
* - $v = MyFloat::fromFloat(1.5);
17+
* - $v->toString(); // "1.5"
18+
*
1019
* @psalm-immutable
1120
*/
1221
interface FloatTypeInterface

src/Abstract/Integer/IntType.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,16 @@
1010
use function sprintf;
1111

1212
/**
13+
* Base implementation for integer-typed values.
14+
*
15+
* Contains strict string-to-int validation and common formatting helpers
16+
* for value objects backed by integer primitives.
17+
*
18+
* Example
19+
* - $v = MyInt::fromString('42');
20+
* - $v->value(); // 42 (int)
21+
* - (string) $v; // "42"
22+
*
1323
* @psalm-immutable
1424
*/
1525
abstract readonly class IntType implements TypeInterface, IntTypeInterface

src/Abstract/Integer/IntTypeInterface.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,15 @@
77
use PhpTypedValues\Undefined\Alias\Undefined;
88

99
/**
10+
* Contract for integer-typed values.
11+
*
12+
* Declares the API for int-backed value objects, including strict parsing
13+
* from string/native int and formatting helpers.
14+
*
15+
* Example
16+
* - $v = MyInt::fromInt(7);
17+
* - $v->toString(); // "7"
18+
*
1019
* @psalm-immutable
1120
*/
1221
interface IntTypeInterface

src/Abstract/String/StrType.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,16 @@
77
use PhpTypedValues\Abstract\TypeInterface;
88

99
/**
10+
* Base implementation for string-typed values.
11+
*
12+
* Provides common formatting helpers for value objects backed by strings.
13+
* Concrete string types extend this class and add domain-specific
14+
* validation/normalization.
15+
*
16+
* Example
17+
* - $v = MyString::fromString('hello');
18+
* - $v->toString(); // "hello"
19+
*
1020
* @psalm-immutable
1121
*/
1222
abstract readonly class StrType implements TypeInterface, StrTypeInterface

src/Abstract/String/StrTypeInterface.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,15 @@
77
use PhpTypedValues\Undefined\Alias\Undefined;
88

99
/**
10+
* Contract for string-typed values.
11+
*
12+
* Declares the API for string-backed value objects, including factory
13+
* methods, accessors and formatting helpers.
14+
*
15+
* Example
16+
* - $v = MyString::fromString('abc');
17+
* - $v->value(); // 'abc'
18+
*
1019
* @psalm-immutable
1120
*/
1221
interface StrTypeInterface

0 commit comments

Comments
 (0)