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

Relation   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 0
cbo 3
dl 0
loc 23
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 2
A setDistance() 0 8 3
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