Passed
Pull Request — master (#34)
by Benjamin
26:50 queued 11:50
created

Space::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
c 0
b 0
f 0
nc 2
nop 1
dl 0
loc 9
rs 10
1
<?php
2
3
namespace Kmeans\Euclidean;
4
5
use Kmeans\Interfaces\PointInterface;
6
use Kmeans\Interfaces\SpaceInterface;
7
8
class Space implements SpaceInterface
9
{
10
    /**
11
     * @var int<1, max>
12
     */
13
    protected int $dimensions;
14
15
    public function __construct(int $dimensions)
16
    {
17
        if ($dimensions < 1) {
18
            throw new \InvalidArgumentException(
19
                "Invalid space dimentions: {$dimensions}"
20
            );
21
        }
22
23
        $this->dimensions = $dimensions;
24
    }
25
26
    public function getDimensions(): int
27
    {
28
        return $this->dimensions;
29
    }
30
31
    public function isEqualTo(SpaceInterface $space): bool
32
    {
33
        return $space instanceof self
34
            && $this->dimensions == $space->dimensions;
35
    }
36
37
    /**
38
     * @param array<float> $coordinates
39
     */
40
    public function makePoint(array $coordinates): PointInterface
41
    {
42
        return new Point($this, $coordinates);
43
    }
44
}
45