Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions src/Html.php
Original file line number Diff line number Diff line change
Expand Up @@ -1649,11 +1649,11 @@
/** @psalm-var array<array-key, scalar[]|string|Stringable|null> $value */
foreach ($value as $n => $v) {
if (!isset($v)) {
continue;

Check warning on line 1652 in src/Html.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.5-ubuntu-latest

Escaped Mutant for Mutator "Continue_": @@ @@ /** @psalm-var array<array-key, scalar[]|string|Stringable|null> $value */ foreach ($value as $n => $v) { if (!isset($v)) { - continue; + break; } $fullName = "$name-$n"; if (in_array($fullName, self::ATTRIBUTES_WITH_CONCATENATED_VALUES, true)) {
}
$fullName = "$name-$n";
if (in_array($fullName, self::ATTRIBUTES_WITH_CONCATENATED_VALUES, true)) {
$html .= self::renderAttribute(

Check warning on line 1656 in src/Html.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.5-ubuntu-latest

Escaped Mutant for Mutator "Assignment": @@ @@ } $fullName = "$name-$n"; if (in_array($fullName, self::ATTRIBUTES_WITH_CONCATENATED_VALUES, true)) { - $html .= self::renderAttribute( + $html = self::renderAttribute( $fullName, self::encodeAttribute( is_array($v) ? implode(' ', $v) : $v,
$fullName,
self::encodeAttribute(
is_array($v) ? implode(' ', $v) : $v,
Expand Down Expand Up @@ -1707,9 +1707,9 @@
* @param array $attributes The attributes to be modified. All string values in the array must be valid UTF-8
* strings.
* @param BackedEnum|BackedEnum[]|null[]|string|string[]|null $class The CSS class(es) to be added. Null values will
Comment thread
Mister-42 marked this conversation as resolved.
Outdated
* be ignored.
* be ignored. When passing an array, use a boolean value to conditionally include/exclude a class by its key.
Comment thread
Mister-42 marked this conversation as resolved.
Outdated
*
* @psalm-param BackedEnum|string|array<array-key,BackedEnum|string|null>|null $class
* @psalm-param BackedEnum|string|array<array-key,BackedEnum|bool|string|null>|null $class
*/
public static function addCssClass(array &$attributes, BackedEnum|array|string|null $class): void
{
Expand All @@ -1727,18 +1727,17 @@
if (is_array($class)) {
$filteredClass = [];
foreach ($class as $key => $value) {
if ($value instanceof BackedEnum) {
$value = is_string($value->value) ? $value->value : null;
}

/** @psalm-suppress DocblockTypeContradiction */
if (is_bool($value)) {
Comment thread
Mister-42 marked this conversation as resolved.
Comment thread
Mister-42 marked this conversation as resolved.
if ($value && is_string($key)) {
$filteredClass[] = $key;
Comment thread
Mister-42 marked this conversation as resolved.
}
continue;

Check warning on line 1734 in src/Html.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.5-ubuntu-latest

Escaped Mutant for Mutator "Continue_": @@ @@ if ($value && is_string($key)) { $filteredClass[] = $key; } - continue; + break; } if ($value instanceof BackedEnum) {
}

if ($value instanceof BackedEnum) {
$value = is_string($value->value) ? $value->value : null;
}

if ($value !== null) {
$filteredClass[$key] = $value;
}
Expand Down
19 changes: 4 additions & 15 deletions tests/HtmlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1054,7 +1054,10 @@ public static function dataAddCssClass(): array
21 => [['class' => ['btn', 'btn-active']], [], ['btn', 'btn-active' => true]],
22 => [['class' => ['btn']], [], ['btn', 'btn-active' => false]],
23 => [['class' => ['btn', 'btn-active']], ['class' => 'btn'], ['btn-active' => true]],
24 => [['class' => 'btn'], ['class' => 'btn'], ['btn-active' => false]],
24 => [['class' => 'btn'], ['class' => 'btn'], ['btn-active' => false]],
25 => [['class' => ['btn', 'btn-active']], ['class' => 'btn'], ['btn-active' => true, 'hidden' => false]],
26 => [['class' => ['btn']], ['class' => 'btn'], ['btn' => true]],
27 => [['class' => ['persistent' => 'widget', 'btn', 'btn-active']], ['class' => ['persistent' => 'widget']], ['btn', 'btn-active' => true]],
Comment thread
Mister-42 marked this conversation as resolved.
Outdated
];
}

Expand Down Expand Up @@ -1097,20 +1100,6 @@ public function testMergeCssClass(): void
$this->assertSame(['persistent' => 'test1', 'additional' => 'test2'], $attributes['class']);
}

public function testAddCssClassConditional(): void
{
$attributes = ['class' => 'btn'];
Html::addCssClass($attributes, ['btn-active' => true, 'hidden' => false]);
$this->assertSame(['class' => ['btn', 'btn-active']], $attributes);

Html::addCssClass($attributes, ['btn' => true]);
$this->assertSame(['class' => ['btn', 'btn-active']], $attributes);

$attributes = ['class' => ['persistent' => 'widget']];
Html::addCssClass($attributes, ['btn', 'btn-active' => true]);
$this->assertSame(['class' => ['persistent' => 'widget', 'btn', 'btn-active']], $attributes);
}

public function testAddCssClassArrayToString(): void
{
$attributes = ['class' => 'test'];
Expand Down
Loading