Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FormElements: Fix return type of createElement() method and related code #138

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 0 additions & 20 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -240,11 +240,6 @@ parameters:
count: 1
path: src/Form.php

-
message: "#^Parameter \\#1 \\$attributes of method ipl\\\\Html\\\\Contract\\\\FormElement\\:\\:addAttributes\\(\\) expects iterable, mixed given\\.$#"
count: 1
path: src/Form.php

-
message: "#^Parameter \\#1 \\.\\.\\.\\$arrays of function array_merge_recursive expects array, array\\|object\\|null given\\.$#"
count: 1
Expand Down Expand Up @@ -362,11 +357,6 @@ parameters:

-
message: "#^Cannot access offset 'name' on mixed\\.$#"
count: 2
path: src/FormElement/BaseFormElement.php

-
message: "#^Method ipl\\\\Html\\\\FormElement\\\\BaseFormElement\\:\\:addValidators\\(\\) has parameter \\$validators with no value type specified in iterable type iterable\\.$#"
count: 1
path: src/FormElement/BaseFormElement.php

Expand Down Expand Up @@ -395,11 +385,6 @@ parameters:
count: 1
path: src/FormElement/BaseFormElement.php

-
message: "#^Method ipl\\\\Html\\\\FormElement\\\\BaseFormElement\\:\\:setValidators\\(\\) has parameter \\$validators with no value type specified in iterable type iterable\\.$#"
count: 1
path: src/FormElement/BaseFormElement.php

-
message: "#^Parameter \\#1 \\$attributes of method ipl\\\\Html\\\\BaseHtmlElement\\:\\:addAttributes\\(\\) expects array\\|ipl\\\\Html\\\\Attributes, mixed given\\.$#"
count: 1
Expand Down Expand Up @@ -435,11 +420,6 @@ parameters:
count: 1
path: src/FormElement/FieldsetElement.php

-
message: "#^Parameter \\#1 \\$attributes of method ipl\\\\Html\\\\Contract\\\\FormElement\\:\\:addAttributes\\(\\) expects iterable, mixed given\\.$#"
count: 1
path: src/FormElement/FieldsetElement.php

-
message: "#^Parameter \\#3 \\$postfix of method ipl\\\\Html\\\\FormElement\\\\FieldsetElement\\:\\:addPluginLoader\\(\\) expects string, string\\|null given\\.$#"
count: 2
Expand Down
5 changes: 3 additions & 2 deletions src/FormElement/BaseFormElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use ipl\Stdlib\Messages;
use ipl\Validator\ValidatorChain;
use ReflectionProperty;
use Traversable;

abstract class BaseFormElement extends BaseHtmlElement implements FormElement, ValueCandidates
{
Expand Down Expand Up @@ -184,7 +185,7 @@ public function getValidators()
/**
* Set the validators
*
* @param iterable $validators
* @param Traversable<int|string, mixed> $validators
*
* @return $this
*/
Expand All @@ -201,7 +202,7 @@ public function setValidators($validators)
/**
* Add validators
*
* @param iterable $validators
* @param Traversable<int|string, mixed> $validators
*
* @return $this
*/
Expand Down
21 changes: 11 additions & 10 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 All @@ -89,9 +90,9 @@ public function getElement($name)
/**
* Add an element
*
* @param string|FormElement $typeOrElement Type of the element as string or an instance of FormElement
* @param string $name Name of the element
* @param mixed $options Element options as key-value pairs
* @param string|(FormElement & BaseHtmlElement) $typeOrElement Element name OR FormElement instance
* @param string $name Name of the element
* @param array<string, mixed>|null $options Element options as key-value pairs
*
* @return $this
*
Expand Down Expand Up @@ -135,9 +136,9 @@ public function addElement($typeOrElement, $name = null, $options = null)
*
* @param string $type Type of the element
* @param string $name Name of the element
* @param mixed $options Element options as key-value pairs
* @param array<string, mixed>|null $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 All @@ -169,7 +170,7 @@ public function createElement($type, $name, $options = null)
*
* Registers the element for value and validation handling but does not add it to the render stack.
*
* @param FormElement $element
* @param FormElement & BaseHtmlElement $element
*
* @return $this
*
Expand Down
Loading