NodesBuilder::build()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 16
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 16
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 11
nc 3
nop 1
1
<?php
2
3
namespace Knp\FriendlyContexts\Table;
4
5
use Knp\FriendlyContexts\Table\Node;
6
use Knp\FriendlyContexts\Table\NodeCollection;
7
8
class NodesBuilder
9
{
10
    public function build(array $table)
11
    {
12
        $collection = new NodeCollection;
13
        foreach ($table as $line => $columns) {
14
            foreach ($columns as $column => $content) {
15
                $collection->addNode($node = new Node, $line, $column);
16
                $node->setContent($content);
17
                $node->setTop($collection->atPosition($line - 1, $column));
18
                $node->setBottom($collection->atPosition($line + 1, $column));
19
                $node->setLeft($collection->atPosition($line, $column - 1));
20
                $node->setLeft($collection->atPosition($line, $column + 1));
21
            }
22
        }
23
24
        return $collection;
25
    }
26
}
27