| Total Complexity | 10 |
| Total Lines | 68 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 0 | ||
| 1 | <?php |
||
| 12 | trait ChunkableOptions |
||
| 13 | { |
||
| 14 | protected $chunks; |
||
| 15 | |||
| 16 | protected $chunkSize = 3; |
||
| 17 | |||
| 18 | /** |
||
| 19 | * @return array |
||
| 20 | */ |
||
| 21 | 19 | public function getChunks(int $chunkSize = null): array |
|
| 22 | { |
||
| 23 | 19 | if (!is_null($chunkSize)) { |
|
| 24 | 9 | $this->chunkSize = $chunkSize; |
|
| 25 | } |
||
| 26 | |||
| 27 | 19 | if (!isset($this->chunks)) { |
|
| 28 | 15 | $this->chunks = array_chunk($this->getOptions(), $this->chunkSize); |
|
| 29 | } |
||
| 30 | |||
| 31 | 19 | return $this->chunks; |
|
| 32 | } |
||
| 33 | |||
| 34 | /** |
||
| 35 | * @param int $index |
||
| 36 | * @return array |
||
| 37 | * @throws EddIriarte\Console\Inputs\Exceptions\IndexOutOfRange |
||
| 38 | */ |
||
| 39 | 2 | public function getChunkAt(int $index): array |
|
| 40 | { |
||
| 41 | 2 | if (!empty($this->getChunks()[$index])) { |
|
| 42 | 1 | return $this->getChunks()[$index]; |
|
| 43 | } |
||
| 44 | |||
| 45 | 1 | throw new IndexOutOfRange($index); |
|
| 46 | } |
||
| 47 | |||
| 48 | /** |
||
| 49 | * @return int |
||
| 50 | */ |
||
| 51 | 8 | public function getChunksCount(): int |
|
| 54 | } |
||
| 55 | |||
| 56 | /** |
||
| 57 | * @param int $rowIndex |
||
| 58 | * @param int $colIndex |
||
| 59 | * @return bool |
||
| 60 | */ |
||
| 61 | 12 | public function hasEntryAt(int $rowIndex, int $colIndex): bool |
|
| 65 | } |
||
| 66 | |||
| 67 | /** |
||
| 68 | * @param int $rowIndex |
||
| 69 | * @param int $colIndex |
||
| 70 | * @return string |
||
| 71 | * @throws EddIriarte\Console\Inputs\Exceptions\IndexOutOfRange |
||
| 72 | */ |
||
| 73 | 7 | public function getEntryAt(int $rowIndex, int $colIndex): string |
|
| 80 | } |
||
| 81 | } |
||
| 82 |