Completed
Push — master ( 1fabfb...84d6ef )
by Ventaquil
02:11
created

Connection::getFrom()   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
namespace Algorithms\GraphTools;
3
4
class Connection
5
{
6
    private $from;
7
    private $to;
8
    private $distance;
9
10
    public function __construct($from, $to, $distance)
11
    {
12
        if (self::isPoint($from) && self::isPoint($to)) {
13
            $this->from = $from;
14
            $this->to = $to;
15
        } else {
16
            throw new ConnectionException('Sent data are not points');
17
        }
18
19
        $distance = intval($distance);
20
        if ($distance > 0) {
21
            $this->distance = $distance;
22
        } else {
23
            throw new ConnectionException('Distance is less than or equal to zero');
24
        }
25
    }
26
27
    private static function isPoint($element)
28
    {
29
        return ($element instanceof Point) || (filter_var($element, FILTER_VALIDATE_INT) !== false);
30
    }
31
32
    public function getFrom()
33
    {
34
        return $this->from;
35
    }
36
37
    public function getTo()
38
    {
39
        return $this->to;
40
    }
41
42
    public function getDistance()
43
    {
44
        return $this->distance;
45
    }
46
}
47