Skip to content

Commit 53da7c1

Browse files
FormElements: Fix return type of createElement() method and related code
This fixes the confusion of phpstan. Since the `createElement()` element returns an instance of `FormElement`, phpstan cannot find an `addHtml()` method for it, for example. The return type must therefore be `FormElement & BaseHtmlElement`.
1 parent ad522bf commit 53da7c1

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

src/FormElement/FormElements.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace ipl\Html\FormElement;
44

55
use InvalidArgumentException;
6+
use ipl\Html\BaseHtmlElement;
67
use ipl\Html\Contract\FormElement;
78
use ipl\Html\Contract\FormElementDecorator;
89
use ipl\Html\Contract\ValueCandidates;
@@ -29,7 +30,7 @@ trait FormElements
2930
/** @var bool Whether the default element loader has been registered */
3031
protected $defaultElementLoaderRegistered = false;
3132

32-
/** @var FormElement[] */
33+
/** @var (FormElement & BaseHtmlElement)[] */
3334
private $elements = [];
3435

3536
/** @var array<string, array<int, mixed>> */
@@ -38,7 +39,7 @@ trait FormElements
3839
/**
3940
* Get all elements
4041
*
41-
* @return FormElement[]
42+
* @return (FormElement & BaseHtmlElement)[]
4243
*/
4344
public function getElements()
4445
{
@@ -70,7 +71,7 @@ public function hasElement($element)
7071
*
7172
* @param string $name
7273
*
73-
* @return FormElement
74+
* @return FormElement & BaseHtmlElement
7475
*
7576
* @throws InvalidArgumentException If no element with the given name exists
7677
*/
@@ -137,7 +138,7 @@ public function addElement($typeOrElement, $name = null, $options = null)
137138
* @param string $name Name of the element
138139
* @param mixed $options Element options as key-value pairs
139140
*
140-
* @return FormElement
141+
* @return FormElement & BaseHtmlElement
141142
*
142143
* @throws InvalidArgumentException If the type of the element is unknown
143144
*/
@@ -154,7 +155,7 @@ public function createElement($type, $name, $options = null)
154155
));
155156
}
156157

157-
/** @var FormElement $element */
158+
/** @var FormElement & BaseFormElement $element */
158159
$element = new $class($name);
159160

160161
if ($options !== null) {

0 commit comments

Comments
 (0)