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

h4kuna / number-format / 6186467286

14 Sep 2023 01:51PM UTC coverage: 98.621% (-1.4%) from 100.0%
6186467286

push

github

h4kuna
Add __invoke for use in callback

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

286 of 290 relevant lines covered (98.62%)

0.99 hits per line

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

94.12
/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
                $that = clone $this;
1✔
36
                $that->nbsp = $nbsp ?? $that->nbsp;
1✔
37
                $that->emptyValue = $emptyValue ?? $that->emptyValue;
1✔
38
                $that->initSpace();
1✔
39

40
                return $that;
1✔
41
        }
42

43

44
        public function format(?DateTimeInterface $dateTime): string
1✔
45
        {
46
                if ($dateTime === null) {
1✔
47
                        $result = $this->emptyValueSpace;
1✔
48
                } else {
49
                        $result = $this->formatter->format($dateTime);
1✔
50
                        assert(is_string($result));
51
                }
52

53
                return $this->nbsp ? Space::nbsp($result) : $result;
1✔
54
        }
55

56

57
        public function __invoke(?DateTimeInterface $dateTime): string
58
        {
59
                return $this->format($dateTime);
×
60
        }
61

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