Skip to content

Commit

Permalink
Fix CS
Browse files Browse the repository at this point in the history
  • Loading branch information
mpdude committed Jan 3, 2024
1 parent fb9ff08 commit b95529d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 22 deletions.
39 changes: 21 additions & 18 deletions lib/Doctrine/ORM/Internal/StronglyConnectedComponents.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -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.
Expand Down Expand Up @@ -61,9 +66,7 @@ final class StronglyConnectedComponents
*/
private $lowlink = [];

/**
* @var int
*/
/** @var int */
private $maxdfs = 0;

/**
Expand All @@ -73,18 +76,16 @@ final class StronglyConnectedComponents
*/
private $representingNodes = [];

/**
* @var array<int>
*/
/** @var array<int> */
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 */
Expand All @@ -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;
}
Expand All @@ -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]);
}
}
Expand All @@ -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');

Check warning on line 161 in lib/Doctrine/ORM/Internal/StronglyConnectedComponents.php

View check run for this annotation

Codecov / codecov/patch

lib/Doctrine/ORM/Internal/StronglyConnectedComponents.php#L161

Added line #L161 was not covered by tests
}

return $this->representingNodes[$oid];
Expand Down
6 changes: 3 additions & 3 deletions lib/Doctrine/ORM/UnitOfWork.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit b95529d

Please sign in to comment.