| Total Complexity | 11 |
| Total Lines | 80 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 19 | final class LatinLetter implements LabelGenerator |
||
| 20 | { |
||
| 21 | /** |
||
| 22 | * @var string |
||
| 23 | */ |
||
| 24 | private $str; |
||
| 25 | |||
| 26 | /** |
||
| 27 | * New instance. |
||
| 28 | */ |
||
| 29 | 60 | public function __construct(string $str = 'A') |
|
| 32 | 60 | } |
|
| 33 | |||
| 34 | 60 | public function filterLetter(string $str): string |
|
| 35 | { |
||
| 36 | 60 | $str = trim($str); |
|
| 37 | 60 | if ('' === $str) { |
|
| 38 | 12 | return '0'; |
|
| 39 | } |
||
| 40 | |||
| 41 | 48 | if (1 !== preg_match('/^[A-Za-z]+$/', $str)) { |
|
| 42 | 6 | return 'A'; |
|
| 43 | } |
||
| 44 | |||
| 45 | 42 | return $str; |
|
| 46 | } |
||
| 47 | |||
| 48 | /** |
||
| 49 | * {@inheritdoc} |
||
| 50 | */ |
||
| 51 | 6 | public function format(string $label): string |
|
| 52 | { |
||
| 53 | 6 | return $label; |
|
| 54 | } |
||
| 55 | |||
| 56 | /** |
||
| 57 | * {@inheritdoc} |
||
| 58 | */ |
||
| 59 | 51 | public function generate(int $nbLabels): \Iterator |
|
| 71 | } |
||
| 72 | 51 | } |
|
| 73 | |||
| 74 | /** |
||
| 75 | * Returns the starting Letter. |
||
| 76 | */ |
||
| 77 | 3 | public function startingAt(): string |
|
| 80 | } |
||
| 81 | |||
| 82 | /** |
||
| 83 | * Return an instance with the starting Letter. |
||
| 84 | * |
||
| 85 | * This method MUST retain the state of the current instance, and return |
||
| 86 | * an instance that contains the starting Letter. |
||
| 87 | */ |
||
| 88 | 3 | public function startsWith(string $str): self |
|
| 99 | } |
||
| 100 | } |
||
| 101 |