Total Complexity | 10 |
Total Lines | 75 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
16 | final class DecimalNumber implements LabelGenerator |
||
17 | { |
||
18 | /** |
||
19 | * @var int |
||
20 | */ |
||
21 | private $int; |
||
22 | |||
23 | /** |
||
24 | * New instance. |
||
25 | */ |
||
26 | 57 | public function __construct(int $int = 1) |
|
27 | { |
||
28 | 57 | if (0 >= $int) { |
|
29 | 18 | $int = 1; |
|
30 | } |
||
31 | |||
32 | 57 | $this->int = $int; |
|
33 | 57 | } |
|
34 | |||
35 | /** |
||
36 | * {@inheritdoc} |
||
37 | */ |
||
38 | 36 | public function generate(int $nbLabels): \Iterator |
|
39 | { |
||
40 | 36 | if (0 >= $nbLabels) { |
|
41 | 9 | return; |
|
42 | } |
||
43 | |||
44 | 27 | $count = 0; |
|
45 | 27 | $end = $this->int + $nbLabels; |
|
46 | 27 | $value = $this->int; |
|
47 | 27 | while ($value < $end) { |
|
48 | 27 | yield $count => $this->format((string) $value); |
|
49 | |||
50 | 27 | ++$count; |
|
51 | 27 | ++$value; |
|
52 | } |
||
53 | 27 | } |
|
54 | |||
55 | /** |
||
56 | * {@inheritdoc} |
||
57 | */ |
||
58 | 30 | public function format(string $label): string |
|
59 | { |
||
60 | 30 | return $label; |
|
61 | } |
||
62 | |||
63 | /** |
||
64 | * Returns the starting Letter. |
||
65 | */ |
||
66 | 6 | public function startingAt(): int |
|
69 | } |
||
70 | |||
71 | /** |
||
72 | * Return an instance with the starting Letter. |
||
73 | * |
||
74 | * This method MUST retain the state of the current instance, and return |
||
75 | * an instance that contains the starting Letter. |
||
76 | */ |
||
77 | 6 | public function startsWith(int $int): self |
|
91 | } |
||
92 | } |
||
93 |