1 | <?php |
||
28 | class Edge implements AttributesAwareInterface |
||
29 | { |
||
30 | use AttributesAware; |
||
31 | |||
32 | /** @var Node Node from where to link */ |
||
33 | private $from; |
||
34 | |||
35 | /** @var Node Node where to to link */ |
||
36 | private $to; |
||
37 | |||
38 | /** @var int The direction */ |
||
39 | private $directed; |
||
40 | |||
41 | /** |
||
42 | * Creates a new Edge / Link between the given nodes. |
||
43 | 1 | * |
|
44 | * @param Node $from Starting node to create an Edge from. |
||
45 | 1 | * @param Node $to Destination node where to create and |
|
46 | 1 | * edge to. |
|
47 | 1 | * @param int $direction |
|
48 | * 0 means undirected, greater than 0 means from FROM to TO, smaller than 0 |
||
49 | * means from TO to FROM. |
||
50 | */ |
||
51 | public function __construct(Node $from, Node $to, int $direction = 1) |
||
65 | |||
66 | 1 | /** |
|
67 | * @return bool |
||
68 | 1 | */ |
|
69 | public function isDirected(): bool |
||
73 | |||
74 | 1 | /** |
|
75 | * Factory method used to assist with fluent interface handling. |
||
76 | 1 | * |
|
77 | * See the examples for more details. |
||
78 | * |
||
79 | * @param Node $from Starting node to create an Edge from. |
||
80 | * @param Node $to Destination node where to create and |
||
81 | * edge to. |
||
82 | * @param int $direction |
||
83 | * 0 means undirected, greater than 0 means from FROM to TO, smaller than 0 |
||
84 | * means from TO to FROM. |
||
85 | * |
||
86 | * @return \phpDocumentor\GraphViz\Edge |
||
87 | */ |
||
88 | public static function create(Node $from, Node $to, int $direction = 1) : self |
||
92 | |||
93 | /** |
||
94 | * @param \phpDocumentor\GraphViz\Node $from |
||
95 | * @param \phpDocumentor\GraphViz\Node $to |
||
96 | * |
||
97 | 1 | * @return \phpDocumentor\GraphViz\Edge |
|
98 | */ |
||
99 | 1 | public static function directed(Node $from, Node $to) : self |
|
103 | |||
104 | 1 | /** |
|
105 | 1 | * @param \phpDocumentor\GraphViz\Node $from |
|
106 | * @param \phpDocumentor\GraphViz\Node $to |
||
107 | * |
||
108 | 1 | * @return \phpDocumentor\GraphViz\Edge |
|
109 | */ |
||
110 | public static function undirected(Node $from, Node $to) : self |
||
114 | 1 | ||
115 | /** |
||
116 | 1 | * Returns the source Node for this Edge. |
|
117 | 1 | */ |
|
118 | 1 | public function getFrom() : Node |
|
122 | |||
123 | 1 | /** |
|
124 | 1 | * Returns the destination Node for this Edge. |
|
125 | */ |
||
126 | public function getTo() : Node |
||
130 | |||
131 | /** |
||
132 | * Magic method to provide a getter/setter to add attributes on the edge. |
||
133 | * |
||
134 | * Using this method we make sure that we support any attribute without too |
||
135 | * much hassle. If the name for this method does not start with get or set |
||
136 | * we return null. |
||
137 | * |
||
138 | * Set methods return this graph (fluent interface) whilst get methods |
||
139 | * return the attribute value. |
||
140 | * |
||
141 | * @param string $name name of the invoked method, expect it to be |
||
142 | * setX or getX. |
||
143 | * @param mixed[] $arguments Arguments for the setter, only 1 is expected: value |
||
144 | * |
||
145 | * @return Attribute|Edge|null |
||
146 | * |
||
147 | * @throws AttributeNotFound |
||
148 | */ |
||
149 | public function __call(string $name, array $arguments) |
||
163 | |||
164 | /** |
||
165 | * Returns the edge definition as is requested by GraphViz. |
||
166 | */ |
||
167 | public function __toString() : string |
||
189 | } |
||
190 |
This check looks for assignments to scalar types that may be of the wrong type.
To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.