Completed
Push — master ( 195fbe...724c19 )
by Ventaquil
02:47
created

Relation::setDistance()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 8
rs 9.4285
cc 3
eloc 4
nc 2
nop 1
1
<?php
2
3
namespace PHPAlgorithms\Dijkstra;
4
5
use PHPAlgorithms\Dijkstra\Exceptions\RelationException;
6
use PHPAlgorithms\GraphTools\AbstractLine;
7
use PHPAlgorithms\GraphTools\Traits\MagicGet;
8
9
class Relation extends AbstractLine {
10
    use MagicGet;
11
12
    private $distance;
13
14
    public function __construct($from, $to, $distance = null)
15
    {
16
        parent::__construct($from, $to);
17
18
        if (!is_null($distance)) {
19
            $this->setDistance($distance);
20
        }
21
    }
22
23
    public function setDistance($distance)
24
    {
25
        if (!is_numeric($distance) && ($distance <= 0)) {
26
            throw new RelationException('Distance must be numeric value greater than 0');
27
        }
28
29
        $this->distance = $distance;
30
    }
31
}
32