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

Line1D::countWidth()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace PHPAlgorithms\GraphTools;
4
5
use PHPAlgorithms\GraphTools\Interfaces\LineInterface;
6
use PHPAlgorithms\GraphTools\Exceptions\LineException;
7
8
class Line1D extends AbstractLine implements LineInterface {
9
    protected $width;
10
11
    protected function checkPoint($point)
12
    {
13
        if (!($point instanceof Point1D)) {
14
            throw new LineException('This is not a point');
15
        }
16
    }
17
18
    protected function countWidth()
19
    {
20
        return abs($this->from->x - $this->to->x);
21
    }
22
23
    public function __construct($from, $to)
24
    {
25
        parent::__construct($from, $to);
26
27
        $this->width = $this->countWidth();
28
    }
29
}
30