Passed
Push — main ( 7f60ea...60225c )
by Thierry
08:29
created

ElementExprWhen   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 6
c 1
b 0
f 0
dl 0
loc 18
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 4
1
<?php
2
3
namespace Lagdo\UiBuilder\Builder\Html;
4
5
use Closure;
6
7
use function is_callable;
8
9
class ElementExprWhen extends ElementExprList
10
{
11
    /**
12
     * The constructor
13
     *
14
     * @param bool $condition
15
     * @param Closure|AbstractElement $element
16
     */
17
    public function __construct(bool $condition, Closure|AbstractElement $element)
18
    {
19
        if (!$condition) {
20
            return;
21
        }
22
        if (is_callable($element)) {
23
            $element = $element();
24
        }
25
        if ($element !== null) {
26
            $this->children[] = $element;
27
        }
28
    }
29
}
30