diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 42eeaee1..0f0cf438 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -1,5 +1,5 @@ - + @@ -552,9 +552,6 @@ - - getValidator - @@ -601,6 +598,14 @@ + + [ + 'a' => 'A', + 'b' => 'B', + ], + ]]]> + @@ -689,6 +694,12 @@ + + true, + 'options' => $valueOptions, + ]]]> + @@ -1101,9 +1112,6 @@ $element - - getAttribute($attribute)]]> - @@ -1120,28 +1128,10 @@ setView - - - getAttribute($attribute)]]> - - - - - getAttribute($attribute)]]> - - - - - getAttribute($attribute)]]> - - new FormDateTimeHelper() - - getAttribute($attribute)]]> - @@ -1154,104 +1144,14 @@ getHash - - - getAttribute($attribute)]]> - - - - - getAttribute($attribute)]]> - - - - - getAttribute($attribute)]]> - - - - - getAttribute($attribute)]]> - - - - - getAttribute($attribute)]]> - - $element - - - getAttribute($attribute)]]> - - - - - getAttribute($attribute)]]> - - - - - getAttribute($attribute)]]> - - - - - getAttribute($attribute)]]> - - - - - getAttribute($attribute)]]> - - $escapeHelper($label) - - - getAttribute($attribute)]]> - - - - - getAttribute($attribute)]]> - - - - - getAttribute($attribute)]]> - - - - - getAttribute($attribute)]]> - - - - - getAttribute($attribute)]]> - - - - - getAttribute($attribute)]]> - - - - - getAttribute($attribute)]]> - - - - - getAttribute($attribute)]]> - - diff --git a/src/Element.php b/src/Element.php index e24d66d5..9c3fc585 100644 --- a/src/Element.php +++ b/src/Element.php @@ -9,6 +9,7 @@ use Traversable; use function array_key_exists; +use function assert; use function is_string; class Element implements @@ -17,19 +18,19 @@ class Element implements InitializableInterface, LabelAwareInterface { - /** @var array */ + /** @var array */ protected $attributes = []; /** @var null|string */ protected $label; - /** @var array */ + /** @var array */ protected $labelAttributes = []; /** * Label specific options * - * @var array + * @var array */ protected $labelOptions = []; @@ -87,7 +88,10 @@ public function setName(string $name) */ public function getName(): ?string { - return $this->getAttribute('name'); + $name = $this->getAttribute('name'); + assert(is_string($name) || $name === null); + + return $name; } /** @@ -158,12 +162,7 @@ public function setOption(string $key, $value) return $this; } - /** - * Set a single element attribute - * - * @param mixed $value - * @return $this - */ + /** @inheritDoc */ public function setAttribute(string $key, $value) { // Do not include the value in the list of attributes @@ -175,11 +174,7 @@ public function setAttribute(string $key, $value) return $this; } - /** - * Retrieve a single element attribute - * - * @return mixed|null - */ + /** @inheritDoc */ public function getAttribute(string $key) { if (! isset($this->attributes[$key])) { @@ -209,11 +204,7 @@ public function hasAttribute(string $key): bool } /** - * Set many attributes at once - * - * Implementation will decide if this will overwrite or merge. - * - * @return $this + * @inheritDoc * @throws Exception\InvalidArgumentException */ public function setAttributes(iterable $arrayOrTraversable) @@ -224,9 +215,7 @@ public function setAttributes(iterable $arrayOrTraversable) return $this; } - /** - * Retrieve all attributes at once - */ + /** @inheritDoc */ public function getAttributes(): array { return $this->attributes; @@ -235,7 +224,7 @@ public function getAttributes(): array /** * Remove many attributes at once * - * @param array $keys + * @param list $keys * @return $this */ public function removeAttributes(array $keys) @@ -304,23 +293,14 @@ public function getLabel(): ?string return $this->label; } - /** - * Set the attributes to use with the label - * - * @param array $labelAttributes - * @return $this - */ + /** @inheritDoc */ public function setLabelAttributes(array $labelAttributes) { $this->labelAttributes = $labelAttributes; return $this; } - /** - * Get the attributes to use with the label - * - * @return array - */ + /** @inheritDoc */ public function getLabelAttributes(): array { return $this->labelAttributes; diff --git a/src/Element/AbstractDateTime.php b/src/Element/AbstractDateTime.php index b8339480..ea959e00 100644 --- a/src/Element/AbstractDateTime.php +++ b/src/Element/AbstractDateTime.php @@ -106,7 +106,7 @@ protected function getValidators(): array if ( isset($this->attributes['min']) - && $this->valueIsValidDateTimeFormat($this->attributes['min']) + && $this->valueIsValidDateTimeFormat((string) $this->attributes['min']) ) { $validators[] = new GreaterThanValidator([ 'min' => $this->attributes['min'], @@ -114,19 +114,19 @@ protected function getValidators(): array ]); } elseif ( isset($this->attributes['min']) - && ! $this->valueIsValidDateTimeFormat($this->attributes['min']) + && ! $this->valueIsValidDateTimeFormat((string) $this->attributes['min']) ) { throw new InvalidArgumentException(sprintf( '%1$s expects "min" to conform to %2$s; received "%3$s"', __METHOD__, $this->format, - $this->attributes['min'] + (string) $this->attributes['min'] )); } if ( isset($this->attributes['max']) - && $this->valueIsValidDateTimeFormat($this->attributes['max']) + && $this->valueIsValidDateTimeFormat((string) $this->attributes['max']) ) { $validators[] = new LessThanValidator([ 'max' => $this->attributes['max'], @@ -134,13 +134,13 @@ protected function getValidators(): array ]); } elseif ( isset($this->attributes['max']) - && ! $this->valueIsValidDateTimeFormat($this->attributes['max']) + && ! $this->valueIsValidDateTimeFormat((string) $this->attributes['max']) ) { throw new InvalidArgumentException(sprintf( '%1$s expects "max" to conform to %2$s; received "%3$s"', __METHOD__, $this->format, - $this->attributes['max'] + (string) $this->attributes['max'] )); } if ( diff --git a/src/Element/Button.php b/src/Element/Button.php index 54c187c5..5a9ba82f 100644 --- a/src/Element/Button.php +++ b/src/Element/Button.php @@ -8,11 +8,7 @@ class Button extends Element { - /** - * Seed attributes - * - * @var array - */ + /** @var array */ protected $attributes = [ 'type' => 'button', ]; diff --git a/src/Element/Checkbox.php b/src/Element/Checkbox.php index e2c5b13c..e9d58583 100644 --- a/src/Element/Checkbox.php +++ b/src/Element/Checkbox.php @@ -11,11 +11,7 @@ class Checkbox extends Element implements InputProviderInterface { - /** - * Seed attributes - * - * @var array - */ + /** @var array */ protected $attributes = [ 'type' => 'checkbox', ]; diff --git a/src/Element/Color.php b/src/Element/Color.php index c91f3776..867ad059 100644 --- a/src/Element/Color.php +++ b/src/Element/Color.php @@ -13,11 +13,7 @@ class Color extends Element implements InputProviderInterface { - /** - * Seed attributes - * - * @var array - */ + /** @var array */ protected $attributes = [ 'type' => 'color', ]; diff --git a/src/Element/Csrf.php b/src/Element/Csrf.php index f50667b8..b01fbd31 100644 --- a/src/Element/Csrf.php +++ b/src/Element/Csrf.php @@ -16,11 +16,7 @@ class Csrf extends Element implements InputProviderInterface, ElementPrepareAwareInterface { - /** - * Seed attributes - * - * @var array - */ + /** @var array */ protected $attributes = [ 'type' => 'hidden', ]; @@ -103,6 +99,8 @@ public function getValue(): string * Override: get attributes * * Seeds 'value' attribute with validator hash + * + * @inheritDoc */ public function getAttributes(): array { diff --git a/src/Element/Date.php b/src/Element/Date.php index 337ddbf0..2a5614a2 100644 --- a/src/Element/Date.php +++ b/src/Element/Date.php @@ -14,11 +14,7 @@ class Date extends DateTimeElement { - /** - * Seed attributes - * - * @var array - */ + /** @var array */ protected $attributes = [ 'type' => 'date', ]; diff --git a/src/Element/DateSelect.php b/src/Element/DateSelect.php index 5712b2e9..8d3d3ca6 100644 --- a/src/Element/DateSelect.php +++ b/src/Element/DateSelect.php @@ -64,7 +64,7 @@ public function getDayElement(): Select /** * Get both the year and month elements * - * @return array + * @return list */ public function getElements(): array { return array_merge(parent::getElements(), [ @@ -124,6 +125,7 @@ public function getElements(): array /** * Set the hour attributes * + * @param array $hourAttributes * @return $this */ public function setHourAttributes(array $hourAttributes) @@ -135,7 +137,7 @@ public function setHourAttributes(array $hourAttributes) /** * Get the hour attributes * - * @return array + * @return array */ public function getHourAttributes(): array { @@ -145,6 +147,7 @@ public function getHourAttributes(): array /** * Set the minute attributes * + * @param array $minuteAttributes * @return $this */ public function setMinuteAttributes(array $minuteAttributes) @@ -156,7 +159,7 @@ public function setMinuteAttributes(array $minuteAttributes) /** * Get the minute attributes * - * @return array + * @return array */ public function getMinuteAttributes(): array { @@ -166,6 +169,7 @@ public function getMinuteAttributes(): array /** * Set the second attributes * + * @param array $secondAttributes * @return $this */ public function setSecondAttributes(array $secondAttributes) @@ -177,7 +181,7 @@ public function setSecondAttributes(array $secondAttributes) /** * Get the second attributes * - * @return array + * @return array */ public function getSecondAttributes(): array { diff --git a/src/Element/Email.php b/src/Element/Email.php index 8ad8f83b..bd578319 100644 --- a/src/Element/Email.php +++ b/src/Element/Email.php @@ -13,11 +13,7 @@ class Email extends Element implements InputProviderInterface { - /** - * Seed attributes - * - * @var array - */ + /** @var array */ protected $attributes = [ 'type' => 'email', ]; diff --git a/src/Element/File.php b/src/Element/File.php index 6f4b794e..65d96c05 100644 --- a/src/Element/File.php +++ b/src/Element/File.php @@ -12,11 +12,7 @@ class File extends Element implements InputProviderInterface, ElementPrepareAwareInterface { - /** - * Seed attributes - * - * @var array - */ + /** @var array */ protected $attributes = [ 'type' => 'file', ]; diff --git a/src/Element/Hidden.php b/src/Element/Hidden.php index 10160fdb..c9ec1e08 100644 --- a/src/Element/Hidden.php +++ b/src/Element/Hidden.php @@ -8,11 +8,7 @@ class Hidden extends Element { - /** - * Seed attributes - * - * @var array - */ + /** @var array */ protected $attributes = [ 'type' => 'hidden', ]; diff --git a/src/Element/Image.php b/src/Element/Image.php index 79792828..b754962b 100644 --- a/src/Element/Image.php +++ b/src/Element/Image.php @@ -8,11 +8,7 @@ class Image extends Element { - /** - * Seed attributes - * - * @var array - */ + /** @var array */ protected $attributes = [ 'type' => 'image', ]; diff --git a/src/Element/Month.php b/src/Element/Month.php index a38d03f3..463e2fa4 100644 --- a/src/Element/Month.php +++ b/src/Element/Month.php @@ -18,11 +18,7 @@ class Month extends AbstractDateTime */ protected $format = '!Y-m'; - /** - * Seed attributes - * - * @var array - */ + /** @var array */ protected $attributes = [ 'type' => 'month', ]; diff --git a/src/Element/MonthSelect.php b/src/Element/MonthSelect.php index 46027f94..4e66cb45 100644 --- a/src/Element/MonthSelect.php +++ b/src/Element/MonthSelect.php @@ -142,7 +142,7 @@ public function getYearElement(): Select /** * Get both the year and month elements * - * @return array + * @return list