PickComponent::__construct()   A
last analyzed

Complexity

Conditions 5
Paths 6

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 7
nc 6
nop 1
dl 0
loc 12
rs 9.6111
c 0
b 0
f 0
1
<?php
2
3
namespace Lagdo\UiBuilder\Component\Virtual;
4
5
use function is_callable;
6
7
class PickComponent extends VirtualComponent
8
{
9
    /**
10
     * The constructor
11
     *
12
     * @param array $choices
13
     */
14
    public function __construct(array $choices)
15
    {
16
        foreach ($choices as [$condition, $element]) {
17
            if ($condition) {
18
                if (is_callable($element)) {
19
                    $element = $element();
20
                }
21
                if ($element !== null) {
22
                    $this->children[] = $element;
23
                }
24
                // The function exits once a condition is matched.
25
                return;
26
            }
27
        }
28
    }
29
}
30