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

Space   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 10
c 0
b 0
f 0
dl 0
loc 35
rs 10
wmc 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A makePoint() 0 3 1
A isEqualTo() 0 4 2
A __construct() 0 9 2
A getDimensions() 0 3 1
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