diff --git a/UPGRADE.md b/UPGRADE.md index b44985a699..e8d5802d1c 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -1,5 +1,15 @@ # Upgrade to 2.14 +## Deprecated constants of `Doctrine\ORM\Internal\CommitOrderCalculator` + +The following public constants have been deprecated: + +* `CommitOrderCalculator::NOT_VISITED` +* `CommitOrderCalculator::IN_PROGRESS` +* `CommitOrderCalculator::VISITED` + +These constants were used for internal purposes. Relying on them is discouraged. + ## Deprecated `Doctrine\ORM\Query\AST\InExpression` The AST parser will create a `InListExpression` or a `InSubselectExpression` when diff --git a/lib/Doctrine/ORM/Internal/CommitOrder/Edge.php b/lib/Doctrine/ORM/Internal/CommitOrder/Edge.php new file mode 100644 index 0000000000..f1457755ee --- /dev/null +++ b/lib/Doctrine/ORM/Internal/CommitOrder/Edge.php @@ -0,0 +1,34 @@ +from = $from; + $this->to = $to; + $this->weight = $weight; + } +} diff --git a/lib/Doctrine/ORM/Internal/CommitOrder/Vertex.php b/lib/Doctrine/ORM/Internal/CommitOrder/Vertex.php new file mode 100644 index 0000000000..c4747e032d --- /dev/null +++ b/lib/Doctrine/ORM/Internal/CommitOrder/Vertex.php @@ -0,0 +1,38 @@ + */ + public $dependencyList = []; + + public function __construct(string $hash, ClassMetadata $value) + { + $this->hash = $hash; + $this->value = $value; + } +} diff --git a/lib/Doctrine/ORM/Internal/CommitOrder/VertexState.php b/lib/Doctrine/ORM/Internal/CommitOrder/VertexState.php new file mode 100644 index 0000000000..395db58d55 --- /dev/null +++ b/lib/Doctrine/ORM/Internal/CommitOrder/VertexState.php @@ -0,0 +1,17 @@ +state (integer) - * Whether the node is NOT_VISITED or IN_PROGRESS - * - * - value (object) - * Actual node value * - * - dependencyList (array) - * Map of node dependencies defined as hashes. + * Keys are provided hashes and values are the node definition objects. * - * @var array + * @var array */ private $nodeList = []; /** * Volatile variable holding calculated nodes during sorting process. * - * @psalm-var list + * @psalm-var list */ private $sortedNodeList = []; @@ -62,21 +60,14 @@ public function hasNode($hash) /** * Adds a new node (vertex) to the graph, assigning its hash and value. * - * @param string $hash - * @param object $node + * @param string $hash + * @param ClassMetadata $node * * @return void */ public function addNode($hash, $node) { - $vertex = new stdClass(); - - $vertex->hash = $hash; - $vertex->state = self::NOT_VISITED; - $vertex->value = $node; - $vertex->dependencyList = []; - - $this->nodeList[$hash] = $vertex; + $this->nodeList[$hash] = new Vertex($hash, $node); } /** @@ -90,14 +81,8 @@ public function addNode($hash, $node) */ public function addDependency($fromHash, $toHash, $weight) { - $vertex = $this->nodeList[$fromHash]; - $edge = new stdClass(); - - $edge->from = $fromHash; - $edge->to = $toHash; - $edge->weight = $weight; - - $vertex->dependencyList[$toHash] = $edge; + $this->nodeList[$fromHash]->dependencyList[$toHash] + = new Edge($fromHash, $toHash, $weight); } /** @@ -106,12 +91,12 @@ public function addDependency($fromHash, $toHash, $weight) * * {@internal Highly performance-sensitive method.} * - * @psalm-return list + * @psalm-return list */ public function sort() { foreach ($this->nodeList as $vertex) { - if ($vertex->state !== self::NOT_VISITED) { + if ($vertex->state !== VertexState::NOT_VISITED) { continue; } @@ -131,19 +116,19 @@ public function sort() * * {@internal Highly performance-sensitive method.} */ - private function visit(stdClass $vertex): void + private function visit(Vertex $vertex): void { - $vertex->state = self::IN_PROGRESS; + $vertex->state = VertexState::IN_PROGRESS; foreach ($vertex->dependencyList as $edge) { $adjacentVertex = $this->nodeList[$edge->to]; switch ($adjacentVertex->state) { - case self::VISITED: + case VertexState::VISITED: // Do nothing, since node was already visited break; - case self::IN_PROGRESS: + case VertexState::IN_PROGRESS: if ( isset($adjacentVertex->dependencyList[$vertex->hash]) && $adjacentVertex->dependencyList[$vertex->hash]->weight < $edge->weight @@ -153,25 +138,25 @@ private function visit(stdClass $vertex): void foreach ($adjacentVertex->dependencyList as $adjacentEdge) { $adjacentEdgeVertex = $this->nodeList[$adjacentEdge->to]; - if ($adjacentEdgeVertex->state === self::NOT_VISITED) { + if ($adjacentEdgeVertex->state === VertexState::NOT_VISITED) { $this->visit($adjacentEdgeVertex); } } - $adjacentVertex->state = self::VISITED; + $adjacentVertex->state = VertexState::VISITED; $this->sortedNodeList[] = $adjacentVertex->value; } break; - case self::NOT_VISITED: + case VertexState::NOT_VISITED: $this->visit($adjacentVertex); } } - if ($vertex->state !== self::VISITED) { - $vertex->state = self::VISITED; + if ($vertex->state !== VertexState::VISITED) { + $vertex->state = VertexState::VISITED; $this->sortedNodeList[] = $vertex->value; } diff --git a/lib/Doctrine/ORM/UnitOfWork.php b/lib/Doctrine/ORM/UnitOfWork.php index b44b0cbb9a..a859ccc46b 100644 --- a/lib/Doctrine/ORM/UnitOfWork.php +++ b/lib/Doctrine/ORM/UnitOfWork.php @@ -1281,7 +1281,7 @@ private function executeDeletions(ClassMetadata $class): void /** * Gets the commit order. * - * @return list + * @return list */ private function getCommitOrder(): array { diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 37387f0cd1..613a58b3f6 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -410,13 +410,9 @@ - - $this->sortedNodeList - $this->sortedNodeList - - $vertex->state !== self::VISITED - $vertex->state !== self::VISITED + $vertex->state !== VertexState::VISITED + $vertex->state !== VertexState::VISITED @@ -2895,10 +2891,6 @@ - - $class - $class - ! is_object($object) is_object($object)