function GraphTest::normalizeGraph

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

Normalizes a graph.

Parameters

$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 91

Class

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

Namespace

Drupal\Tests\Component\Graph

Code

protected function normalizeGraph($graph) {
    $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.