Skip to content

Commit

Permalink
Add key & value type hint to all properties of type array
Browse files Browse the repository at this point in the history
  • Loading branch information
yhabteab authored and nilmerg committed Sep 1, 2023
1 parent 638e65e commit ad522bf
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 71 deletions.
65 changes: 0 additions & 65 deletions phpstan-baseline.neon
Expand Up @@ -155,11 +155,6 @@ parameters:
count: 1
path: src/BaseHtmlElement.php

-
message: "#^Property ipl\\\\Html\\\\BaseHtmlElement\\:\\:\\$defaultAttributes type has no value type specified in iterable type array\\.$#"
count: 1
path: src/BaseHtmlElement.php

-
message: "#^Property ipl\\\\Html\\\\BaseHtmlElement\\:\\:\\$voidElements type has no value type specified in iterable type array\\.$#"
count: 1
Expand All @@ -180,16 +175,6 @@ parameters:
count: 1
path: src/Contract/FormElementDecorator.php

-
message: "#^Method ipl\\\\Html\\\\Contract\\\\ValueCandidates\\:\\:getValueCandidates\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: src/Contract/ValueCandidates.php

-
message: "#^Method ipl\\\\Html\\\\Contract\\\\ValueCandidates\\:\\:setValueCandidates\\(\\) has parameter \\$values with no value type specified in iterable type array\\.$#"
count: 1
path: src/Contract/ValueCandidates.php

-
message: "#^Method ipl\\\\Html\\\\Error\\:\\:getPhpTypeName\\(\\) has no return type specified\\.$#"
count: 1
Expand Down Expand Up @@ -235,11 +220,6 @@ parameters:
count: 1
path: src/Form.php

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

-
message: "#^Method ipl\\\\Html\\\\Form\\:\\:registerAttributeCallbacks\\(\\) has no return type specified\\.$#"
count: 1
Expand Down Expand Up @@ -280,11 +260,6 @@ parameters:
count: 1
path: src/Form.php

-
message: "#^Property ipl\\\\Html\\\\Form\\:\\:\\$populatedValues type has no value type specified in iterable type array\\.$#"
count: 1
path: src/Form.php

-
message: "#^Property ipl\\\\Html\\\\Form\\:\\:\\$submitButton \\(ipl\\\\Html\\\\Contract\\\\FormSubmitElement\\) does not accept null\\.$#"
count: 1
Expand Down Expand Up @@ -395,11 +370,6 @@ parameters:
count: 1
path: src/FormElement/BaseFormElement.php

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

-
message: "#^Method ipl\\\\Html\\\\FormElement\\\\BaseFormElement\\:\\:getValueOfNameAttribute\\(\\) has no return type specified\\.$#"
count: 1
Expand Down Expand Up @@ -430,21 +400,11 @@ parameters:
count: 1
path: src/FormElement/BaseFormElement.php

-
message: "#^Method ipl\\\\Html\\\\FormElement\\\\BaseFormElement\\:\\:setValueCandidates\\(\\) has parameter \\$values with no value type specified in iterable type array\\.$#"
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
path: src/FormElement/BaseFormElement.php

-
message: "#^Property ipl\\\\Html\\\\FormElement\\\\BaseFormElement\\:\\:\\$valueCandidates type has no value type specified in iterable type array\\.$#"
count: 1
path: src/FormElement/BaseFormElement.php

-
message: "#^Trying to invoke mixed but it's not a callable\\.$#"
count: 1
Expand Down Expand Up @@ -475,21 +435,11 @@ parameters:
count: 1
path: src/FormElement/FieldsetElement.php

-
message: "#^Method ipl\\\\Html\\\\FormElement\\\\FieldsetElement\\:\\:populate\\(\\) has parameter \\$values with no value type specified in iterable type iterable\\.$#"
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 \\#1 \\$values of method ipl\\\\Html\\\\FormElement\\\\FieldsetElement\\:\\:populate\\(\\) 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 All @@ -500,11 +450,6 @@ parameters:
count: 1
path: src/FormElement/FieldsetElement.php

-
message: "#^Property ipl\\\\Html\\\\FormElement\\\\FieldsetElement\\:\\:\\$populatedValues type has no value type specified in iterable type array\\.$#"
count: 1
path: src/FormElement/FieldsetElement.php

-
message: "#^Cannot access offset 0 on mixed\\.$#"
count: 1
Expand Down Expand Up @@ -545,11 +490,6 @@ parameters:
count: 1
path: src/FormElement/InputElement.php

-
message: "#^Property ipl\\\\Html\\\\FormElement\\\\LocalDateTimeElement\\:\\:\\$defaultAttributes type has no value type specified in iterable type array\\.$#"
count: 1
path: src/FormElement/LocalDateTimeElement.php

-
message: "#^Method ipl\\\\Html\\\\FormElement\\\\PasswordElement\\:\\:registerAttributeCallbacks\\(\\) has no return type specified\\.$#"
count: 1
Expand Down Expand Up @@ -640,11 +580,6 @@ parameters:
count: 1
path: src/FormElement/SubmitButtonElement.php

-
message: "#^Property ipl\\\\Html\\\\FormElement\\\\SubmitButtonElement\\:\\:\\$defaultAttributes type has no value type specified in iterable type array\\.$#"
count: 1
path: src/FormElement/SubmitButtonElement.php

-
message: "#^Property ipl\\\\Html\\\\FormElement\\\\SubmitElement\\:\\:\\$buttonLabel has no type specified\\.$#"
count: 1
Expand Down
2 changes: 1 addition & 1 deletion src/BaseHtmlElement.php
Expand Up @@ -70,7 +70,7 @@ abstract class BaseHtmlElement extends HtmlDocument
/** @var bool|null Whether the element is void. If null, void check should use {@link $voidElements} */
protected $isVoid;

/** @var array You may want to set default attributes when extending this class */
/** @var array<string, mixed> You may want to set default attributes when extending this class */
protected $defaultAttributes;

/** @var string Tag of element. Set this property in order to provide the element's tag when extending this class */
Expand Down
4 changes: 2 additions & 2 deletions src/Contract/ValueCandidates.php
Expand Up @@ -7,14 +7,14 @@ interface ValueCandidates
/**
* Get value candidates of this element
*
* @return array
* @return array<int, mixed>
*/
public function getValueCandidates();

/**
* Set value candidates of this element
*
* @param array $values
* @param array<int, mixed> $values
*
* @return $this
*/
Expand Down
2 changes: 1 addition & 1 deletion src/FormElement/BaseFormElement.php
Expand Up @@ -42,7 +42,7 @@ abstract class BaseFormElement extends BaseHtmlElement implements FormElement, V
/** @var mixed Value of the element */
protected $value;

/** @var array Value candidates of the element */
/** @var array<int, mixed> Value candidates of the element */
protected $valueCandidates = [];

/**
Expand Down
13 changes: 13 additions & 0 deletions src/FormElement/FieldsetElement.php
Expand Up @@ -2,11 +2,14 @@

namespace ipl\Html\FormElement;

use InvalidArgumentException;
use ipl\Html\Contract\FormElement;
use ipl\Html\Contract\FormElementDecorator;
use ipl\Html\Contract\Wrappable;
use LogicException;

use function ipl\Stdlib\get_php_type;

class FieldsetElement extends BaseFormElement
{
use FormElements {
Expand Down Expand Up @@ -46,6 +49,16 @@ public function getValue($name = null, $default = null)

public function setValue($value)
{
if (! is_iterable($value)) {
throw new InvalidArgumentException(
sprintf(
'%s expects parameter $value to be an array|iterable, got %s instead',
__METHOD__,
get_php_type($value)
)
);
}

// We expect an array/iterable here,
// so call populate to loop through it and apply values to the child elements of the fieldset.
$this->populate($value);
Expand Down
4 changes: 2 additions & 2 deletions src/FormElement/FormElements.php
Expand Up @@ -32,7 +32,7 @@ trait FormElements
/** @var FormElement[] */
private $elements = [];

/** @var array */
/** @var array<string, array<int, mixed>> */
private $populatedValues = [];

/**
Expand Down Expand Up @@ -311,7 +311,7 @@ public function getValues()
/**
* Populate values of registered elements
*
* @param iterable $values Values as name-value pairs
* @param iterable<string, mixed> $values Values as name-value pairs
*
* @return $this
*/
Expand Down

0 comments on commit ad522bf

Please sign in to comment.