Skip to content

Commit b9f9920

Browse files
authored
Fix switcher extension (#20)
* PHPStan\Type\MixedType does not have `getValue()` method, get boolean value for `raw` instead. * Update tests expectation, stricter now.
1 parent e5aa348 commit b9f9920

4 files changed

Lines changed: 8 additions & 6 deletions

File tree

src/GuessTypeFromSwitcherAttributes.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,11 @@ private function guessType(Arg $args, Scope $scope) : Type
3434

3535
if ($argsType instanceof IntersectionType && $argsType->isIterable()) {
3636
// Let's look into each types to see if it contains 'raw' key.
37-
foreach($argsType->getTypes() as $type) {
38-
if ($type->hasOffsetValueType(new ConstantStringType('raw'))->yes()) {
39-
$isRaw = $type->getOffsetValueType(new ConstantStringType('raw'))->getValue() ? TrinaryLogic::createYes() : TrinaryLogic::createNo();
37+
$types = $argsType->getTypes();
38+
foreach($types as $type) {
39+
$rawKey = new ConstantStringType('raw');
40+
if ($type->hasOffsetValueType($rawKey)->yes()) {
41+
$isRaw = $type->getOffsetValueType($rawKey)->toBoolean()->isTrue() ? TrinaryLogic::createYes() : TrinaryLogic::createNo();
4042
}
4143
}
4244
}

tests/data/get_languages_list.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
assertType('array<int, mixed>', $model->get_languages_list($array));
3131

3232
// With array_merge() result passed as parameter.
33-
assertType('array<int, mixed>', $model->get_languages_list(array_merge($array, ['fields' => 'slug'])));
33+
assertType('array<int, string>', $model->get_languages_list(array_merge($array, ['fields' => 'slug'])));
3434

3535
// With 'fields' key set on top of variable containing unknown data.
3636
$array['fields'] = 'slug';

tests/data/pll_the_languages.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040

4141
// With unknown variable merged.
4242
$args = array_merge( [ 'raw' => 1 ], $options );
43-
assertType('array<string, mixed>|string', pll_the_languages($args));
43+
assertType('array<string, mixed>', pll_the_languages($args));
4444

4545
// With raw attribute set to true outside.
4646
$array['raw'] = 1;

tests/data/the_languages.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343

4444
// With unknown variable merged.
4545
$args = array_merge( $array, [ 'raw' => 1 ] );
46-
assertType('array<string, mixed>|string', $switcher->the_languages($link, $args));
46+
assertType('array<string, mixed>', $switcher->the_languages($link, $args));
4747

4848
// With raw attribute set to true outside.
4949
$array['raw'] = 1;

0 commit comments

Comments
 (0)