Skip to content

Commit 96cc97b

Browse files
committed
style(class-variance): fixes from phpstan
1 parent 34cac61 commit 96cc97b

5 files changed

Lines changed: 27 additions & 19 deletions

File tree

packages/class-variance/src/ClassNames.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,11 @@ public static function of(string|array|bool $input, string $slot = ''): self
5454

5555
$items = [];
5656
foreach ($input as $entry) {
57-
if (is_string($entry)) {
58-
array_push($items, ...self::tokenise($entry));
57+
if (! is_string($entry)) {
58+
continue;
5959
}
60+
61+
array_push($items, ...self::tokenise($entry));
6062
}
6163

6264
return new self($items);

packages/class-variance/src/ClassVariance.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ interface ClassVariance
1414
/**
1515
* Resolve the class string for the given props and slot.
1616
*
17-
* @param array<string, string|bool> $props Active variant prop values.
17+
* @param array<string, string|bool|array<string, string|bool>> $props Active variant prop values.
1818
* @param string $slot Named slot to resolve (e.g. 'base', 'label'). When omitted
1919
* and the base defines a single slot, that slot is inferred automatically.
2020
*/

packages/class-variance/src/GenericClassVariance.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313
use ResolvesVariants;
1414

1515
/**
16-
* @param array<string, string|array<string, mixed>>|string $base
16+
* @param array<string, string|list<string>|array<string, string|list<string>>>|list<string>|string $base
1717
* Base classes. A plain string or indexed array targets the implicit 'base' slot.
1818
* An associative array is a slot-keyed map: ['base' => '...', 'label' => '...'].
19-
* @param array<string, array<string, string|array<string, mixed>>> $variants
19+
* @param array<string, array<string, string|list<string>|array<string, string|list<string>>>> $variants
2020
* Variant dimensions. Keys are prop names; values map prop values to classes.
2121
* Per-value classes may be a plain string (implicit 'base') or a slot-keyed array.
2222
* @param array<int, array<string, mixed>> $compoundVariants

packages/class-variance/src/ResolvesVariants.php

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
*/
2727
trait ResolvesVariants
2828
{
29-
/** @param array<string, string|bool> $props */
29+
/** @param array<string, string|bool|array<string, string|bool>> $props */
3030
public function __invoke(array $props = [], string $slot = ''): string
3131
{
3232
$props = $this->applyDefaultVariants($props);
@@ -41,8 +41,8 @@ public function __invoke(array $props = [], string $slot = ''): string
4141
}
4242

4343
/**
44-
* @param array<string, string|bool> $props
45-
* @return array<string, string|bool>
44+
* @param array<string, string|bool|array<string, string|bool>> $props
45+
* @return array<string, string|bool|array<string, string|bool>>
4646
*/
4747
private function applyDefaultVariants(array $props): array
4848
{
@@ -66,9 +66,7 @@ private function resolveSlot(string $slot): string
6666
if (is_array($this->base) && ! array_is_list($this->base)) {
6767
if (count($this->base) === 1) {
6868
return (string) array_key_first($this->base);
69-
}
70-
71-
if (count($this->base) > 1) {
69+
} else {
7270
throw new InvalidArgumentException(
7371
'Multiple slots defined but no slot specified. Available slots: ' . implode(', ', array_keys($this->base)),
7472
);
@@ -106,7 +104,7 @@ private function resolvePassthrough(array $props, string $slot): ClassNames
106104
}
107105

108106
/**
109-
* @param array<string, string|bool> $props
107+
* @param array<string, string|bool|array<string, string|bool>> $props
110108
*/
111109
private function resolveVariants(array $props, string $slot): ClassNames
112110
{
@@ -116,7 +114,15 @@ private function resolveVariants(array $props, string $slot): ClassNames
116114
$variants = $this->variants;
117115

118116
foreach ($props as $key => $value) {
119-
$lookupKey = is_bool($value) ? ($value ? 'true' : 'false') : $value;
117+
if (is_array($value)) {
118+
continue;
119+
}
120+
121+
$lookupKey = match (true) {
122+
$value === true => 'true',
123+
$value === false => 'false',
124+
default => $value,
125+
};
120126
$entry = $variants[$key][$lookupKey] ?? null;
121127

122128
if ($entry === null) {
@@ -130,7 +136,7 @@ private function resolveVariants(array $props, string $slot): ClassNames
130136
}
131137

132138
/**
133-
* @param array<string, string|bool> $props
139+
* @param array<string, string|bool|array<string, string|bool>> $props
134140
*/
135141
private function resolveCompoundVariants(array $props, string $slot): ClassNames
136142
{
@@ -153,7 +159,7 @@ private function resolveCompoundVariants(array $props, string $slot): ClassNames
153159
}
154160

155161
/**
156-
* @param array<string, string|bool> $props
162+
* @param array<string, string|bool|array<string, string|bool>> $props
157163
* @param array<string, mixed> $compound
158164
*/
159165
private function compoundMatches(array $props, array $compound): bool

packages/class-variance/src/functions.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@
1616
* Pass a ClassGroupMap via GenericClassVarianceConfig to declare explicit
1717
* conflict groups for classes that share no common prefix.
1818
*
19-
* @param array<string, array<string, string|array<string, mixed>>>|string $base
19+
* @param array<string, string|list<string>|array<string, string|list<string>>>|list<string>|string $base
2020
* Base classes. A plain string or indexed array implicitly targets the 'base'
2121
* slot. An associative array is a slot-keyed map.
22-
* @param array<string, array<string, string|array<string, mixed>>> $variants
22+
* @param array<string, array<string, string|list<string>|array<string, string|list<string>>>> $variants
2323
* @param array<int, array<string, mixed>> $compoundVariants
2424
* @param array<string, string|bool> $defaultVariants
2525
*/
@@ -45,10 +45,10 @@ function cv(
4545
* Pass a TailwindClassVarianceConfig to extend/override groups for custom
4646
* plugins or a non-standard Tailwind prefix / separator.
4747
*
48-
* @param array<string, array<string, string|array<string, mixed>>>|string $base
48+
* @param array<string, string|list<string>|array<string, string|list<string>>>|list<string>|string $base
4949
* Base classes. A plain string or indexed array implicitly targets the 'base'
5050
* slot. An associative array is a slot-keyed map.
51-
* @param array<string, array<string, string|array<string, mixed>>> $variants
51+
* @param array<string, array<string, string|list<string>|array<string, string|list<string>>>> $variants
5252
* @param array<int, array<string, mixed>> $compoundVariants
5353
* @param array<string, string|bool> $defaultVariants
5454
*/

0 commit comments

Comments
 (0)