Skip to content

Commit 397cbc6

Browse files
committed
Add __toString implementation across value objects and update tests
- Implemented `__toString` in `DateTimeType`, `IntType`, `FloatType`, `StrType`, and `UndefinedType`. - Extended interfaces to mandate `__toString` declaration. - Enhanced unit tests to validate `__toString` behavior for all value objects. - Introduced architectural tests to ensure all value objects and interfaces define `__toString`.
1 parent 4522011 commit 397cbc6

File tree

16 files changed

+139
-0
lines changed

16 files changed

+139
-0
lines changed

src/Abstract/DateTime/DateTimeType.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,4 +111,9 @@ public static function getFormat(): string
111111
{
112112
return static::FORMAT;
113113
}
114+
115+
public function __toString(): string
116+
{
117+
return $this->toString();
118+
}
114119
}

src/Abstract/DateTime/DateTimeTypeInterface.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,6 @@ public static function fromDateTime(DateTimeImmutable $value): static;
1818
public function toString(): string;
1919

2020
public static function fromString(string $value): static;
21+
22+
public function __toString(): string;
2123
}

src/Abstract/Float/FloatType.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,9 @@ public function toString(): string
2727
{
2828
return (string) $this->value();
2929
}
30+
31+
public function __toString(): string
32+
{
33+
return $this->toString();
34+
}
3035
}

src/Abstract/Float/FloatTypeInterface.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,6 @@ public static function fromFloat(float $value): static;
1616
public function toString(): string;
1717

1818
public static function fromString(string $value): static;
19+
20+
public function __toString(): string;
1921
}

src/Abstract/Integer/IntType.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,9 @@ public function toString(): string
2929
{
3030
return (string) $this->value();
3131
}
32+
33+
public function __toString(): string
34+
{
35+
return $this->toString();
36+
}
3237
}

src/Abstract/Integer/IntTypeInterface.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,6 @@ public static function fromInt(int $value): static;
1616
public function toString(): string;
1717

1818
public static function fromString(string $value): static;
19+
20+
public function __toString(): string;
1921
}

src/Abstract/String/StrType.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,9 @@ public function toString(): string
1313
{
1414
return $this->value();
1515
}
16+
17+
public function __toString(): string
18+
{
19+
return $this->toString();
20+
}
1621
}

src/Abstract/String/StrTypeInterface.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,6 @@ public function value(): string;
1414
public static function fromString(string $value): static;
1515

1616
public function toString(): string;
17+
18+
public function __toString(): string;
1719
}

src/Abstract/Undefined/UndefinedType.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,12 @@ public function value(): void
3535
{
3636
throw new UndefinedTypeException('Undefined type has no value.');
3737
}
38+
39+
/**
40+
* @throws UndefinedTypeException
41+
*/
42+
public function __toString(): string
43+
{
44+
throw new UndefinedTypeException('Undefined type cannot be converted to string.');
45+
}
3846
}

src/Abstract/Undefined/UndefinedTypeInterface.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,6 @@ public static function create(): static;
1414
public function value(): void;
1515

1616
public function toString(): void;
17+
18+
public function __toString(): string;
1719
}

0 commit comments

Comments
 (0)