Point::addPoint()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 12
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 5
c 1
b 0
f 0
nc 4
nop 1
dl 0
loc 12
ccs 6
cts 6
cp 1
crap 3
rs 10
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 12
    public function __construct(int $x, int $y)
13
    {
14 12
        $this->x = $x;
15 12
        $this->y = $y;
16 12
        $this->points = [];
17 12
        $this->ref = "{$x}-{$y}";
18 12
    }
19
20 6
    public function addPoint(self $point): self
21
    {
22 6
        if (! in_array($point, $this->points)) {
23 6
            $this->points[] = $point;
24
        }
25
26
        // add the reverse point
27 6
        if (! in_array($this, $point->points)) {
28 6
            $point->points[] = $this;
29
        }
30
31 6
        return $this;
32
    }
33
34 8
    public function equals(self $point): bool
35
    {
36 8
        return $this->ref === $point->ref;
37
    }
38
}
39