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

Connection   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 9
c 1
b 0
f 0
lcom 0
cbo 1
dl 0
loc 43
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 16 4
A isPoint() 0 4 2
A getFrom() 0 4 1
A getTo() 0 4 1
A getDistance() 0 4 1
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