@@ -90,19 +90,19 @@ |
||
90 | 90 | */ |
91 | 91 | public function isSuitableVertex(VertexInterface $vertex): bool |
92 | 92 | { |
93 | - if($this->vertexTypesOnly !== null && !in_array($vertex->getType(), $this->vertexTypesOnly)) { |
|
93 | + if ($this->vertexTypesOnly !== null && !in_array($vertex->getType(), $this->vertexTypesOnly)) { |
|
94 | 94 | return false; |
95 | 95 | } |
96 | 96 | |
97 | - if($this->vertexIdsOnly !== null && !in_array($vertex->getId(), $this->vertexIdsOnly)) { |
|
97 | + if ($this->vertexIdsOnly !== null && !in_array($vertex->getId(), $this->vertexIdsOnly)) { |
|
98 | 98 | return false; |
99 | 99 | } |
100 | 100 | |
101 | - if(in_array($vertex->getType(), $this->vertexTypesExclude)) { |
|
101 | + if (in_array($vertex->getType(), $this->vertexTypesExclude)) { |
|
102 | 102 | return false; |
103 | 103 | } |
104 | 104 | |
105 | - if(in_array($vertex->getId(), $this->vertexIdsExclude)) { |
|
105 | + if (in_array($vertex->getId(), $this->vertexIdsExclude)) { |
|
106 | 106 | return false; |
107 | 107 | } |
108 | 108 |
@@ -27,8 +27,8 @@ |
||
27 | 27 | public static function combine(TraverseStepIteratorInterface ...$iterators): TraverseStepIteratorInterface |
28 | 28 | { |
29 | 29 | $source = []; |
30 | - foreach($iterators as $iterator) { |
|
31 | - foreach($iterator as $edge => $vertex) { |
|
30 | + foreach ($iterators as $iterator) { |
|
31 | + foreach ($iterator as $edge => $vertex) { |
|
32 | 32 | $source[] = new TraverseStepItem($edge, $vertex); |
33 | 33 | } |
34 | 34 | } |
@@ -21,8 +21,8 @@ discard block |
||
21 | 21 | public static function getBranches(Generator $contexts, ?callable $callback = null): array |
22 | 22 | { |
23 | 23 | $branchMap = []; |
24 | - foreach($contexts as $context) { |
|
25 | - if(is_callable($callback)) { |
|
24 | + foreach ($contexts as $context) { |
|
25 | + if (is_callable($callback)) { |
|
26 | 26 | $callback($context, $contexts); |
27 | 27 | } |
28 | 28 | |
@@ -31,8 +31,8 @@ discard block |
||
31 | 31 | $parentBranchIndex = $context->getBranchContext()->getParentIndex(); |
32 | 32 | $vertex = $context->getVertex(); |
33 | 33 | |
34 | - if(!isset($branchMap[$branchIndex])) { |
|
35 | - if(isset($branchMap[$parentBranchIndex])) { |
|
34 | + if (!isset($branchMap[$branchIndex])) { |
|
35 | + if (isset($branchMap[$parentBranchIndex])) { |
|
36 | 36 | $parentBranch = $branchMap[$parentBranchIndex]; |
37 | 37 | $key = array_search($branchContext->getStart(), $parentBranch); |
38 | 38 | $branchMap[$branchIndex] = array_slice($parentBranch, 0, $key+1); |
@@ -54,11 +54,11 @@ |
||
54 | 54 | */ |
55 | 55 | public function isSuitableEdge(EdgeInterface $edge): bool |
56 | 56 | { |
57 | - if($this->edgeTypesOnly !== null && !in_array($edge->getType(), $this->edgeTypesOnly)) { |
|
57 | + if ($this->edgeTypesOnly !== null && !in_array($edge->getType(), $this->edgeTypesOnly)) { |
|
58 | 58 | return false; |
59 | 59 | } |
60 | 60 | |
61 | - if(in_array($edge->getType(), $this->edgeTypesExclude)) { |
|
61 | + if (in_array($edge->getType(), $this->edgeTypesExclude)) { |
|
62 | 62 | return false; |
63 | 63 | } |
64 | 64 |
@@ -31,9 +31,9 @@ discard block |
||
31 | 31 | { |
32 | 32 | $passCondition = $this->getDefaultPassCondition($context); |
33 | 33 | |
34 | - if($this->needToPreventLoopPass($context)) { |
|
34 | + if ($this->needToPreventLoopPass($context)) { |
|
35 | 35 | $passCondition = (clone $passCondition)->onlyVertexTypes([]); |
36 | - } elseif($this->needToCheckReturnBackPass() && ($prevVertex = $context->getPrevVertex()) !== null) { |
|
36 | + } elseif ($this->needToCheckReturnBackPass() && ($prevVertex = $context->getPrevVertex()) !== null) { |
|
37 | 37 | $passCondition = (clone $passCondition)->excludeVertexIds([$prevVertex->getId()]); |
38 | 38 | } |
39 | 39 | |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | { |
49 | 49 | $handleCondition = $this->getDefaultHandleCondition($context); |
50 | 50 | |
51 | - if($this->needToPreventLoopHandle($context) || $this->needToPreventRepeatHandle($context)) { |
|
51 | + if ($this->needToPreventLoopHandle($context) || $this->needToPreventRepeatHandle($context)) { |
|
52 | 52 | $handleCondition = (clone $handleCondition)->onlyVertexTypes([]); |
53 | 53 | } |
54 | 54 |
@@ -88,24 +88,24 @@ discard block |
||
88 | 88 | $globalPassedVertexesMap = $startContext->getGlobalPassedVertexesMap(); |
89 | 89 | $contexts = $this->createContextCollection($traverseMode, $startContext); |
90 | 90 | |
91 | - while(count($contexts)) { |
|
91 | + while (count($contexts)) { |
|
92 | 92 | /** @var TraverseContextInterface $currentContext */ |
93 | 93 | $currentContext = $contexts->pop(); |
94 | 94 | $currentVertex = $currentContext->getVertex(); |
95 | 95 | |
96 | 96 | $customPassCondition = null; |
97 | 97 | $nextVertex = null; |
98 | - if($filter->matchesHandleCondition($currentContext)) { |
|
98 | + if ($filter->matchesHandleCondition($currentContext)) { |
|
99 | 99 | $cmd = (yield $currentContext); |
100 | 100 | |
101 | - if($cmd instanceof FilterConditionInterface) { |
|
101 | + if ($cmd instanceof FilterConditionInterface) { |
|
102 | 102 | $customPassCondition = $cmd; |
103 | 103 | yield $currentContext; |
104 | - } elseif($cmd instanceof VertexInterface) { |
|
104 | + } elseif ($cmd instanceof VertexInterface) { |
|
105 | 105 | $nextVertex = $cmd; |
106 | 106 | yield $currentContext; |
107 | 107 | } else { |
108 | - switch($cmd) { |
|
108 | + switch ($cmd) { |
|
109 | 109 | case static::STOP_BRANCH: |
110 | 110 | yield $currentContext; |
111 | 111 | continue 2; |
@@ -127,9 +127,9 @@ discard block |
||
127 | 127 | } |
128 | 128 | |
129 | 129 | $i = 0; |
130 | - foreach($nextVertexes as $edge => $vertex) { |
|
130 | + foreach ($nextVertexes as $edge => $vertex) { |
|
131 | 131 | $currentBranchContext = $currentContext->getBranchContext(); |
132 | - if(count($nextVertexes) > 1 && $i > 0) { |
|
132 | + if (count($nextVertexes) > 1 && $i > 0) { |
|
133 | 133 | $nextBranchContext = $this->createBranchContext( |
134 | 134 | ++$lastBranchIndex, |
135 | 135 | $currentBranchContext->getIndex(), |
@@ -178,7 +178,7 @@ discard block |
||
178 | 178 | int $traverseMode, |
179 | 179 | TraverseContextInterface $startContext |
180 | 180 | ): Collection { |
181 | - if($traverseMode === self::MODE_WIDE) { |
|
181 | + if ($traverseMode === self::MODE_WIDE) { |
|
182 | 182 | $contexts = new Queue([$startContext]); |
183 | 183 | } else { |
184 | 184 | $contexts = new Stack([$startContext]); |
@@ -43,11 +43,11 @@ discard block |
||
43 | 43 | array $vertexes, |
44 | 44 | array $edges |
45 | 45 | ) { |
46 | - foreach($vertexes as $vertex) { |
|
46 | + foreach ($vertexes as $vertex) { |
|
47 | 47 | $this->vertexMap[$vertex->getId()] = $vertex; |
48 | 48 | } |
49 | 49 | |
50 | - foreach($edges as $edge) { |
|
50 | + foreach ($edges as $edge) { |
|
51 | 51 | $this->edgesMap[$edge->getId()] = $edge; |
52 | 52 | |
53 | 53 | $this->setToMap( |
@@ -70,7 +70,7 @@ discard block |
||
70 | 70 | */ |
71 | 71 | public function getVertexById(string $id): VertexInterface |
72 | 72 | { |
73 | - if(!isset($this->vertexMap[$id])) { |
|
73 | + if (!isset($this->vertexMap[$id])) { |
|
74 | 74 | throw new RepositoryException( |
75 | 75 | "vertex with id '{$id}' not exist", |
76 | 76 | RepositoryException::VERTEX_NOT_FOUND |
@@ -85,7 +85,7 @@ discard block |
||
85 | 85 | */ |
86 | 86 | public function getEdgeById(string $id): EdgeInterface |
87 | 87 | { |
88 | - if(!isset($this->edgesMap[$id])) { |
|
88 | + if (!isset($this->edgesMap[$id])) { |
|
89 | 89 | throw new RepositoryException( |
90 | 90 | "edge with id '{$id}' not exist", |
91 | 91 | RepositoryException::EDGE_NOT_FOUND |
@@ -138,11 +138,11 @@ discard block |
||
138 | 138 | ?FilterConditionInterface $condition |
139 | 139 | ): TraverseStepIteratorInterface { |
140 | 140 | $result = []; |
141 | - foreach($source[$vertex->getId()] ?? [] as $edgeId => [$edgeType, $targetId]) { |
|
141 | + foreach ($source[$vertex->getId()] ?? [] as $edgeId => [$edgeType, $targetId]) { |
|
142 | 142 | $edge = $this->getEdgeById($edgeId); |
143 | - if($this->isSuitableEdge($edge, $condition)) { |
|
143 | + if ($this->isSuitableEdge($edge, $condition)) { |
|
144 | 144 | $target = $this->getVertexById($targetId); |
145 | - if($this->isSuitableVertex($target, $condition)) { |
|
145 | + if ($this->isSuitableVertex($target, $condition)) { |
|
146 | 146 | $result[] = new TraverseStepItem($edge, $target); |
147 | 147 | } |
148 | 148 | } |