From 3a13c7d11382aa96cadc1dbd3453999bca4724dd Mon Sep 17 00:00:00 2001 From: Wilmer Date: Thu, 10 Jun 2021 14:59:18 -0400 Subject: [PATCH] Fix issue psalm. --- psalm.xml | 4 ++++ src/Hint.php | 3 ++- src/Input.php | 10 ++++++---- src/Label.php | 6 +++++- src/Widget.php | 2 +- 5 files changed, 18 insertions(+), 7 deletions(-) diff --git a/psalm.xml b/psalm.xml index 3240886..f36cc18 100644 --- a/psalm.xml +++ b/psalm.xml @@ -12,4 +12,8 @@ + + + + diff --git a/src/Hint.php b/src/Hint.php index 1bc0ef1..b7a1ce4 100644 --- a/src/Hint.php +++ b/src/Hint.php @@ -19,7 +19,8 @@ protected function run(): string { $new = clone $this; - $hint = $new->modelInterface->getAttributeHint($new->attribute) ?? $new->hint; + $hint = $new->modelInterface->getAttributeHint($new->attribute) !== '' + ? $new->modelInterface->getAttributeHint($new->attribute) : $new->hint; $new->attributes['id'] = $new->getId($new->modelInterface->getFormName(), $new->attribute) . '-hint'; diff --git a/src/Input.php b/src/Input.php index b962fcc..6b72a6c 100644 --- a/src/Input.php +++ b/src/Input.php @@ -90,7 +90,11 @@ protected function run(): string $new->setPlaceholder(); } - foreach ($new->modelInterface->getRules()[$new->attribute] as $rule) { + /** @var array */ + $rules = $new->modelInterface->getRules(); + + /** @var object $rule */ + foreach ($rules[$new->attribute] as $rule) { if ($rule instanceof Required) { $new = $new->required(); } @@ -258,9 +262,7 @@ private function setPlaceholder(): void ) { $attributeName = $this->getAttributeName($this->attribute); - if ($this->modelInterface !== null) { - $this->attributes['placeholder'] = $this->modelInterface->getAttributeLabel($attributeName); - } + $this->attributes['placeholder'] = $this->modelInterface->getAttributeLabel($attributeName); } } } diff --git a/src/Label.php b/src/Label.php index 27b7e4d..f3b46c0 100644 --- a/src/Label.php +++ b/src/Label.php @@ -8,6 +8,9 @@ use Yiisoft\Form\FormModelInterface; use Yiisoft\Html\Html; +/** + * @psalm-suppress MissingConstructor + */ final class Label extends Widget { private string $charset = 'UTF-8'; @@ -22,10 +25,11 @@ protected function run(): string { $new = clone $this; + /** @var string */ $for = ArrayHelper::remove( $new->attributes, 'for', - $new->getId($new->modelInterface->getFormName(), $new->attribute, $new->charset) + $new->getId($new->modelInterface->getFormName(), $new->attribute) ); $label = $new->label === '' diff --git a/src/Widget.php b/src/Widget.php index 362ea4c..eba9ef2 100644 --- a/src/Widget.php +++ b/src/Widget.php @@ -14,7 +14,7 @@ abstract class Widget extends AbstractWidget implements NoEncodeStringableInterf { protected string $attribute = ''; protected array $attributes = []; - protected ?ModelInterface $modelInterface = null; + protected ModelInterface $modelInterface; private bool $autoGenerate = true; private string $charset = 'UTF-8'; private string $id = '';