Completed
Push — master ( d791dd...2d8ee5 )
by Ventaquil
02:14
created

AbstractLine::checkPoint()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
rs 9.4285
cc 2
eloc 3
nc 2
nop 1
1
<?php
2
3
namespace PHPAlgorithms\GraphTools;
4
5
use PHPAlgorithms\GraphTools\Interfaces\LineInterface;
6
use PHPAlgorithms\GraphTools\Exceptions\LineException;
7
use PHPAlgorithms\GraphTools\Traits\MagicGet;
8
use PHPAlgorithms\GraphTools\Traits\toArray;
9
10
class AbstractLine implements LineInterface {
11
    use MagicGet, toArray;
12
13
    protected $from, $to;
0 ignored issues
show
Coding Style introduced by
It is generally advisable to only define one property per statement.

Only declaring a single property per statement allows you to later on add doc comments more easily.

It is also recommended by PSR2, so it is a common style that many people expect.

Loading history...
14
15
    protected function checkPoints($from, $to)
16
    {
17
        if ($from->equals($to)) {
18
            throw new LineException('You can not build the line from the same point');
19
        }
20
    }
21
22
    protected function checkPoint($point)
23
    {
24
        if (!($point instanceof AbstractPoint)) {
25
            throw new LineException('This is not a point');
26
        }
27
    }
28
29
    protected function setFrom($from)
30
    {
31
        $this->checkPoint($from);
32
        $this->from = $from;
33
    }
34
35
    protected function setTo($to)
36
    {
37
        $this->checkPoint($to);
38
        $this->to = $to;
39
    }
40
41
    public function __construct($from, $to)
42
    {
43
        $this->setFrom($from);
44
45
        $this->setTo($to);
46
47
        $this->checkPoints($from, $to);
48
    }
49
}
50