NodesBuilder   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 11
c 1
b 0
f 0
dl 0
loc 17
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A build() 0 15 3
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));
0 ignored issues
show
Bug introduced by
It seems like $collection->atPosition($line - 1, $column) can also be of type array; however, parameter $top of Knp\FriendlyContexts\Table\Node::setTop() does only seem to accept Knp\FriendlyContexts\Table\Node|null, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

17
                $node->setTop(/** @scrutinizer ignore-type */ $collection->atPosition($line - 1, $column));
Loading history...
18
                $node->setBottom($collection->atPosition($line + 1, $column));
0 ignored issues
show
Bug introduced by
It seems like $collection->atPosition($line + 1, $column) can also be of type array; however, parameter $bottom of Knp\FriendlyContexts\Table\Node::setBottom() does only seem to accept Knp\FriendlyContexts\Table\Node|null, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

18
                $node->setBottom(/** @scrutinizer ignore-type */ $collection->atPosition($line + 1, $column));
Loading history...
19
                $node->setLeft($collection->atPosition($line, $column - 1));
0 ignored issues
show
Bug introduced by
It seems like $collection->atPosition($line, $column - 1) can also be of type array; however, parameter $left of Knp\FriendlyContexts\Table\Node::setLeft() does only seem to accept Knp\FriendlyContexts\Table\Node|null, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

19
                $node->setLeft(/** @scrutinizer ignore-type */ $collection->atPosition($line, $column - 1));
Loading history...
20
                $node->setLeft($collection->atPosition($line, $column + 1));
21
            }
22
        }
23
24
        return $collection;
25
    }
26
}
27