Skip to content

Commit 4db4f3c

Browse files
committed
Fix build
1 parent b1e6ae1 commit 4db4f3c

6 files changed

+49
-41
lines changed

src/Rule/Nette/RegularExpressionPatternRule.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
use PHPStan\Analyser\Scope;
1010
use PHPStan\Rules\Rule;
1111
use PHPStan\Rules\RuleErrorBuilder;
12-
use PHPStan\Type\Constant\ConstantStringType;
1312
use function in_array;
1413
use function sprintf;
1514
use function strtolower;
@@ -84,11 +83,9 @@ private function extractPatterns(StaticCall $staticCall, Scope $scope): array
8483
}
8584

8685
foreach ($constantArrayType->getKeyTypes() as $arrayKeyType) {
87-
if (!$arrayKeyType instanceof ConstantStringType) {
88-
continue;
86+
foreach ($arrayKeyType->getConstantStrings() as $constantString) {
87+
$patternStrings[] = $constantString->getValue();
8988
}
90-
91-
$patternStrings[] = $arrayKeyType->getValue();
9289
}
9390
}
9491

src/Type/Nette/ComponentModelArrayAccessDynamicReturnTypeExtension.php

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
use PHPStan\Analyser\Scope;
77
use PHPStan\Reflection\MethodReflection;
88
use PHPStan\Reflection\ParametersAcceptorSelector;
9-
use PHPStan\Type\Constant\ConstantStringType;
109
use PHPStan\Type\DynamicMethodReturnTypeExtension;
1110
use PHPStan\Type\MixedType;
1211
use PHPStan\Type\Type;
12+
use PHPStan\Type\TypeCombinator;
1313
use function count;
1414
use function sprintf;
1515
use function ucfirst;
@@ -43,20 +43,25 @@ public function getTypeFromMethodCall(
4343
}
4444

4545
$argType = $scope->getType($args[0]->value);
46-
if (!$argType instanceof ConstantStringType) {
46+
if (count($argType->getConstantStrings()) === 0) {
4747
return $mixedType;
4848
}
4949

50-
$componentName = $argType->getValue();
50+
$types = [];
51+
foreach ($argType->getConstantStrings() as $constantString) {
52+
$componentName = $constantString->getValue();
5153

52-
$methodName = sprintf('createComponent%s', ucfirst($componentName));
53-
if (!$calledOnType->hasMethod($methodName)->yes()) {
54-
return $mixedType;
55-
}
54+
$methodName = sprintf('createComponent%s', ucfirst($componentName));
55+
if (!$calledOnType->hasMethod($methodName)->yes()) {
56+
return $mixedType;
57+
}
5658

57-
$method = $calledOnType->getMethod($methodName, $scope);
59+
$method = $calledOnType->getMethod($methodName, $scope);
60+
61+
$types[] = ParametersAcceptorSelector::selectSingle($method->getVariants())->getReturnType();
62+
}
5863

59-
return ParametersAcceptorSelector::selectSingle($method->getVariants())->getReturnType();
64+
return TypeCombinator::union(...$types);
6065
}
6166

6267
}

src/Type/Nette/ComponentModelDynamicReturnTypeExtension.php

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
use PHPStan\Analyser\Scope;
77
use PHPStan\Reflection\MethodReflection;
88
use PHPStan\Reflection\ParametersAcceptorSelector;
9-
use PHPStan\Type\Constant\ConstantStringType;
109
use PHPStan\Type\DynamicMethodReturnTypeExtension;
1110
use PHPStan\Type\MixedType;
1211
use PHPStan\Type\Type;
12+
use PHPStan\Type\TypeCombinator;
1313
use function count;
1414
use function sprintf;
1515
use function ucfirst;
@@ -43,20 +43,25 @@ public function getTypeFromMethodCall(
4343
}
4444

4545
$argType = $scope->getType($args[0]->value);
46-
if (!$argType instanceof ConstantStringType) {
46+
if (count($argType->getConstantStrings()) === 0) {
4747
return $mixedType;
4848
}
4949

50-
$componentName = $argType->getValue();
50+
$types = [];
51+
foreach ($argType->getConstantStrings() as $constantString) {
52+
$componentName = $constantString->getValue();
5153

52-
$methodName = sprintf('createComponent%s', ucfirst($componentName));
53-
if (!$calledOnType->hasMethod($methodName)->yes()) {
54-
return $mixedType;
55-
}
54+
$methodName = sprintf('createComponent%s', ucfirst($componentName));
55+
if (!$calledOnType->hasMethod($methodName)->yes()) {
56+
return $mixedType;
57+
}
5658

57-
$method = $calledOnType->getMethod($methodName, $scope);
59+
$method = $calledOnType->getMethod($methodName, $scope);
60+
61+
$types[] = ParametersAcceptorSelector::selectSingle($method->getVariants())->getReturnType();
62+
}
5863

59-
return ParametersAcceptorSelector::selectSingle($method->getVariants())->getReturnType();
64+
return TypeCombinator::union(...$types);
6065
}
6166

6267
}

src/Type/Nette/FormContainerUnsafeValuesDynamicReturnTypeExtension.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,8 @@
77
use PHPStan\Reflection\MethodReflection;
88
use PHPStan\Reflection\ParametersAcceptorSelector;
99
use PHPStan\Type\ArrayType;
10-
use PHPStan\Type\Constant\ConstantStringType;
1110
use PHPStan\Type\DynamicMethodReturnTypeExtension;
1211
use PHPStan\Type\MixedType;
13-
use PHPStan\Type\NullType;
1412
use PHPStan\Type\ObjectType;
1513
use PHPStan\Type\StringType;
1614
use PHPStan\Type\Type;
@@ -37,11 +35,11 @@ public function getTypeFromMethodCall(MethodReflection $methodReflection, Method
3735

3836
$arg = $methodCall->getArgs()[0]->value;
3937
$scopedType = $scope->getType($arg);
40-
if ($scopedType instanceof NullType) {
38+
if ($scopedType->isNull()->yes()) {
4139
return new ObjectType('Nette\Utils\ArrayHash');
4240
}
4341

44-
if ($scopedType instanceof ConstantStringType && $scopedType->getValue() === 'array') {
42+
if (count($scopedType->getConstantStrings()) === 1 && $scopedType->getConstantStrings()[0]->getValue() === 'array') {
4543
return new ArrayType(new StringType(), new MixedType());
4644
}
4745

src/Type/Nette/PresenterGetSessionReturnTypeExtension.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
use PHPStan\Analyser\Scope;
77
use PHPStan\Reflection\MethodReflection;
88
use PHPStan\Type\DynamicMethodReturnTypeExtension;
9-
use PHPStan\Type\NullType;
109
use PHPStan\Type\ObjectType;
1110
use PHPStan\Type\Type;
1211
use function count;
@@ -26,7 +25,7 @@ public function isMethodSupported(MethodReflection $methodReflection): bool
2625

2726
public function getTypeFromMethodCall(MethodReflection $methodReflection, MethodCall $methodCall, Scope $scope): Type
2827
{
29-
if (count($methodCall->getArgs()) === 0 || $scope->getType($methodCall->getArgs()[0]->value) instanceof NullType) {
28+
if (count($methodCall->getArgs()) === 0 || $scope->getType($methodCall->getArgs()[0]->value)->isNull()->yes()) {
3029
return new ObjectType('Nette\Http\Session');
3130
}
3231

src/Type/Nette/ServiceLocatorDynamicReturnTypeExtension.php

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
use PHPStan\Analyser\Scope;
77
use PHPStan\Reflection\MethodReflection;
88
use PHPStan\Type\Constant\ConstantBooleanType;
9-
use PHPStan\Type\Constant\ConstantStringType;
109
use PHPStan\Type\DynamicMethodReturnTypeExtension;
1110
use PHPStan\Type\MixedType;
1211
use PHPStan\Type\ObjectType;
@@ -46,25 +45,30 @@ public function getTypeFromMethodCall(MethodReflection $methodReflection, Method
4645
return $mixedType;
4746
}
4847
$argType = $scope->getType($methodCall->getArgs()[0]->value);
49-
if (!$argType instanceof ConstantStringType) {
48+
if (count($argType->getConstantStrings()) === 0) {
5049
return $mixedType;
5150
}
5251

53-
$type = new ObjectType($argType->getValue());
54-
if (
55-
$methodReflection->getName() === 'getByType'
56-
&& count($methodCall->getArgs()) >= 2
57-
) {
58-
$throwType = $scope->getType($methodCall->getArgs()[1]->value);
52+
$types = [];
53+
foreach ($argType->getConstantStrings() as $constantString) {
54+
$type = new ObjectType($constantString->getValue());
5955
if (
60-
!$throwType instanceof ConstantBooleanType
61-
|| !$throwType->getValue()
56+
$methodReflection->getName() === 'getByType'
57+
&& count($methodCall->getArgs()) >= 2
6258
) {
63-
$type = TypeCombinator::addNull($type);
59+
$throwType = $scope->getType($methodCall->getArgs()[1]->value);
60+
if (
61+
!$throwType instanceof ConstantBooleanType
62+
|| !$throwType->getValue()
63+
) {
64+
$type = TypeCombinator::addNull($type);
65+
}
6466
}
67+
68+
$types[] = $type;
6569
}
6670

67-
return $type;
71+
return TypeCombinator::union(...$types);
6872
}
6973

7074
}

0 commit comments

Comments
 (0)