PickComponent   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 19
rs 10
c 0
b 0
f 0
wmc 5

1 Method

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 12 5
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