From 92f438b1465245e8da633bb7140f5b2cb212e809 Mon Sep 17 00:00:00 2001 From: IanDelMar <42134098+IanDelMar@users.noreply.github.com> Date: Fri, 24 Feb 2023 10:22:27 +0100 Subject: [PATCH] remove deprecated instanceof ConstantStringType See https://phpstan.org/blog/why-is-instanceof-type-wrong-and-getting-deprecated --- src/phpstan/GetThemeModReturnType.php | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/phpstan/GetThemeModReturnType.php b/src/phpstan/GetThemeModReturnType.php index 1278d1aa..886436aa 100644 --- a/src/phpstan/GetThemeModReturnType.php +++ b/src/phpstan/GetThemeModReturnType.php @@ -54,14 +54,20 @@ class GetThemeModReturnType implements DynamicFunctionReturnTypeExtension { $functionReflection->getVariants() )->getReturnType(); - if (!$argType instanceof ConstantStringType) { - return $defaultType; + if (count($argType->getConstantStrings()) === 0) { + return null; } - // Return the default value if it is not an Understrap specific theme mod. - if (!in_array($argType->getValue(), self::$themeMods, true)) { - return $defaultType; + $returnType = []; + foreach ($argType->getConstantStrings() as $constantString) { + if (in_array($constantString->getValue(), self::$themeMods, true)) { + $returnType[] = new StringType(); + } else { + $returnType[] = $defaultType; + } } + $returnType = TypeCombinator::union(...$returnType); + // Without second argument the default value is false, but can be filtered. $defaultType = new MixedType(); @@ -69,6 +75,6 @@ class GetThemeModReturnType implements DynamicFunctionReturnTypeExtension { $defaultType = $scope->getType($functionCall->getArgs()[1]->value); } - return TypeCombinator::union(new StringType(), $defaultType); + return TypeCombinator::union($returnType, $defaultType); } }