Skip to content

Commit

Permalink
FormElements: Fix return type of createElement() method and related…
Browse files Browse the repository at this point in the history
… 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`.
  • Loading branch information
sukhwinder33445 committed May 3, 2024
1 parent ad522bf commit 53da7c1
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/FormElement/FormElements.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace ipl\Html\FormElement;

use InvalidArgumentException;
use ipl\Html\BaseHtmlElement;
use ipl\Html\Contract\FormElement;
use ipl\Html\Contract\FormElementDecorator;
use ipl\Html\Contract\ValueCandidates;
Expand All @@ -29,7 +30,7 @@ trait FormElements
/** @var bool Whether the default element loader has been registered */
protected $defaultElementLoaderRegistered = false;

/** @var FormElement[] */
/** @var (FormElement & BaseHtmlElement)[] */
private $elements = [];

/** @var array<string, array<int, mixed>> */
Expand All @@ -38,7 +39,7 @@ trait FormElements
/**
* Get all elements
*
* @return FormElement[]
* @return (FormElement & BaseHtmlElement)[]
*/
public function getElements()
{
Expand Down Expand Up @@ -70,7 +71,7 @@ public function hasElement($element)
*
* @param string $name
*
* @return FormElement
* @return FormElement & BaseHtmlElement
*
* @throws InvalidArgumentException If no element with the given name exists
*/
Expand Down Expand Up @@ -137,7 +138,7 @@ public function addElement($typeOrElement, $name = null, $options = null)
* @param string $name Name of the element
* @param mixed $options Element options as key-value pairs
*
* @return FormElement
* @return FormElement & BaseHtmlElement
*
* @throws InvalidArgumentException If the type of the element is unknown
*/
Expand All @@ -154,7 +155,7 @@ public function createElement($type, $name, $options = null)
));
}

/** @var FormElement $element */
/** @var FormElement & BaseFormElement $element */
$element = new $class($name);

if ($options !== null) {
Expand Down

0 comments on commit 53da7c1

Please sign in to comment.