Skip to content

Commit 821ed31

Browse files
committed
Rename StrictType, AnyType, and OptionalType to EarlyFail, LateFail, and OptionalFail, and update all references in codebase and tests.
1 parent b5ecc4f commit 821ed31

File tree

7 files changed

+36
-36
lines changed

7 files changed

+36
-36
lines changed

src/Usage/Composite/Composite.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,28 @@
66

77
use const PHP_EOL;
88

9-
use PhpTypedValues\Usage\Example\AnyType;
10-
use PhpTypedValues\Usage\Example\OptionalType;
11-
use PhpTypedValues\Usage\Example\StrictType;
9+
use PhpTypedValues\Usage\Example\EarlyFail;
10+
use PhpTypedValues\Usage\Example\LateFail;
11+
use PhpTypedValues\Usage\Example\OptionalFail;
1212

1313
/**
1414
* COMPOSITE.
1515
*/
1616
echo PHP_EOL . '> COMPOSITE' . PHP_EOL;
1717

18-
$test = StrictType::fromScalars(id: 1, firstName: 'Foobar', height: 170);
18+
$test = EarlyFail::fromScalars(id: 1, firstName: 'Foobar', height: 170);
1919

2020
echo $test->getId()->toString() . PHP_EOL;
2121
echo $test->getFirstName()->toString() . PHP_EOL;
2222
echo $test->getHeight()->toString() . PHP_EOL;
2323

24-
$test = AnyType::fromScalars(id: 1, firstName: 'Foobar', height: 170);
24+
$test = LateFail::fromScalars(id: 1, firstName: 'Foobar', height: 170);
2525

2626
echo $test->getId()->toString() . PHP_EOL;
2727
echo $test->getFirstName()->toString() . PHP_EOL;
2828
echo $test->getHeight()->toString() . PHP_EOL;
2929

30-
$test = OptionalType::fromScalars(id: 1, firstName: 'Foobar', height: 170);
30+
$test = OptionalFail::fromScalars(id: 1, firstName: 'Foobar', height: 170);
3131

3232
echo $test->getId()->toString() . PHP_EOL;
3333
echo $test->getFirstName()->toString() . PHP_EOL;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*
1919
* @psalm-internal PhpTypedValues
2020
*/
21-
final readonly class StrictType
21+
final readonly class EarlyFail
2222
{
2323
public function __construct(
2424
private IntegerPositive $id,
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
*
1818
* @psalm-internal PhpTypedValues
1919
*/
20-
final readonly class AnyType
20+
final readonly class LateFail
2121
{
2222
public function __construct(
2323
private IntegerPositive $id,
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*
1919
* @psalm-internal PhpTypedValues
2020
*/
21-
final readonly class OptionalType
21+
final readonly class OptionalFail
2222
{
2323
public function __construct(
2424
private IntegerPositive $id,

tests/Unit/Usage/Example/StrictTypeTest.php renamed to tests/Unit/Usage/Example/EarlyFailTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,22 @@
44

55
use PhpTypedValues\Exception\FloatTypeException;
66
use PhpTypedValues\Exception\StringTypeException;
7-
use PhpTypedValues\Usage\Example\StrictType;
7+
use PhpTypedValues\Usage\Example\EarlyFail;
88

9-
it('constructs StrictType from scalars and exposes typed values', function (): void {
10-
$vo = StrictType::fromScalars(id: 1, firstName: 'Foobar', height: 170);
9+
it('constructs EarlyFail from scalars and exposes typed values', function (): void {
10+
$vo = EarlyFail::fromScalars(id: 1, firstName: 'Foobar', height: 170);
1111

1212
expect($vo->getId()->toString())->toBe('1');
1313
expect($vo->getFirstName()->toString())->toBe('Foobar');
1414
expect($vo->getHeight()->toString())->toBe('170');
1515
});
1616

1717
it('fails early when firstName is empty', function (): void {
18-
expect(fn() => StrictType::fromScalars(id: 1, firstName: '', height: 10.0))
18+
expect(fn() => EarlyFail::fromScalars(id: 1, firstName: '', height: 10.0))
1919
->toThrow(StringTypeException::class, 'Expected non-empty string, got ""');
2020
});
2121

2222
it('fails early when height is negative', function (): void {
23-
expect(fn() => StrictType::fromScalars(id: 1, firstName: 'Foobar', height: -10.0))
23+
expect(fn() => EarlyFail::fromScalars(id: 1, firstName: 'Foobar', height: -10.0))
2424
->toThrow(FloatTypeException::class, 'Expected positive float, got "-10"');
2525
});
Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,44 +4,44 @@
44

55
use PhpTypedValues\Exception\IntegerTypeException;
66
use PhpTypedValues\Undefined\Alias\Undefined;
7-
use PhpTypedValues\Usage\Example\AnyType;
7+
use PhpTypedValues\Usage\Example\LateFail;
88

9-
it('constructs AnyType from scalars/mixed and exposes typed values', function (): void {
10-
$vo = AnyType::fromScalars(id: 1, firstName: 'Foobar', height: 170);
9+
it('constructs LateFail from scalars/mixed and exposes typed values', function (): void {
10+
$vo = LateFail::fromScalars(id: 1, firstName: 'Foobar', height: 170);
1111

1212
expect($vo->getId()->toString())->toBe('1');
1313
expect($vo->getFirstName()->toString())->toBe('Foobar');
1414
expect($vo->getHeight()->toString())->toBe('170');
1515
});
1616

1717
it('coerces mixed valid values via tryFromMixed', function (): void {
18-
$vo = AnyType::fromScalars(id: 2, firstName: 123, height: '170.5');
18+
$vo = LateFail::fromScalars(id: 2, firstName: 123, height: '170.5');
1919

2020
expect($vo->getId()->toString())->toBe('2');
2121
expect($vo->getFirstName()->toString())->toBe('123');
2222
expect($vo->getHeight()->toString())->toBe('170.5');
2323
});
2424

2525
it('keeps Undefined for invalid optional firstName (late fail)', function (): void {
26-
$vo = AnyType::fromScalars(id: 1, firstName: '', height: 10);
26+
$vo = LateFail::fromScalars(id: 1, firstName: '', height: 10);
2727

2828
expect($vo->getFirstName())->toBeInstanceOf(Undefined::class);
2929
// height remains valid
3030
expect($vo->getHeight()->toString())->toBe('10');
3131
});
3232

3333
it('keeps Undefined for invalid optional height values (late fail)', function (): void {
34-
$vo1 = AnyType::fromScalars(id: 1, firstName: 'Foo', height: -10);
34+
$vo1 = LateFail::fromScalars(id: 1, firstName: 'Foo', height: -10);
3535
expect($vo1->getHeight())->toBeInstanceOf(Undefined::class);
3636

37-
$vo2 = AnyType::fromScalars(id: 1, firstName: 'Foo', height: null);
37+
$vo2 = LateFail::fromScalars(id: 1, firstName: 'Foo', height: null);
3838
expect($vo2->getHeight())->toBeInstanceOf(Undefined::class);
3939

40-
$vo3 = AnyType::fromScalars(id: 1, firstName: 'Foo', height: 'abc');
40+
$vo3 = LateFail::fromScalars(id: 1, firstName: 'Foo', height: 'abc');
4141
expect($vo3->getHeight())->toBeInstanceOf(Undefined::class);
4242
});
4343

4444
it('fails early on invalid id', function (): void {
45-
expect(fn() => AnyType::fromScalars(id: 0, firstName: 'Foo', height: 10))
45+
expect(fn() => LateFail::fromScalars(id: 0, firstName: 'Foo', height: 10))
4646
->toThrow(IntegerTypeException::class, 'Expected positive integer, got "0"');
4747
});

tests/Unit/Usage/Example/OptionalTypeTest.php renamed to tests/Unit/Usage/Example/OptionalFailTest.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,35 +6,35 @@
66
use PhpTypedValues\Exception\IntegerTypeException;
77
use PhpTypedValues\Float\FloatPositive;
88
use PhpTypedValues\Undefined\Alias\Undefined;
9-
use PhpTypedValues\Usage\Example\OptionalType;
9+
use PhpTypedValues\Usage\Example\OptionalFail;
1010

11-
it('constructs OptionalType from scalars and exposes typed values', function (): void {
12-
$vo = OptionalType::fromScalars(id: 1, firstName: 'Foobar', height: 170);
11+
it('constructs OptionalFail from scalars and exposes typed values', function (): void {
12+
$vo = OptionalFail::fromScalars(id: 1, firstName: 'Foobar', height: 170);
1313

1414
expect($vo->getId()->toString())->toBe('1');
1515
expect($vo->getFirstName()->toString())->toBe('Foobar');
1616
expect($vo->getHeight()->toString())->toBe('170');
1717
});
1818

1919
it('checks string cast', function (): void {
20-
$voInt = OptionalType::fromScalars(id: 1, firstName: 'Test', height: 99);
20+
$voInt = OptionalFail::fromScalars(id: 1, firstName: 'Test', height: 99);
2121
expect($voInt->getHeight()->value())->toBe(99.0);
2222
});
2323

2424
it('treats empty firstName as Undefined (late-fail semantics)', function (): void {
25-
$vo = OptionalType::fromScalars(id: 1, firstName: '', height: 10.0);
25+
$vo = OptionalFail::fromScalars(id: 1, firstName: '', height: 10.0);
2626
expect($vo->getFirstName())->toBeInstanceOf(Undefined::class);
2727
});
2828

2929
it('fails early when height is negative', function (): void {
30-
expect(fn() => OptionalType::fromScalars(id: 1, firstName: 'Foobar', height: -10.0))
30+
expect(fn() => OptionalFail::fromScalars(id: 1, firstName: 'Foobar', height: -10.0))
3131
->toThrow(FloatTypeException::class, 'Expected positive float, got "-10"');
3232
});
3333

3434
it('accepts int/float/numeric-string heights and preserves string formatting via fromString casting', function (): void {
35-
$asInt = OptionalType::fromScalars(id: 1, firstName: 'Foobar', height: 170);
36-
$asFloat = OptionalType::fromScalars(id: 1, firstName: 'Foobar', height: 170.5);
37-
$asString = OptionalType::fromScalars(id: 1, firstName: 'Foobar', height: '42.25');
35+
$asInt = OptionalFail::fromScalars(id: 1, firstName: 'Foobar', height: 170);
36+
$asFloat = OptionalFail::fromScalars(id: 1, firstName: 'Foobar', height: 170.5);
37+
$asString = OptionalFail::fromScalars(id: 1, firstName: 'Foobar', height: '42.25');
3838

3939
expect($asInt->getHeight())->toBeInstanceOf(FloatPositive::class)
4040
->and($asInt->getHeight()->toString())->toBe('170')
@@ -45,22 +45,22 @@
4545
});
4646

4747
it('treats null height as Undefined (late-fail semantics)', function (): void {
48-
$obj = OptionalType::fromScalars(id: 1, firstName: 'Foobar', height: null);
48+
$obj = OptionalFail::fromScalars(id: 1, firstName: 'Foobar', height: null);
4949
expect($obj->getHeight())->toBeInstanceOf(Undefined::class);
5050
});
5151

5252
it('null firstName produces Undefined via tryFromMixed while height succeeds', function (): void {
53-
$obj = OptionalType::fromScalars(id: 1, firstName: null, height: 180);
53+
$obj = OptionalFail::fromScalars(id: 1, firstName: null, height: 180);
5454
expect($obj->getFirstName())->toBeInstanceOf(Undefined::class)
5555
->and($obj->getHeight())->toBeInstanceOf(FloatPositive::class);
5656
});
5757

5858
it('invalid id throws IntegerTypeException with exact message', function (): void {
59-
expect(fn() => OptionalType::fromScalars(id: 0, firstName: 'Name', height: 100))
59+
expect(fn() => OptionalFail::fromScalars(id: 0, firstName: 'Name', height: 100))
6060
->toThrow(IntegerTypeException::class, 'Expected positive integer, got "0"');
6161
});
6262

6363
it('non-numeric height string throws FloatTypeException from assertFloatString', function (): void {
64-
expect(fn() => OptionalType::fromScalars(id: 1, firstName: 'Name', height: 'abc'))
64+
expect(fn() => OptionalFail::fromScalars(id: 1, firstName: 'Name', height: 'abc'))
6565
->toThrow(FloatTypeException::class, 'String "abc" has no valid float value');
6666
});

0 commit comments

Comments
 (0)