Issues (4)

src/AbstractBuilder.php (2 issues)

Labels
Severity
1
<?php
2
3
namespace Lagdo\UiBuilder;
4
5
use Lagdo\UiBuilder\Builder\Html\AbstractElement;
6
use Lagdo\UiBuilder\Builder\Html\Element;
7
use Lagdo\UiBuilder\Builder\Html\ElementExprEach;
8
use Lagdo\UiBuilder\Builder\Html\ElementExprList;
9
use Lagdo\UiBuilder\Builder\Html\ElementExprWhen;
10
use Lagdo\UiBuilder\Builder\Html\HtmlBuilder;
11
use Lagdo\UiBuilder\Element\ElementInterface;
12
use Lagdo\UiBuilder\Element\ColInterface;
13
use Lagdo\UiBuilder\Element\RowInterface;
14
use Closure;
15
16
abstract class AbstractBuilder implements BuilderInterface
17
{
18
    /**
19
     * @var HtmlBuilder
20
     */
21
    protected $builder;
22
23
    /**
24
     * The constructor
25
     */
26
    public function __construct()
27
    {
28
        $this->builder = new HtmlBuilder();
29
        $this->builder->addElementBuilder('form', function(Element|null $element,
30
            string $tagName, string $method, array $arguments) {
31
            return $this->createFormElement($tagName, $arguments);
32
        });
33
    }
34
35
    /**
36
     * @param string $method
37
     * @param array $arguments
38
     *
39
     * @return ElementInterface
40
     */
41
    public function __call(string $method, array $arguments): mixed
42
    {
43
        return $this->builder->make($method, $arguments);
44
    }
45
46
    /**
47
     * @param string $tagPrefix
48
     * @param Closure $tagBuilder
49
     *
50
     * @return void
51
     */
52
    public function addElementBuilder(string $tagPrefix, Closure $tagBuilder)
53
    {
54
        $this->builder->addElementBuilder($tagPrefix, $tagBuilder);
55
    }
56
57
    /**
58
     * @param string $name
59
     *
60
     * @return ElementInterface
61
     */
62
    public function tag(string $name, ...$arguments): ElementInterface
63
    {
64
        return $this->builder->createElement($name, $arguments);
65
    }
66
67
    /**
68
     * Create an element of a given class name
69
     *
70
     * @template T of Element
71
     * @psalm-param class-string<T> $class
72
     * @param array $arguments
73
     *
74
     * @return T
0 ignored issues
show
The type Lagdo\UiBuilder\T was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
75
     */
76
    protected function createElementOfClass(string $class, $arguments): Element
77
    {
78
        return $this->builder->createElement($class::$tag, $arguments, $class);
0 ignored issues
show
The property tag does not exist on string.
Loading history...
79
    }
80
81
    /**
82
     * @param string $tagName
83
     * @param array $arguments
84
     *
85
     * @return ElementInterface
86
     */
87
    abstract protected function createFormElement(string $tagName, $arguments): ElementInterface;
88
89
    /**
90
     * @inheritDoc
91
     */
92
    public function formRow(...$arguments): RowInterface
93
    {
94
        return $this->row(...$arguments);
95
    }
96
97
    /**
98
     * @inheritDoc
99
     */
100
    public function formCol(...$arguments): ColInterface
101
    {
102
        return $this->col(...$arguments);
103
    }
104
105
    /**
106
     * @param array $values
107
     * @param Closure $closure
108
     *
109
     * @return ElementExprEach
110
     */
111
    public function each(array $values, Closure $closure): AbstractElement
112
    {
113
        return new ElementExprEach($values, $closure);
114
    }
115
116
    /**
117
     * @return AbstractElement
118
     */
119
    public function list(...$arguments): AbstractElement
120
    {
121
        return new ElementExprList($arguments);
122
    }
123
124
    /**
125
     * @param bool $condition
126
     * @param Closure $closure
127
     *
128
     * @return AbstractElement
129
     */
130
    public function when(bool $condition, Closure $closure): AbstractElement
131
    {
132
        return new ElementExprWhen($condition, $closure);
133
    }
134
135
    /**
136
     * @inheritDoc
137
     */
138
    public function build(...$arguments): string
139
    {
140
        return $this->builder->build($arguments);
141
    }
142
}
143