77use Doctrine \ORM \Internal \CommitOrder \Edge ;
88use Doctrine \ORM \Internal \CommitOrder \Vertex ;
99use Doctrine \ORM \Internal \CommitOrder \VertexState ;
10- use Doctrine \ORM \Mapping \ClassMetadata ;
1110
1211use function array_reverse ;
1312
@@ -34,55 +33,42 @@ class CommitOrderCalculator
3433 *
3534 * Keys are provided hashes and values are the node definition objects.
3635 *
37- * @var array<string , Vertex>
36+ * @var array<int , Vertex>
3837 */
3938 private $ nodeList = [];
4039
4140 /**
4241 * Volatile variable holding calculated nodes during sorting process.
4342 *
44- * @psalm-var list<ClassMetadata >
43+ * @psalm-var array<int, object >
4544 */
4645 private $ sortedNodeList = [];
4746
4847 /**
4948 * Checks for node (vertex) existence in graph.
50- *
51- * @param string $hash
52- *
53- * @return bool
5449 */
55- public function hasNode ($ hash )
50+ public function hasNode (int $ hash ): book
5651 {
5752 return isset ($ this ->nodeList [$ hash ]);
5853 }
5954
6055 /**
6156 * Adds a new node (vertex) to the graph, assigning its hash and value.
6257 *
63- * @param string $hash
64- * @param ClassMetadata $node
65- *
66- * @return void
58+ * @param object $node
6759 */
68- public function addNode ($ hash , $ node )
60+ public function addNode (int $ hash , $ node ): void
6961 {
7062 $ this ->nodeList [$ hash ] = new Vertex ($ hash , $ node );
7163 }
7264
7365 /**
7466 * Adds a new dependency (edge) to the graph using their hashes.
75- *
76- * @param string $fromHash
77- * @param string $toHash
78- * @param int $weight
79- *
80- * @return void
8167 */
82- public function addDependency ($ fromHash , $ toHash , $ weight )
68+ public function addDependency (int $ fromHash , int $ toHash , bool $ optional ): void
8369 {
8470 $ this ->nodeList [$ fromHash ]->dependencyList [$ toHash ]
85- = new Edge ($ fromHash , $ toHash , $ weight );
71+ = new Edge ($ fromHash , $ toHash , $ optional );
8672 }
8773
8874 /**
@@ -91,7 +77,7 @@ public function addDependency($fromHash, $toHash, $weight)
9177 *
9278 * {@internal Highly performance-sensitive method.}
9379 *
94- * @psalm-return list<ClassMetadata >
80+ * @psalm-return list<object >
9581 */
9682 public function sort ()
9783 {
@@ -108,7 +94,7 @@ public function sort()
10894 $ this ->nodeList = [];
10995 $ this ->sortedNodeList = [];
11096
111- return array_reverse ($ sortedList );
97+ return array_reverse ($ sortedList, true );
11298 }
11399
114100 /**
@@ -131,7 +117,7 @@ private function visit(Vertex $vertex): void
131117 case VertexState::IN_PROGRESS :
132118 if (
133119 isset ($ adjacentVertex ->dependencyList [$ vertex ->hash ]) &&
134- $ adjacentVertex ->dependencyList [$ vertex ->hash ]->weight < $ edge ->weight
120+ $ adjacentVertex ->dependencyList [$ vertex ->hash ]->optional < $ edge ->optional
135121 ) {
136122 // If we have some non-visited dependencies in the in-progress dependency, we
137123 // need to visit them before adding the node.
@@ -145,7 +131,7 @@ private function visit(Vertex $vertex): void
145131
146132 $ adjacentVertex ->state = VertexState::VISITED ;
147133
148- $ this ->sortedNodeList [] = $ adjacentVertex ->value ;
134+ $ this ->sortedNodeList [$ adjacentVertex -> hash ] = $ adjacentVertex ->value ;
149135 }
150136
151137 break ;
@@ -158,7 +144,7 @@ private function visit(Vertex $vertex): void
158144 if ($ vertex ->state !== VertexState::VISITED ) {
159145 $ vertex ->state = VertexState::VISITED ;
160146
161- $ this ->sortedNodeList [] = $ vertex ->value ;
147+ $ this ->sortedNodeList [$ vertex -> hash ] = $ vertex ->value ;
162148 }
163149 }
164150}
0 commit comments