Skip to content

Commit 045936a

Browse files
committed
Fix CS.
1 parent 4edfd8f commit 045936a

File tree

3 files changed

+15
-46
lines changed

3 files changed

+15
-46
lines changed

src/Builder/BuilderInterface.php

+1-4
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,10 @@
66

77
use loophp\phptree\Node\NodeInterface;
88

9-
/**
10-
* Interface BuilderInterface.
11-
*/
129
interface BuilderInterface
1310
{
1411
/**
15-
* @param iterable<mixed> $nodes
12+
* @param iterable<int, array<int, class-string|callable():(NodeInterface)|mixed>> $nodes
1613
*/
1714
public static function create(iterable $nodes): ?NodeInterface;
1815
}

src/Builder/Random.php

+6-7
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,8 @@
88

99
use function is_callable;
1010

11-
/**
12-
* Class Random.
13-
*/
1411
class Random implements BuilderInterface
1512
{
16-
/**
17-
* {@inheritdoc}
18-
*/
1913
public static function create(iterable $nodes): ?NodeInterface
2014
{
2115
$root = null;
@@ -38,11 +32,16 @@ public static function create(iterable $nodes): ?NodeInterface
3832
}
3933

4034
/**
41-
* @param array<mixed> $parameters
35+
* @param array<int, class-string|callable():(NodeInterface)|mixed> $parameters
4236
*/
4337
private static function createNode(array $parameters = []): NodeInterface
4438
{
4539
$parameters = array_map(
40+
/**
41+
* @param class-string|callable():(NodeInterface)|mixed $parameter
42+
*
43+
* @return class-string|mixed
44+
*/
4645
static function ($parameter) {
4746
if (is_callable($parameter)) {
4847
return $parameter();

src/Exporter/Graph.php

+8-35
Original file line numberDiff line numberDiff line change
@@ -9,35 +9,22 @@
99
use loophp\phptree\Node\AttributeNodeInterface;
1010
use loophp\phptree\Node\NodeInterface;
1111

12-
/**
13-
* Class Graph.
14-
*/
1512
final class Graph implements ExporterInterface
1613
{
17-
/**
18-
* The graph.
19-
*
20-
* @var \Fhaculty\Graph\Graph
21-
*/
22-
private $graph;
23-
24-
/**
25-
* {@inheritdoc}
26-
*/
2714
public function export(NodeInterface $node): OriginalGraph
2815
{
29-
$this->graph = new OriginalGraph();
16+
$graph = new OriginalGraph();
3017

3118
foreach ($node->all() as $node_visited) {
32-
$vertexFrom = $this->createVertex($node_visited);
19+
$vertexFrom = $this->createVertex($node_visited, $graph);
3320

3421
foreach ($node_visited->children() as $child) {
35-
$vertexTo = $this->createVertex($child);
22+
$vertexTo = $this->createVertex($child, $graph);
3623
$vertexFrom->createEdgeTo($vertexTo);
3724
}
3825
}
3926

40-
return $this->getGraph();
27+
return $graph;
4128
}
4229

4330
/**
@@ -49,13 +36,13 @@ public function export(NodeInterface $node): OriginalGraph
4936
* @return Vertex
5037
* A vertex
5138
*/
52-
private function createVertex(NodeInterface $node): Vertex
39+
private function createVertex(NodeInterface $node, OriginalGraph $graph): Vertex
5340
{
5441
/** @var int $vertexId */
5542
$vertexId = $this->createVertexId($node);
5643

57-
if (!$this->getGraph()->hasVertex($vertexId)) {
58-
$vertex = $this->getGraph()->createVertex($vertexId);
44+
if (!$graph->hasVertex($vertexId)) {
45+
$vertex = $graph->createVertex($vertexId);
5946

6047
$vertex->setAttribute(
6148
'graphviz.label',
@@ -69,25 +56,11 @@ private function createVertex(NodeInterface $node): Vertex
6956
}
7057
}
7158

72-
return $this->getGraph()->getVertex($vertexId);
59+
return $graph->getVertex($vertexId);
7360
}
7461

75-
/**
76-
* Create a vertex ID.
77-
*
78-
* @param NodeInterface $node
79-
* The node
80-
*
81-
* @return string
82-
* A vertex ID
83-
*/
8462
private function createVertexId(NodeInterface $node): string
8563
{
8664
return sha1(spl_object_hash($node));
8765
}
88-
89-
private function getGraph(): OriginalGraph
90-
{
91-
return $this->graph;
92-
}
9366
}

0 commit comments

Comments
 (0)