Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
6 / 6 |
|
100.00% |
4 / 4 |
CRAP | |
100.00% |
1 / 1 |
| Record | |
100.00% |
6 / 6 |
|
100.00% |
4 / 4 |
5 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getData | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getDataByKey | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |||
| hasData | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 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 Record |
| 14 | * |
| 15 | * @package CNIC\HEXONET |
| 16 | */ |
| 17 | |
| 18 | class Record // implements \CNIC\RecordInterface |
| 19 | { |
| 20 | /** |
| 21 | * row data container |
| 22 | * e.g. |
| 23 | * <code> |
| 24 | * $data = [ |
| 25 | * "DOMAIN" => "mydomain.com", |
| 26 | * "USER" => "test.user", |
| 27 | * // ... further column data ... |
| 28 | * ]; |
| 29 | * </code> |
| 30 | * @var array |
| 31 | */ |
| 32 | private $data; |
| 33 | |
| 34 | /** |
| 35 | * Constructor |
| 36 | * e.g. |
| 37 | * <code> |
| 38 | * $data = [ |
| 39 | * "DOMAIN" => "mydomain.com", |
| 40 | * "USER" => "test.user", |
| 41 | * // ... further column data ... |
| 42 | * ]; |
| 43 | * </code> |
| 44 | * @param array $data data object |
| 45 | */ |
| 46 | public function __construct($data) |
| 47 | { |
| 48 | $this->data = $data; |
| 49 | } |
| 50 | |
| 51 | /** |
| 52 | * get row data |
| 53 | * @return array row data |
| 54 | */ |
| 55 | public function getData() |
| 56 | { |
| 57 | return $this->data; |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * get row data for given column |
| 62 | * @param string $key column name |
| 63 | * @return string|null row data for given column or null if column does not exist |
| 64 | */ |
| 65 | public function getDataByKey($key) |
| 66 | { |
| 67 | if ($this->hasData($key)) { |
| 68 | return $this->data[$key]; |
| 69 | } |
| 70 | return null; |
| 71 | } |
| 72 | |
| 73 | /** |
| 74 | * check if record has data for given column |
| 75 | * @param string $key column name |
| 76 | * @return bool boolean result |
| 77 | */ |
| 78 | private function hasData($key) |
| 79 | { |
| 80 | return array_key_exists($key, $this->data); |
| 81 | } |
| 82 | } |