• 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

92.86
/src/Number/Formatters/IntlNumberFormatter.php
1
<?php declare(strict_types=1);
2

3
namespace h4kuna\Format\Number\Formatters;
4

5
use h4kuna\Format\Number\Formatter;
6
use h4kuna\Format\Utils\Space;
7

8
/**
9
 * NumberFormatter default settings:
10
 *  - zeroClear: ZeroClear::DECIMALS
11
 *  - nbsp: true
12
 */
13
final class IntlNumberFormatter implements Formatter
14
{
15
        public function __construct(
1✔
16
                private \NumberFormatter $formatter,
17
                public string $emptyValue = '',
18
                public bool $zeroIsEmpty = false,
19
        )
20
        {
21
                $this->emptyValue = Space::nbsp($this->emptyValue);
1✔
22
        }
1✔
23

24

25
        public function modify(
1✔
26
                ?string $emptyValue = null,
27
                ?bool $zeroIsEmpty = null,
28
        ): self
29
        {
30
                $that = clone $this;
1✔
31
                $that->zeroIsEmpty = $zeroIsEmpty ?? $that->zeroIsEmpty;
1✔
32
                $that->emptyValue = $emptyValue === null ? $this->emptyValue : Space::nbsp($emptyValue);
1✔
33

34
                return $that;
1✔
35
        }
36

37

38
        public function format(string|int|float|null $number): string
1✔
39
        {
40
                if (is_numeric($number) === false || ($this->zeroIsEmpty && (int) $number === 0)) {
1✔
41
                        return $this->emptyValue;
1✔
42
                }
43

44
                $result = $this->formatter->format(is_string($number) ? (float) $number : $number);
1✔
45
                assert(is_string($result));
46

47
                return $result;
1✔
48
        }
49

50

51
        public function __invoke(float|int|string|null $number): string
52
        {
53
                return $this->format($number);
×
54
        }
55

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