Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
7 / 7 |
|
100.00% |
5 / 5 |
CRAP | |
100.00% |
1 / 1 |
| Column | |
100.00% |
7 / 7 |
|
100.00% |
5 / 5 |
7 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
| getKey | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getData | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getDataByIndex | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
2 | |||
| hasDataIndex | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | #declare(strict_types=1); |
| 4 | |
| 5 | /** |
| 6 | * CNIC\HEXONET |
| 7 | * Copyright © CentralNic Group PLC |
| 8 | */ |
| 9 | |
| 10 | namespace CNIC\HEXONET; |
| 11 | |
| 12 | /** |
| 13 | * HEXONET Column |
| 14 | * |
| 15 | * @package CNIC\HEXONET |
| 16 | */ |
| 17 | |
| 18 | class Column // implements \CNIC\ColumnInterface |
| 19 | { |
| 20 | /** |
| 21 | * count of column data entries |
| 22 | * @var int |
| 23 | */ |
| 24 | public $length; |
| 25 | |
| 26 | /** |
| 27 | * column key name |
| 28 | * @var string |
| 29 | */ |
| 30 | private $key; |
| 31 | /** |
| 32 | * column data container |
| 33 | * @var string[] |
| 34 | */ |
| 35 | private $data; |
| 36 | |
| 37 | /** |
| 38 | * Constructor |
| 39 | * |
| 40 | * @param string $key Column Name |
| 41 | * @param string[] $data Column Data |
| 42 | */ |
| 43 | public function __construct($key, $data) |
| 44 | { |
| 45 | $this->key = $key; |
| 46 | $this->data = $data; |
| 47 | $this->length = count($data); |
| 48 | } |
| 49 | |
| 50 | /** |
| 51 | * Get column name |
| 52 | * @return string column name |
| 53 | */ |
| 54 | public function getKey() |
| 55 | { |
| 56 | return $this->key; |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * Get column data |
| 61 | * @return string[] column data |
| 62 | */ |
| 63 | public function getData() |
| 64 | { |
| 65 | return $this->data; |
| 66 | } |
| 67 | |
| 68 | /** |
| 69 | * Get column data at given index |
| 70 | * @param integer $idx data index |
| 71 | * @return string|null data at given index |
| 72 | */ |
| 73 | public function getDataByIndex($idx) |
| 74 | { |
| 75 | return $this->hasDataIndex($idx) ? $this->data[$idx] : null; |
| 76 | } |
| 77 | |
| 78 | /** |
| 79 | * Check if column has a given data index |
| 80 | * @param integer $idx data index |
| 81 | * @return bool result |
| 82 | */ |
| 83 | private function hasDataIndex($idx) |
| 84 | { |
| 85 | return ($idx >= 0 && $idx < $this->length); |
| 86 | } |
| 87 | } |