Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
8 / 8 |
|
100.00% |
4 / 4 |
CRAP | |
100.00% |
1 / 1 |
FrmtrRange | |
100.00% |
8 / 8 |
|
100.00% |
4 / 4 |
5 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getRangeElementFrmtr | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
setRangeElementFrmtr | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
format | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
2 |
1 | <?php |
2 | |
3 | /** |
4 | * @author: Doug Wilbourne (dougwilbourne@gmail.com) |
5 | */ |
6 | |
7 | declare(strict_types=1); |
8 | |
9 | namespace pvc\frmtr\range; |
10 | |
11 | use pvc\interfaces\frmtr\FrmtrInterface; |
12 | use pvc\interfaces\struct\range\RangeInterface; |
13 | |
14 | /** |
15 | * Class FrmtrRange |
16 | */ |
17 | class FrmtrRange |
18 | { |
19 | /** |
20 | * @var FrmtrInterface<int|float> |
21 | */ |
22 | protected FrmtrInterface $rangeElementFrmtr; |
23 | |
24 | /** |
25 | * @param FrmtrInterface<int|float> $rangeElementFrmtr |
26 | */ |
27 | public function __construct(FrmtrInterface $rangeElementFrmtr) |
28 | { |
29 | $this->setRangeElementFrmtr($rangeElementFrmtr); |
30 | } |
31 | |
32 | /** |
33 | * @return FrmtrInterface<int|float> |
34 | */ |
35 | public function getRangeElementFrmtr(): FrmtrInterface |
36 | { |
37 | return $this->rangeElementFrmtr; |
38 | } |
39 | |
40 | /** |
41 | * @param FrmtrInterface<int|float> $rangeElementFrmtr |
42 | */ |
43 | public function setRangeElementFrmtr(FrmtrInterface $rangeElementFrmtr): void |
44 | { |
45 | $this->rangeElementFrmtr = $rangeElementFrmtr; |
46 | } |
47 | |
48 | /** |
49 | * format |
50 | * @param RangeInterface<int|float> $range |
51 | * @return string |
52 | */ |
53 | public function format(RangeInterface $range): string |
54 | { |
55 | $rangeArray = $range->getRange(); |
56 | |
57 | $result = $this->rangeElementFrmtr->format($rangeArray[0]); |
58 | |
59 | if ($rangeArray[0] != $rangeArray[1]) { |
60 | $result .= '-' . $this->rangeElementFrmtr->format($rangeArray[1]); |
61 | } |
62 | |
63 | return $result; |
64 | } |
65 | } |