Skip to content

Commit 71eacfa

Browse files
committed
wip
1 parent c6dc137 commit 71eacfa

23 files changed

+471
-77
lines changed

src/Attribute/With.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,10 @@
1010
namespace fab2s\Dt0\Attribute;
1111

1212
use Attribute;
13-
use fab2s\Dt0\Exception\AttributeException;
1413

1514
#[Attribute(Attribute::TARGET_CLASS)]
1615
class With extends WithAbstract
1716
{
18-
/**
19-
* @throws AttributeException
20-
*/
2117
public function __construct(
2218
WithProp|string ...$withCasts,
2319
) {

src/Attribute/WithProp.php

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,38 +9,27 @@
99

1010
namespace fab2s\Dt0\Attribute;
1111

12-
use fab2s\Dt0\Caster\CasterInterface;
13-
use fab2s\Dt0\Exception\AttributeException;
14-
1512
class WithProp extends WithPropAbstract
1613
{
17-
public readonly ?string $getter;
18-
public readonly CasterInterface|string|null $caster;
14+
public readonly string|bool|null $getter;
15+
public readonly ?string $name;
1916

20-
/**
21-
* @throws AttributeException
22-
*/
2317
public function __construct(
2418
?string $name = null,
25-
?string $getter = null,
26-
CasterInterface|string|null $caster = null,
19+
string|bool|null $getter = null,
2720
) {
28-
$this->caster = $this->getCasterInstance($caster);
29-
$this->getter = $getter ?? $name;
21+
$this->name = $name;
22+
$this->getter = $getter;
3023

31-
if ($name !== null) {
32-
$this->setPropName($name);
24+
if ($this->name !== null) {
25+
$this->setPropName($this->name);
3326
}
3427
}
3528

36-
/**
37-
* @throws AttributeException
38-
*/
3929
public static function make(
4030
?string $name = null,
4131
?string $getter = null,
42-
CasterInterface|string|null $cast = null,
4332
): static {
44-
return new static($name, $getter, $cast);
33+
return new static($name, $getter);
4534
}
4635
}

src/Attribute/WithPropAbstract.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,13 @@
99

1010
namespace fab2s\Dt0\Attribute;
1111

12-
use fab2s\Dt0\Caster\CasterInterface;
13-
use fab2s\Dt0\Concern\HasCasterInstance;
1412
use fab2s\Dt0\Concern\HasDeclaringFqn;
1513
use fab2s\Dt0\Concern\HasPropName;
1614

1715
abstract class WithPropAbstract implements WithPropInterface
1816
{
19-
use HasCasterInstance;
2017
use HasDeclaringFqn;
2118
use HasPropName;
22-
public readonly ?string $getter;
23-
public readonly CasterInterface|string|null $caster;
19+
public readonly ?string $name;
20+
public readonly string|bool|null $getter;
2421
}

src/Caster/ArrayOfCaster.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,16 @@ public function __construct(
4646
$this->scalarCaster = $this->logicalType instanceof ScalarType ? new ScalarCaster($this->logicalType) : null;
4747
}
4848

49+
/**
50+
* @throws CasterException
51+
*/
52+
public static function make(
53+
/** @var class-string<Dt0|UnitEnum>|ScalarType|string $type */
54+
ScalarType|string $type,
55+
): static {
56+
return new static($type);
57+
}
58+
4959
/**
5060
* @throws CasterException
5161
* @throws Dt0Exception

src/Caster/CarbonCaster.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,16 @@ public function __construct(
3030
$this->dateTimeClass = $immutable ? CarbonImmutable::class : Carbon::class;
3131
}
3232

33+
/**
34+
* @throws Exception
35+
*/
36+
public static function make(
37+
DateTimeZone|string|null $timeZone = null,
38+
bool $immutable = true,
39+
): static {
40+
return new static($timeZone, $immutable);
41+
}
42+
3343
/**
3444
* @throws Exception
3545
*/

src/Caster/NoOpCaster.php renamed to src/Caster/CasterCollection.php

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,4 @@
99

1010
namespace fab2s\Dt0\Caster;
1111

12-
use fab2s\Dt0\Dt0;
13-
14-
class NoOpCaster extends CasterAbstract
15-
{
16-
public static function make(): static
17-
{
18-
return new static;
19-
}
20-
21-
public function cast(mixed $value, Dt0|array|null $data = null): mixed
22-
{
23-
return $value;
24-
}
25-
}
12+
class CasterCollection extends CasterCollectionAbstract {}

src/Caster/DateTimeCaster.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,16 @@ public function __construct(
3131
$this->dateTimeClass = $immutable ? DateTimeImmutable::class : DateTime::class;
3232
}
3333

34+
/**
35+
* @throws DateInvalidTimeZoneException
36+
*/
37+
public static function make(
38+
DateTimeZone|string|null $timeZone = null,
39+
bool $immutable = true,
40+
): static {
41+
return new static($timeZone, $immutable);
42+
}
43+
3444
/**
3545
* @throws Exception
3646
*/

src/Caster/DateTimeFormatCaster.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,16 @@ public function __construct(
3131
$this->dateTimeClass = DateTimeImmutable::class;
3232
}
3333

34+
/**
35+
* @throws DateInvalidTimeZoneException
36+
*/
37+
public static function make(
38+
string $format,
39+
DateTimeZone|string|null $timeZone = null,
40+
): static {
41+
return new static($format, $timeZone);
42+
}
43+
3444
/**
3545
* @throws Exception
3646
*/

src/Caster/Dt0Caster.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,13 @@
1313
use fab2s\Dt0\Exception\CasterException;
1414
use fab2s\Dt0\Exception\Dt0Exception;
1515
use JsonException;
16+
use ReflectionException;
1617

1718
class Dt0Caster extends CasterAbstract
1819
{
1920
/**
2021
* @throws Dt0Exception
22+
* @throws CasterException
2123
*/
2224
public function __construct(
2325
/** @var class-string<Dt0> */
@@ -28,9 +30,21 @@ public function __construct(
2830
}
2931
}
3032

33+
/**
34+
* @throws Dt0Exception
35+
* @throws CasterException
36+
*/
37+
public static function make(
38+
/** @var class-string<Dt0> $dt0Fqn */
39+
string $dt0Fqn,
40+
): static {
41+
return new static($dt0Fqn);
42+
}
43+
3144
/**
3245
* @throws Dt0Exception
3346
* @throws JsonException
47+
* @throws ReflectionException
3448
*/
3549
public function cast(mixed $value, array|Dt0|null $data = null): ?Dt0
3650
{

src/Caster/MathCaster.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ public function __construct(
2222
$this->precision = max(0, $precision);
2323
}
2424

25+
public static function make(
26+
int $precision = Math::PRECISION,
27+
): static {
28+
return new static($precision);
29+
}
30+
2531
public function cast(mixed $value, array|Dt0|null $data = null): Math
2632
{
2733
return Math::number($value)->setPrecision($this->precision);

0 commit comments

Comments
 (0)