StructuredElements   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 86.67%

Importance

Changes 4
Bugs 2 Features 1
Metric Value
wmc 6
c 4
b 2
f 1
lcom 1
cbo 1
dl 0
loc 62
ccs 13
cts 15
cp 0.8667
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 3
A getElements() 0 4 1
A getStructure() 0 4 1
A render() 0 11 1
1
<?php
2
3
namespace Matks\Vivian\Output;
4
5
use Matks\Vivian\Structure\Structure;
6
use Matks\Vivian\Structure\StructureManager;
7
8
/**
9
 * Structured Elements
10
 *
11
 * Array of TextElements to be echoed printed in a structured way
12
 */
13
class StructuredElements
14
{
15
16
    /**
17
     * @var TextElement[]
18
     */
19
    private $elements;
20
21
    /**
22
     * @var Structure
23
     */
24
    private $structure;
25
26
    /**
27
     * @param TextElement[] $elements
28
     * @param Structure     $structure
29
     */
30
    public function __construct(array $elements, Structure $structure)
31
    {
32 1
        foreach ($elements as $element) {
33 1
            if (!($element instanceof \Matks\Vivian\Output\TextElement)) {
34
                throw new \InvalidArgumentException('Provided array should contain only TextElement, ' . get_class($element) . ' provided instead');
35
            }
36 1
        }
37
38 1
        $this->elements  = $elements;
39 1
        $this->structure = $structure;
40 1
    }
41
42
    /**
43
     * @return TextElement[]
44
     */
45
    public function getElements()
46
    {
47
        return $this->elements;
48
    }
49
50
    /**
51
     * @return Structure
52
     */
53
    public function getStructure()
54
    {
55 1
        return $this->structure;
56
    }
57
58
    /**
59
     * Render structured element
60
     *
61
     * @return string
62
     */
63
    public function render()
64
    {
65 1
        $renderFunction = function (&$element, $key) {
0 ignored issues
show
Unused Code introduced by
The parameter $key is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
66 1
            $element = $element->render();
67 1
        };
68 1
        array_walk($this->elements, $renderFunction);
69
70 1
        $structuredElements = StructureManager::buildStructure($this->elements, $this->structure);
71
72 1
        return $structuredElements;
73
    }
74
}
75