Skip to content

Commit 9944826

Browse files
committed
fix: failing phpstan checks
fix: function strval expects bool|float|int|resource|string|null, mixed given.
1 parent 8720dc6 commit 9944826

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

src/Html/HtmlBuilder.php

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ protected function attributeElement(string $key, mixed $value): mixed
119119
return 'class="'.implode(' ', $value).'"';
120120
}
121121

122-
if (! is_null($value)) {
122+
if (is_bool($value) || is_float($value) || is_int($value) || is_resource($value) || is_string($value)) {
123123
return $key.'="'.e(strval($value), false).'"';
124124
}
125125

@@ -459,8 +459,18 @@ protected function listingElement(mixed $key, string $type, mixed $value): HtmlS
459459
if (is_array($value)) {
460460
return $this->nestedListing($key, $type, $value);
461461
} else {
462-
return '<li>'.e(strval($value), false).'</li>';
462+
if (is_bool($value)
463+
|| is_float($value)
464+
|| is_int($value)
465+
|| is_resource($value)
466+
|| is_string($value)
467+
|| is_null($value)
468+
) {
469+
return '<li>'.e(strval($value), false).'</li>';
470+
}
463471
}
472+
473+
return '<li>'.$value.'</li>';
464474
}
465475

466476
/**
@@ -549,6 +559,18 @@ public function tag(string $tag, mixed $content, array $attributes = []): HtmlSt
549559
{
550560
$content = is_array($content) ? implode('', $content) : $content;
551561

552-
return $this->toHtmlString('<'.$tag.$this->attributes($attributes).'>'.$this->toHtmlString(strval($content)).'</'.$tag.'>');
562+
if (is_bool($content)
563+
|| is_float($content)
564+
|| is_int($content)
565+
|| is_resource($content)
566+
|| is_string($content)
567+
|| is_null($content)
568+
) {
569+
return $this->toHtmlString(
570+
'<'.$tag.$this->attributes($attributes).'>'.$this->toHtmlString(strval($content)).'</'.$tag.'>'
571+
);
572+
}
573+
574+
return $this->toHtmlString('<'.$tag.$this->attributes($attributes).'>'.$content.'</'.$tag.'>');
553575
}
554576
}

0 commit comments

Comments
 (0)