@@ 61-82 (lines=22) @@ | ||
58 | /** |
|
59 | * @return void |
|
60 | */ |
|
61 | private function validateNodes() |
|
62 | { |
|
63 | foreach ($this->nodes as $nodeIndex => $nodes) { |
|
64 | if (empty($nodes)) { |
|
65 | throw new InvalidArgumentException('A node should have at least a callable function'); |
|
66 | } |
|
67 | ||
68 | $callable = $nodes[0]; |
|
69 | if ( ! is_callable($callable)) { |
|
70 | throw new InvalidArgumentException('Node index = ' . $nodeIndex . '. Expected type callable as first array value, but got type ' . gettype($callable) . '.'); |
|
71 | } |
|
72 | } |
|
73 | ||
74 | $identifiers = array_keys($this->nodes); |
|
75 | foreach ($this->nodes as $nodeIndex => $nodes) { |
|
76 | $testedNodes = array_slice($nodes, 1); |
|
77 | $missingNodes = array_diff($testedNodes, $identifiers); |
|
78 | if ( ! empty($missingNodes)) { |
|
79 | throw new InvalidArgumentException('Node index = ' . $nodeIndex . '. Nodes [' . implode(', ', $missingNodes) . '] do not exist. Cannot create a graph to missing nodes.'); |
|
80 | } |
|
81 | } |
|
82 | } |
|
83 | ||
84 | /** |
|
85 | * @return void |
@@ 40-61 (lines=22) @@ | ||
37 | /** |
|
38 | * @return void |
|
39 | */ |
|
40 | private function validateNodes() |
|
41 | { |
|
42 | foreach ($this->nodes as $nodeIndex => $nodes) { |
|
43 | if (empty($nodes)) { |
|
44 | throw new InvalidArgumentException('A node should have at least a callable function'); |
|
45 | } |
|
46 | ||
47 | $callable = $nodes[0]; |
|
48 | if ( ! is_callable($callable)) { |
|
49 | throw new InvalidArgumentException('Node index = ' . $nodeIndex . '. Expected type callable as first array value, but got type ' . gettype($callable) . '.'); |
|
50 | } |
|
51 | } |
|
52 | ||
53 | $identifiers = array_keys($this->nodes); |
|
54 | foreach ($this->nodes as $nodeIndex => $nodes) { |
|
55 | $testedNodes = array_slice($nodes, 1); |
|
56 | $missingNodes = array_diff($testedNodes, $identifiers); |
|
57 | if ( ! empty($missingNodes)) { |
|
58 | throw new InvalidArgumentException('Node index = ' . $nodeIndex . '. Nodes [' . implode(', ', $missingNodes) . '] do not exist. Cannot create a graph to missing nodes.'); |
|
59 | } |
|
60 | } |
|
61 | } |
|
62 | ||
63 | /** |
|
64 | * @return void |