Skip to content

Commit 660dc7e

Browse files
authored
Fix switcher extension regression (#21)
* Use given trinary value directly for raw attribute guessed type. * Better tests.
1 parent b9f9920 commit 660dc7e

3 files changed

Lines changed: 23 additions & 3 deletions

File tree

src/GuessTypeFromSwitcherAttributes.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ private function guessType(Arg $args, Scope $scope) : Type
3838
foreach($types as $type) {
3939
$rawKey = new ConstantStringType('raw');
4040
if ($type->hasOffsetValueType($rawKey)->yes()) {
41-
$isRaw = $type->getOffsetValueType($rawKey)->toBoolean()->isTrue() ? TrinaryLogic::createYes() : TrinaryLogic::createNo();
41+
$isRaw = $type->getOffsetValueType($rawKey)->toBoolean()->isTrue();
4242
}
4343
}
4444
}

tests/data/pll_the_languages.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,12 @@
4040

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

4545
// With raw attribute set to true outside.
4646
$array['raw'] = 1;
4747
assertType('array<string, mixed>', pll_the_languages($array));
48+
49+
// With raw attribute set to false outside.
50+
$array['raw'] = false;
51+
assertType('string', pll_the_languages($array));

tests/data/the_languages.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,26 @@
4141
// Unknown attributes.
4242
assertType('array<string, mixed>|string', $switcher->the_languages($link, $array));
4343

44-
// With unknown variable merged.
44+
// With raw attribute set to true and merged into an array.
4545
$args = array_merge( $array, [ 'raw' => 1 ] );
4646
assertType('array<string, mixed>', $switcher->the_languages($link, $args));
4747

48+
// With raw attribute set to true and merged with an array.
49+
$args = array_merge( [ 'raw' => true ], $array );
50+
assertType('array<string, mixed>|string', $switcher->the_languages($link, $args));
51+
4852
// With raw attribute set to true outside.
4953
$array['raw'] = 1;
5054
assertType('array<string, mixed>', $switcher->the_languages($link, $array));
55+
56+
// With raw attribute set to false outside.
57+
$array['raw'] = false;
58+
assertType('string', $switcher->the_languages($link, $array));
59+
60+
// With raw attribute set to false and merged in an array.
61+
$args = array_merge( $array, [ 'raw' => false ] );
62+
assertType('string', $switcher->the_languages($link, $array));
63+
64+
// With raw attribute set to false and merged with an array.
65+
$args = array_merge( [ 'raw' => false ], $array );
66+
assertType('string', $switcher->the_languages($link, $array));

0 commit comments

Comments
 (0)