• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

tempestphp / tempest-framework / 14049246919

24 Mar 2025 09:42PM UTC coverage: 79.353% (-0.04%) from 79.391%
14049246919

push

github

web-flow
feat(support): support array parameters in string manipulations (#1073)

48 of 48 new or added lines in 2 files covered. (100.0%)

735 existing lines in 126 files now uncovered.

10492 of 13222 relevant lines covered (79.35%)

90.78 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

77.78
/src/Tempest/Mapper/src/Casters/DateTimeCaster.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace Tempest\Mapper\Casters;
6

7
use DateTime;
8
use DateTimeImmutable;
9
use DateTimeInterface;
10
use Tempest\Mapper\Caster;
11
use Tempest\Reflection\PropertyReflector;
12
use Tempest\Validation\Rules\DateTimeFormat;
13

14
final readonly class DateTimeCaster implements Caster
15
{
16
    public function __construct(
1✔
17
        private string $format = DateTimeFormat::FORMAT,
18
        private bool $immutable = true,
19
    ) {}
1✔
20

21
    public static function fromProperty(PropertyReflector $property): DateTimeCaster
1✔
22
    {
23
        $format = $property->getAttribute(DateTimeFormat::class)->format ?? DateTimeFormat::FORMAT;
1✔
24

25
        return match ($property->getType()->getName()) {
1✔
UNCOV
26
            DateTime::class => new DateTimeCaster($format, immutable: false),
×
27
            default => new DateTimeCaster($format, immutable: true),
1✔
28
        };
1✔
29
    }
30

31
    public function cast(mixed $input): ?DateTimeInterface
1✔
32
    {
33
        if (! $input) {
1✔
UNCOV
34
            return null;
×
35
        }
36

37
        if ($input instanceof DateTimeInterface) {
1✔
UNCOV
38
            return $input;
×
39
        }
40

41
        $class = $this->immutable ? DateTimeImmutable::class : DateTime::class;
1✔
42

43
        $date = $class::createFromFormat($this->format, $input);
1✔
44

45
        if (! $date) {
1✔
UNCOV
46
            return new $class($input);
×
47
        }
48

49
        return $date;
1✔
50
    }
51
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc