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

Point::addPoint()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 12
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 5
nc 4
nop 1
dl 0
loc 12
rs 10
c 0
b 0
f 0
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