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

tempestphp / tempest-framework / 14024978163

23 Mar 2025 05:55PM UTC coverage: 79.391% (-0.05%) from 79.441%
14024978163

push

github

web-flow
feat(view): cache Blade and Twig templates in internal storage (#1061)

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

912 existing lines in 110 files now uncovered.

10478 of 13198 relevant lines covered (79.39%)

91.09 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
    ) {
20
    }
1✔
21

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

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

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

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

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

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

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

50
        return $date;
1✔
51
    }
52
}
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