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

h4kuna / number-format / 8415460082

25 Mar 2024 05:19AM UTC coverage: 98.625% (-0.02%) from 98.644%
8415460082

push

github

h4kuna
doc(IntlDateFormatterFactory): how to use

287 of 291 relevant lines covered (98.63%)

0.99 hits per line

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

92.31
/src/Date/Formatters/IntlDateFormatter.php
1
<?php declare(strict_types=1);
2

3
namespace h4kuna\Format\Date\Formatters;
4

5
use DateTimeInterface;
6
use h4kuna\Format\Date\Formatter;
7
use h4kuna\Format\Utils\Space;
8

9
final class IntlDateFormatter implements Formatter
10
{
11
        private string $emptyValueSpace;
12

13

14
        public function __construct(
1✔
15
                private \IntlDateFormatter $formatter,
16
                public bool $nbsp = true,
17
                public string $emptyValue = '',
18
        )
19
        {
20
                $this->initSpace();
1✔
21
        }
1✔
22

23

24
        private function initSpace(): void
25
        {
26
                $this->emptyValueSpace = $this->nbsp ? Space::nbsp($this->emptyValue) : $this->emptyValue;
1✔
27
        }
1✔
28

29

30
        public function modify(
1✔
31
                ?bool $nbsp = null,
32
                ?string $emptyValue = null,
33
        ): self
34
        {
35
                return new static($this->formatter, $nbsp ?? $this->nbsp, $emptyValue ?? $this->emptyValue);
1✔
36
        }
37

38

39
        public function format(?DateTimeInterface $dateTime): string
1✔
40
        {
41
                if ($dateTime === null) {
1✔
42
                        $result = $this->emptyValueSpace;
1✔
43
                } else {
44
                        $result = $this->formatter->format($dateTime);
1✔
45
                        assert(is_string($result));
46
                }
47

48
                return $this->nbsp ? Space::nbsp($result) : $result;
1✔
49
        }
50

51

52
        public function __invoke(?DateTimeInterface $dateTime): string
53
        {
54
                return $this->format($dateTime);
×
55
        }
56

57
}
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