| Total Complexity | 10 |
| Total Lines | 59 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 2 | ||
| Bugs | 1 | Features | 0 |
| 1 | <?php |
||
| 8 | class Point implements PointInterface |
||
| 9 | { |
||
| 10 | private $dValues; |
||
| 11 | private $length; |
||
| 12 | |||
| 13 | /** |
||
| 14 | * Item constructor. |
||
| 15 | * @param array $dValues |
||
| 16 | */ |
||
| 17 | 102 | public function __construct(array $dValues) |
|
| 18 | { |
||
| 19 | 102 | $this->length = count($dValues); |
|
| 20 | 102 | $this->validateDValues($dValues); |
|
| 21 | |||
| 22 | 102 | $this->dValues = $dValues; |
|
| 23 | 102 | } |
|
| 24 | |||
| 25 | /** |
||
| 26 | * get nth dimension value from vector |
||
| 27 | * |
||
| 28 | * @api |
||
| 29 | * @param int $d |
||
| 30 | * @return float |
||
| 31 | */ |
||
| 32 | 102 | public function getNthDimension(int $d): float |
|
| 38 | } |
||
| 39 | |||
| 40 | |||
| 41 | /** |
||
| 42 | * validate multi dimension vector |
||
| 43 | * |
||
| 44 | * @param array $dValues |
||
| 45 | * @throws ValidationException |
||
| 46 | */ |
||
| 47 | 102 | private function validateDValues(array $dValues) |
|
| 48 | { |
||
| 49 | 102 | if ($this->length == 0) { |
|
| 50 | 3 | throw new ValidationException('$dValues should be not empty'); |
|
| 51 | } |
||
| 52 | |||
| 53 | 102 | for ($i = 0; $i < $this->length; $i++) { |
|
| 54 | 102 | if (!isset($dValues[$i]) || !is_numeric($dValues[$i])) { |
|
| 55 | 3 | throw new ValidationException('$dValues is not a simple array list'); |
|
| 56 | } |
||
| 57 | } |
||
| 58 | 102 | } |
|
| 59 | |||
| 60 | /** |
||
| 61 | * @api |
||
| 62 | * @return int number of dimensions in the point |
||
| 63 | */ |
||
| 64 | 105 | public function getDimensionsCount(): int |
|
| 67 | } |
||
| 68 | } |
||
| 69 |