function GraphTest::normalizeGraph

Same name in other branches
  1. 9 core/tests/Drupal/Tests/Component/Graph/GraphTest.php \Drupal\Tests\Component\Graph\GraphTest::normalizeGraph()
  2. 8.9.x core/tests/Drupal/Tests/Component/Graph/GraphTest.php \Drupal\Tests\Component\Graph\GraphTest::normalizeGraph()
  3. 10 core/tests/Drupal/Tests/Component/Graph/GraphTest.php \Drupal\Tests\Component\Graph\GraphTest::normalizeGraph()

Normalizes a graph.

Parameters

array $graph: A graph array processed by \Drupal\Component\Graph\Graph::searchAndSort()

Return value

array The normalized version of a graph.

1 call to GraphTest::normalizeGraph()
GraphTest::testDepthFirstSearch in core/tests/Drupal/Tests/Component/Graph/GraphTest.php
Tests depth-first-search features.

File

core/tests/Drupal/Tests/Component/Graph/GraphTest.php, line 93

Class

GraphTest
@coversDefaultClass \Drupal\Component\Graph\Graph @group Graph

Namespace

Drupal\Tests\Component\Graph

Code

protected function normalizeGraph($graph) : array {
    $normalized_graph = [];
    foreach ($graph as $vertex => $edges) {
        // Create vertex even if it hasn't any edges.
        $normalized_graph[$vertex] = [];
        foreach ($edges as $edge) {
            $normalized_graph[$vertex]['edges'][$edge] = TRUE;
        }
    }
    return $normalized_graph;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.