Edgeable::addEdgeFrom()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 2
Metric Value
cc 2
eloc 3
c 2
b 0
f 2
nc 2
nop 2
dl 0
loc 7
rs 10
1
<?php
2
3
/*
4
 * This file is part of the doctrineviz package
5
 *
6
 * Copyright (c) 2017 Pierre Hennequart
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 *
11
 * Feel free to edit as you please, and have fun.
12
 *
13
 * @author Pierre Hennequart <[email protected]>
14
 */
15
16
declare(strict_types=1);
17
18
namespace Janalis\Doctrineviz\Graphviz;
19
20
trait Edgeable
21
{
22
    /** @var GraphInterface */
23
    protected $graph;
24
25
    /**
26
     * Get graph.
27
     *
28
     * @return GraphInterface
29
     */
30
    public function getGraph(): ?GraphInterface
31
    {
32
        return $this->graph;
33
    }
34
35
    /**
36
     * Set graph.
37
     *
38
     * @param GraphInterface|null $graph
39
     */
40
    public function setGraph(GraphInterface $graph = null): void
41
    {
42
        $this->graph = $graph;
43
    }
44
45
    /**
46
     * Add edge to.
47
     *
48
     * @param ElementInterface $element
49
     * @param null|string      $label
50
     *
51
     * @return EdgeInterface
52
     *
53
     * @throws \RuntimeException
54
     */
55
    public function addEdgeTo(ElementInterface $element, string $label = null): EdgeInterface
56
    {
57
        if (!$this->graph) {
58
            throw new \RuntimeException('Graph is not defined');
59
        }
60
61
        return $this->graph->addEdge(new Edge($this, $element, $label));
0 ignored issues
show
Bug introduced by
$this of type Janalis\Doctrineviz\Graphviz\Edgeable is incompatible with the type Janalis\Doctrineviz\Graphviz\ElementInterface|null expected by parameter $from of Janalis\Doctrineviz\Graphviz\Edge::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

61
        return $this->graph->addEdge(new Edge(/** @scrutinizer ignore-type */ $this, $element, $label));
Loading history...
62
    }
63
64
    /**
65
     * Remove edge to.
66
     *
67
     * @param ElementInterface $element
68
     * @param null|string      $label
69
     *
70
     * @throws \RuntimeException
71
     */
72
    public function removeEdgeTo(ElementInterface $element, string $label = null): void
73
    {
74
        if (!$this->graph) {
75
            throw new \RuntimeException('Graph is not defined');
76
        }
77
        $this->graph->removeEdge(new Edge($this, $element, $label));
0 ignored issues
show
Bug introduced by
$this of type Janalis\Doctrineviz\Graphviz\Edgeable is incompatible with the type Janalis\Doctrineviz\Graphviz\ElementInterface|null expected by parameter $from of Janalis\Doctrineviz\Graphviz\Edge::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

77
        $this->graph->removeEdge(new Edge(/** @scrutinizer ignore-type */ $this, $element, $label));
Loading history...
78
    }
79
80
    /**
81
     * Add edge from.
82
     *
83
     * @param ElementInterface $element
84
     * @param null|string      $label
85
     *
86
     * @return EdgeInterface
87
     *
88
     * @throws \RuntimeException
89
     */
90
    public function addEdgeFrom(ElementInterface $element, string $label = null): EdgeInterface
91
    {
92
        if (!$this->graph) {
93
            throw new \RuntimeException('Graph is not defined');
94
        }
95
96
        return $this->graph->addEdge(new Edge($element, $this, $label));
0 ignored issues
show
Bug introduced by
$this of type Janalis\Doctrineviz\Graphviz\Edgeable is incompatible with the type Janalis\Doctrineviz\Graphviz\ElementInterface|null expected by parameter $to of Janalis\Doctrineviz\Graphviz\Edge::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

96
        return $this->graph->addEdge(new Edge($element, /** @scrutinizer ignore-type */ $this, $label));
Loading history...
97
    }
98
99
    /**
100
     * Remove edge from.
101
     *
102
     * @param ElementInterface $element
103
     * @param null|string      $label
104
     *
105
     * @throws \RuntimeException
106
     */
107
    public function removeEdgeFrom(ElementInterface $element, string $label = null): void
108
    {
109
        if (!$this->graph) {
110
            throw new \RuntimeException('Graph is not defined');
111
        }
112
        $this->graph->removeEdge(new Edge($element, $this, $label));
0 ignored issues
show
Bug introduced by
$this of type Janalis\Doctrineviz\Graphviz\Edgeable is incompatible with the type Janalis\Doctrineviz\Graphviz\ElementInterface|null expected by parameter $to of Janalis\Doctrineviz\Graphviz\Edge::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

112
        $this->graph->removeEdge(new Edge($element, /** @scrutinizer ignore-type */ $this, $label));
Loading history...
113
    }
114
}
115