Skip to content

Commit

Permalink
Fix issue psalm.
Browse files Browse the repository at this point in the history
  • Loading branch information
terabytesoftw committed Jun 10, 2021
1 parent cbc18f0 commit 3a13c7d
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 7 deletions.
4 changes: 4 additions & 0 deletions psalm.xml
Expand Up @@ -12,4 +12,8 @@
<directory name="vendor" />
</ignoreFiles>
</projectFiles>

<issueHandlers>
<PropertyNotSetInConstructor errorLevel="suppress" />
</issueHandlers>
</psalm>
3 changes: 2 additions & 1 deletion src/Hint.php
Expand Up @@ -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';

Expand Down
10 changes: 6 additions & 4 deletions src/Input.php
Expand Up @@ -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();
}
Expand Down Expand Up @@ -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);
}
}
}
6 changes: 5 additions & 1 deletion src/Label.php
Expand Up @@ -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';
Expand All @@ -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 === ''
Expand Down
2 changes: 1 addition & 1 deletion src/Widget.php
Expand Up @@ -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 = '';
Expand Down

0 comments on commit 3a13c7d

Please sign in to comment.