Passed
Branch develop (12c5b1)
by Benjamin
05:18
created

Point   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 15
dl 0
loc 32
rs 10
c 0
b 0
f 0
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A addPoint() 0 12 3
A equals() 0 3 1
1
<?php
2
3
namespace Bmichotte\Dijkstra;
4
5
class Point
6
{
7
    public $x;
8
    public $y;
9
    public $points;
10
    public $ref;
11
12
    public function __construct($x, $y)
13
    {
14
        $this->x = $x;
15
        $this->y = $y;
16
        $this->points = [];
17
        $this->ref = "{$x}-{$y}";
18
    }
19
20
    public function addPoint(Point $point): Point
21
    {
22
        if (! in_array($point, $this->points)) {
23
            $this->points[] = $point;
24
        }
25
26
        // add the reverse point
27
        if (! in_array($this, $point->points)) {
28
            $point->points[] = $this;
29
        }
30
31
        return $this;
32
    }
33
34
    public function equals(Point $point): bool
35
    {
36
        return $this->ref === $point->ref;
37
    }
38
}
39