Total Complexity | 10 |
Total Lines | 75 |
Duplicated Lines | 0 % |
Changes | 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 | public function __construct(int $int = 1) |
||
27 | { |
||
28 | if (0 >= $int) { |
||
29 | $int = 1; |
||
30 | } |
||
31 | |||
32 | $this->int = $int; |
||
33 | } |
||
34 | |||
35 | /** |
||
36 | * {@inheritdoc} |
||
37 | */ |
||
38 | public function generate(int $nbLabels): \Iterator |
||
39 | { |
||
40 | if (0 >= $nbLabels) { |
||
41 | return; |
||
42 | } |
||
43 | |||
44 | $count = 0; |
||
45 | $end = $this->int + $nbLabels; |
||
46 | $value = $this->int; |
||
47 | while ($value < $end) { |
||
48 | yield $count => $this->format((string) $value); |
||
49 | |||
50 | ++$count; |
||
51 | ++$value; |
||
52 | } |
||
53 | } |
||
54 | |||
55 | /** |
||
56 | * {@inheritdoc} |
||
57 | */ |
||
58 | public function format(string $label): string |
||
59 | { |
||
60 | return $label; |
||
61 | } |
||
62 | |||
63 | /** |
||
64 | * Returns the starting Letter. |
||
65 | */ |
||
66 | 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 | public function startsWith(int $int): self |
||
91 | } |
||
92 | } |
||
93 |