Skip to content

Commit 025d5a3

Browse files
committed
Refactor static return types across interfaces and implementations
- Updated `self` return types to `static` for improved covariant return type support in interfaces and classes. - Adjusted method signatures across various type interfaces and implementations (`BoolType`, `FloatType`, `IntType`, `DateTimeType`, etc.) accordingly. - Updated related examples in `README.md` and `USAGE.md` for consistency.
1 parent 302249f commit 025d5a3

File tree

10 files changed

+21
-21
lines changed

10 files changed

+21
-21
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ final class Profile
5454
int $id,
5555
string $firstName,
5656
string|float|int|null $height,
57-
): self {
58-
return new self(
57+
): static {
58+
return new static(
5959
PositiveInt::fromInt($id),
6060
NonEmptyStr::fromString($firstName),
6161
$height !== null ? FloatNonNegative::fromString((string) $height) : null,

docs/USAGE.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,17 +98,17 @@ readonly class EvenPositiveInt extends IntType
9898
}
9999

100100
/** @throws IntegerTypeException */
101-
public static function fromInt(int $value): self
101+
public static function fromInt(int $value): static
102102
{
103-
return new self($value);
103+
return new static($value);
104104
}
105105

106106
/** @throws IntegerTypeException */
107-
public static function fromString(string $value): self
107+
public static function fromString(string $value): static
108108
{
109109
parent::assertIntegerString($value);
110110

111-
return new self((int) $value);
111+
return new static((int) $value);
112112
}
113113
}
114114

@@ -151,8 +151,8 @@ final class Profile
151151
?string $middleName,
152152
?string $birthDateAtom, // e.g. "2025-01-02T03:04:05+00:00"
153153
int|float|string|null $heightM
154-
): self {
155-
return new self(
154+
): static {
155+
return new static(
156156
IntegerPositive::fromInt($id),
157157
StringNonEmpty::fromString($firstName),
158158
StringNonEmpty::fromString($lastName),

src/Abstract/Bool/BoolType.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public function toString(): string
1616
return $this->value() ? 'true' : 'false';
1717
}
1818

19-
public static function fromBool(bool $value): self
19+
public static function fromBool(bool $value): static
2020
{
2121
return new static($value);
2222
}

src/Abstract/Bool/BoolTypeInterface.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ interface BoolTypeInterface
1111
{
1212
public function value(): bool;
1313

14-
public static function fromString(string $value): self;
14+
public static function fromString(string $value): static;
1515

16-
public static function fromBool(bool $value): self;
16+
public static function fromBool(bool $value): static;
1717

1818
public function toString(): string;
1919
}

src/Abstract/DateTime/DateTimeTypeInterface.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ interface DateTimeTypeInterface
1313
{
1414
public function value(): DateTimeImmutable;
1515

16-
public static function fromDateTime(DateTimeImmutable $value): self;
16+
public static function fromDateTime(DateTimeImmutable $value): static;
1717

1818
public function toString(): string;
1919

20-
public static function fromString(string $value): self;
20+
public static function fromString(string $value): static;
2121
}

src/Abstract/Float/FloatTypeInterface.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ interface FloatTypeInterface
1111
{
1212
public function value(): float;
1313

14-
public static function fromFloat(float $value): self;
14+
public static function fromFloat(float $value): static;
1515

1616
public function toString(): string;
1717

18-
public static function fromString(string $value): self;
18+
public static function fromString(string $value): static;
1919
}

src/Abstract/Integer/IntTypeInterface.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ interface IntTypeInterface
1111
{
1212
public function value(): int;
1313

14-
public static function fromInt(int $value): self;
14+
public static function fromInt(int $value): static;
1515

1616
public function toString(): string;
1717

18-
public static function fromString(string $value): self;
18+
public static function fromString(string $value): static;
1919
}

src/Abstract/String/StrTypeInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ interface StrTypeInterface
1111
{
1212
public function value(): string;
1313

14-
public static function fromString(string $value): self;
14+
public static function fromString(string $value): static;
1515

1616
public function toString(): string;
1717
}

src/Abstract/Undefined/UndefinedTypeInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*/
1010
interface UndefinedTypeInterface
1111
{
12-
public static function create(): self;
12+
public static function create(): static;
1313

1414
public function value(): void;
1515

src/Bool/BoolStandard.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function __construct(bool $value)
2727
$this->value = $value;
2828
}
2929

30-
public static function tryFromString(string $value): self|UndefinedStandard
30+
public static function tryFromString(string $value): static|UndefinedStandard
3131
{
3232
try {
3333
return static::fromString($value);
@@ -36,7 +36,7 @@ public static function tryFromString(string $value): self|UndefinedStandard
3636
}
3737
}
3838

39-
public static function tryFromInt(int $value): self|UndefinedStandard
39+
public static function tryFromInt(int $value): static|UndefinedStandard
4040
{
4141
try {
4242
return static::fromInt($value);

0 commit comments

Comments
 (0)