From b95529d5d0da45687b6d2bcccf77904561f9f73f Mon Sep 17 00:00:00 2001 From: Matthias Pigulla Date: Tue, 2 Jan 2024 19:49:06 +0100 Subject: [PATCH] Fix CS --- .../Internal/StronglyConnectedComponents.php | 39 ++++++++++--------- lib/Doctrine/ORM/UnitOfWork.php | 6 +-- .../StronglyConnectedComponentsTest.php | 2 +- 3 files changed, 25 insertions(+), 22 deletions(-) diff --git a/lib/Doctrine/ORM/Internal/StronglyConnectedComponents.php b/lib/Doctrine/ORM/Internal/StronglyConnectedComponents.php index f2ccd434133..48082b19da6 100644 --- a/lib/Doctrine/ORM/Internal/StronglyConnectedComponents.php +++ b/lib/Doctrine/ORM/Internal/StronglyConnectedComponents.php @@ -4,7 +4,12 @@ namespace Doctrine\ORM\Internal; +use InvalidArgumentException; + use function array_keys; +use function array_pop; +use function array_push; +use function min; use function spl_object_id; /** @@ -22,7 +27,7 @@ final class StronglyConnectedComponents { private const NOT_VISITED = 1; private const IN_PROGRESS = 2; - private const VISITED = 3; + private const VISITED = 3; /** * Array of all nodes, indexed by object ids. @@ -61,9 +66,7 @@ final class StronglyConnectedComponents */ private $lowlink = []; - /** - * @var int - */ + /** @var int */ private $maxdfs = 0; /** @@ -73,18 +76,16 @@ final class StronglyConnectedComponents */ private $representingNodes = []; - /** - * @var array - */ + /** @var array */ private $stack = []; /** @param object $node */ public function addNode($node): void { - $id = spl_object_id($node); - $this->nodes[$id] = $node; + $id = spl_object_id($node); + $this->nodes[$id] = $node; $this->states[$id] = self::NOT_VISITED; - $this->edges[$id] = []; + $this->edges[$id] = []; } /** @param object $node */ @@ -102,7 +103,7 @@ public function hasNode($node): bool public function addEdge($from, $to): void { $fromId = spl_object_id($from); - $toId = spl_object_id($to); + $toId = spl_object_id($to); $this->edges[$fromId][$toId] = true; } @@ -118,15 +119,15 @@ public function findStronglyConnectedComponents(): void private function tarjan(int $oid): void { - $this->dfs[$oid] = $this->lowlink[$oid] = $this->maxdfs++; + $this->dfs[$oid] = $this->lowlink[$oid] = $this->maxdfs++; $this->states[$oid] = self::IN_PROGRESS; array_push($this->stack, $oid); - foreach ($this->edges[$oid] as $adjacentId => $_) { + foreach ($this->edges[$oid] as $adjacentId => $ignored) { if ($this->states[$adjacentId] === self::NOT_VISITED) { $this->tarjan($adjacentId); $this->lowlink[$oid] = min($this->lowlink[$oid], $this->lowlink[$adjacentId]); - } else if ($this->states[$adjacentId] === self::IN_PROGRESS) { + } elseif ($this->states[$adjacentId] === self::IN_PROGRESS) { $this->lowlink[$oid] = min($this->lowlink[$oid], $this->dfs[$adjacentId]); } } @@ -137,25 +138,27 @@ private function tarjan(int $oid): void do { $unwindOid = array_pop($this->stack); - if (!$representingNode) { + if (! $representingNode) { $representingNode = $this->nodes[$unwindOid]; } + $this->representingNodes[$unwindOid] = $representingNode; - $this->states[$unwindOid] = self::VISITED; + $this->states[$unwindOid] = self::VISITED; } while ($unwindOid !== $oid); } } /** * @param object $node + * * @return object */ public function getNodeRepresentingStronglyConnectedComponent($node) { $oid = spl_object_id($node); - if (!isset($this->representingNodes[$oid])) { - throw new \InvalidArgumentException('unknown node'); + if (! isset($this->representingNodes[$oid])) { + throw new InvalidArgumentException('unknown node'); } return $this->representingNodes[$oid]; diff --git a/lib/Doctrine/ORM/UnitOfWork.php b/lib/Doctrine/ORM/UnitOfWork.php index 5df0df33daf..bd2d0ba5910 100644 --- a/lib/Doctrine/ORM/UnitOfWork.php +++ b/lib/Doctrine/ORM/UnitOfWork.php @@ -1393,7 +1393,7 @@ private function computeInsertExecutionOrder(): array private function computeDeleteExecutionOrder(): array { $stronglyConnectedComponents = new StronglyConnectedComponents(); - $sort = new TopologicalSort(); + $sort = new TopologicalSort(); foreach ($this->entityDeletions as $entity) { $stronglyConnectedComponents->addNode($entity); @@ -1412,13 +1412,13 @@ private function computeDeleteExecutionOrder(): array // We only need to consider the owning sides of to-one associations, // since many-to-many associations can always be (and have already been) // deleted in a preceding step. - if (!($assoc['isOwningSide'] && $assoc['type'] & ClassMetadata::TO_ONE)) { + if (! ($assoc['isOwningSide'] && $assoc['type'] & ClassMetadata::TO_ONE)) { continue; } assert(isset($assoc['joinColumns'])); $joinColumns = reset($assoc['joinColumns']); - if (!isset($joinColumns['onDelete'])) { + if (! isset($joinColumns['onDelete'])) { continue; } diff --git a/tests/Doctrine/Tests/ORM/Internal/StronglyConnectedComponentsTest.php b/tests/Doctrine/Tests/ORM/Internal/StronglyConnectedComponentsTest.php index fe66f0a41a4..a2adee9dc22 100644 --- a/tests/Doctrine/Tests/ORM/Internal/StronglyConnectedComponentsTest.php +++ b/tests/Doctrine/Tests/ORM/Internal/StronglyConnectedComponentsTest.php @@ -84,7 +84,7 @@ public function testFindStronglyConnectedComponents3(): void private function addNodes(string ...$names): void { foreach ($names as $name) { - $node = new Node($name); + $node = new Node($name); $this->nodes[$name] = $node; $this->stronglyConnectedComponents->addNode($node); }