• 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

93.33
/src/Date/Formatters/DateTimeFormatter.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 DateTimeFormatter implements Formatter
10
{
11
        private string $emptyValueSpace;
12

13
        private string $formatSpace;
14

15

16
        public function __construct(
1✔
17
                public string $format,
18
                public bool $nbsp = true,
19
                public string $emptyValue = '',
20
        )
21
        {
22
                $this->initSpace();
1✔
23
        }
1✔
24

25

26
        private function initSpace(): void
27
        {
28
                $this->emptyValueSpace = $this->nbsp ? Space::nbsp($this->emptyValue) : $this->emptyValue;
1✔
29
                $this->formatSpace = $this->nbsp ? Space::nbsp($this->format) : $this->format;
1✔
30
        }
1✔
31

32

33
        public function modify(
1✔
34
                ?bool $nbsp = null,
35
                ?string $emptyValue = null,
36
        ): self
37
        {
38
                $that = clone $this;
1✔
39
                $that->nbsp = $nbsp ?? $that->nbsp;
1✔
40
                $that->emptyValue = $emptyValue ?? $that->emptyValue;
1✔
41
                $that->initSpace();
1✔
42

43
                return $that;
1✔
44
        }
45

46

47
        public function format(?DateTimeInterface $dateTime): string
1✔
48
        {
49
                return $dateTime === null ? $this->emptyValueSpace : $dateTime->format($this->formatSpace);
1✔
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