Edge   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 18
c 1
b 0
f 0
dl 0
loc 52
rs 10
wmc 7

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setFromPort() 0 3 1
A create() 0 2 1
A __toString() 0 16 4
A setToPort() 0 3 1
1
<?php
2
3
namespace BeyondCode\ErdGenerator;
4
5
use phpDocumentor\GraphViz\Node;
6
7
/**
8
 * Class Edge
9
 * @package BeyondCode\ErdGenerator
10
 * @method void setLabel(string $name)
11
 * @method void setXLabel(string $name)
12
 *
13
 */
14
class Edge extends \phpDocumentor\GraphViz\Edge
15
{
16
    protected $fromPort = null;
17
18
    protected $toPort = null;
19
20
    /**
21
     * @param Node $from
22
     * @param Node $to
23
     * @return Edge|\phpDocumentor\GraphViz\Edge
24
     */
25
    public static function create(Node $from, Node $to) {
26
        return new static($from, $to);
27
    }
28
29
    /**
30
     * @param null $fromPort
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $fromPort is correct as it would always require null to be passed?
Loading history...
31
     */
32
    public function setFromPort($fromPort): void
33
    {
34
        $this->fromPort = $fromPort;
35
    }
36
37
    /**
38
     * @param null $toPort
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $toPort is correct as it would always require null to be passed?
Loading history...
39
     */
40
    public function setToPort($toPort): void
41
    {
42
        $this->toPort = $toPort;
43
    }
44
45
    /**
46
     * Returns the edge definition as is requested by GraphViz.
47
     *
48
     * @return string
49
     */
50
    public function __toString()
51
    {
52
        $attributes = array();
53
        foreach ($this->attributes as $value) {
54
            $attributes[] = (string)$value;
55
        }
56
        $attributes = implode("\n", $attributes);
57
58
        $from_name = addslashes($this->getFrom()->getName());
59
        $to_name = addslashes($this->getTo()->getName());
60
        $from_name .= (!empty($this->fromPort)) ? ':' . $this->fromPort : '';
61
        $to_name .= (!empty($this->toPort)) ? ':' . $this->toPort : '';
62
63
        return <<<DOT
64
$from_name -> $to_name [
65
$attributes
66
]
67
DOT;
68
    }
69
}