Skip to content

Commit dc199bb

Browse files
authored
Fix #68: Fix TagContentTrait::content() and TagContentTrait::addContent() when used with named parameters
1 parent 7658a2d commit dc199bb

50 files changed

Lines changed: 43 additions & 20 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CHANGELOG.md

Lines changed: 2 additions & 2 deletions

composer.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@
2020
"yiisoft/json": "^1.0"
2121
},
2222
"require-dev": {
23-
"maglnet/composer-require-checker": "^3.1",
23+
"maglnet/composer-require-checker": "^3.2",
2424
"phpunit/phpunit": "^9.5",
2525
"roave/infection-static-analysis-plugin": "^1.7",
2626
"spatie/phpunit-watcher": "^1.23",
27-
"vimeo/psalm": "^4.6"
27+
"vimeo/psalm": "^4.7"
2828
},
2929
"autoload": {
3030
"psr-4": {
@@ -33,7 +33,8 @@
3333
},
3434
"autoload-dev": {
3535
"psr-4": {
36-
"Yiisoft\\Html\\Tests\\": "tests"
36+
"Yiisoft\\Html\\Tests\\": "tests/common",
37+
"Yiisoft\\Html\\Tests\\Php8\\": "tests/php8"
3738
}
3839
},
3940
"config": {

phpunit.xml.dist

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515

1616
<testsuites>
1717
<testsuite name="Yii HTML tests">
18-
<directory>./tests/</directory>
18+
<directory>./tests/common</directory>
19+
<directory phpVersion="8" phpVersionOperator=">=">./tests/php8</directory>
1920
</testsuite>
2021
</testsuites>
2122

src/Html.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1065,7 +1065,7 @@ public static function addCssStyle(array &$options, $style, bool $overwrite = tr
10651065
$oldStyle = is_array($options['style']) ? $options['style'] : self::cssStyleToArray($options['style']);
10661066
$newStyle = is_array($style) ? $style : self::cssStyleToArray($style);
10671067
if (!$overwrite) {
1068-
foreach ($newStyle as $property => $value) {
1068+
foreach ($newStyle as $property => $_value) {
10691069
if (isset($oldStyle[$property])) {
10701070
unset($newStyle[$property]);
10711071
}

src/Tag/Base/TagContentTrait.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ trait TagContentTrait
1717
private bool $doubleEncode = true;
1818

1919
/**
20-
* @var string[]|Stringable[]
20+
* @psalm-var list<string|Stringable>
2121
*/
2222
private array $content = [];
2323

@@ -59,7 +59,7 @@ final public function doubleEncode(bool $doubleEncode): self
5959
final public function content(...$content): self
6060
{
6161
$new = clone $this;
62-
$new->content = $content;
62+
$new->content = array_values($content);
6363
return $new;
6464
}
6565

@@ -71,7 +71,7 @@ final public function content(...$content): self
7171
final public function addContent(...$content): self
7272
{
7373
$new = clone $this;
74-
$new->content = [...$new->content, ...$content];
74+
$new->content = array_merge($new->content, array_values($content));
7575
return $new;
7676
}
7777

src/Tag/Select.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,17 @@ public function name(?string $name): self
4444
}
4545

4646
/**
47-
* @psalm-param \Stringable|scalar|null ...$value One or more string values.
47+
* @psalm-param \Stringable|scalar ...$value One or more string values.
4848
*/
4949
public function value(...$value): self
5050
{
5151
$new = clone $this;
52-
$new->values = array_map('\strval', $value);
52+
$new->values = array_map('\strval', array_values($value));
5353
return $new;
5454
}
5555

5656
/**
57-
* @psalm-param iterable<array-key, \Stringable|scalar|null> $values A set of values.
57+
* @psalm-param iterable<int, \Stringable|scalar> $values A set of values.
5858
*/
5959
public function values($values): self
6060
{
@@ -63,7 +63,7 @@ public function values($values): self
6363
throw new InvalidArgumentException('$values should be iterable.');
6464
}
6565

66-
/** @psalm-var iterable<array-key, \Stringable|scalar|null> $values */
66+
/** @psalm-var iterable<int, \Stringable|scalar> $values */
6767
$values = is_array($values) ? $values : iterator_to_array($values);
6868

6969
return $this->value(...$values);
@@ -221,8 +221,6 @@ protected function generateContent(): string
221221
array_unshift($items, $this->prompt);
222222
}
223223

224-
/** @var Optgroup[]|Option[] $items */
225-
226224
$items = array_map(function ($item) {
227225
if ($item instanceof Option) {
228226
return $item->selected(in_array($item->getValue(), $this->values, true));

src/Widget/CheckboxList/CheckboxList.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,17 +105,17 @@ public function items(array $items, bool $encodeLabels = true): self
105105
}
106106

107107
/**
108-
* @param bool|float|int|string|\Stringable|null ...$value
108+
* @param scalar|\Stringable ...$value
109109
*/
110110
public function value(...$value): self
111111
{
112112
$new = clone $this;
113-
$new->values = array_map('\strval', $value);
113+
$new->values = array_map('\strval', array_values($value));
114114
return $new;
115115
}
116116

117117
/**
118-
* @psalm-param iterable<array-key, \Stringable|scalar|null> $values
118+
* @psalm-param iterable<int, \Stringable|scalar> $values
119119
*/
120120
public function values($values): self
121121
{
@@ -124,7 +124,7 @@ public function values($values): self
124124
throw new InvalidArgumentException('$values should be iterable.');
125125
}
126126

127-
/** @psalm-var iterable<array-key, \Stringable|scalar|null> $values */
127+
/** @psalm-var iterable<int, \Stringable|scalar> $values */
128128
$values = is_array($values) ? $values : iterator_to_array($values);
129129

130130
return $this->value(...$values);

0 commit comments

Comments
 (0)