Skip to content

Commit 0e3a680

Browse files
committed
getComponent with 2nd parameter bool might throw or it might not
1 parent c82fd6c commit 0e3a680

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

Diff for: src/Type/Nette/ComponentModelDynamicReturnTypeExtension.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public function getTypeFromMethodCall(
5050
$throw = true;
5151
if (isset($args[1])) {
5252
$throwType = $scope->getType($args[1]->value);
53-
if ($throwType->isTrue()->no()) {
53+
if (!$throwType->isTrue()->yes()) {
5454
$throw = false;
5555
}
5656
}

Diff for: tests/Type/Nette/data/componentModel.php

+5
Original file line numberDiff line numberDiff line change
@@ -33,21 +33,26 @@ public function createComponent(string $name): AnotherControl {
3333

3434
}
3535

36+
$bool = rand(0, 1) ? true : false;
37+
3638
$someControl = new SomeControl();
3739
assertType('PHPStan\Type\Nette\Data\ComponentModel\SomeControl', $someControl->getComponent('some'));
3840
assertType('mixed~null', $someControl->getComponent('unknown'));
3941
assertType('mixed', $someControl->getComponent('unknown', false));
4042
assertType('mixed~null', $someControl->getComponent('unknown', true));
43+
assertType('mixed', $someControl->getComponent('unknown', $bool));
4144

4245
$anotherControl = new AnotherControl();
4346
assertType('PHPStan\Type\Nette\Data\ComponentModel\AnotherControl', $anotherControl->getComponent('another'));
4447
assertType('PHPStan\Type\Nette\Data\ComponentModel\SomeControl', $anotherControl->getComponent('some'));
4548
assertType('mixed~null', $anotherControl->getComponent('unknown'));
4649
assertType('mixed', $anotherControl->getComponent('unknown', false));
4750
assertType('mixed~null', $anotherControl->getComponent('unknown', true));
51+
assertType('mixed', $anotherControl->getComponent('unknown', $bool));
4852

4953
$overrideCreateControl = new OverrideCreateControl();
5054
assertType('PHPStan\Type\Nette\Data\ComponentModel\AnotherControl', $overrideCreateControl->getComponent('some'));
5155
assertType('PHPStan\Type\Nette\Data\ComponentModel\AnotherControl', $overrideCreateControl->getComponent('unknown'));
5256
assertType('PHPStan\Type\Nette\Data\ComponentModel\AnotherControl', $overrideCreateControl->getComponent('unknown', false));
5357
assertType('PHPStan\Type\Nette\Data\ComponentModel\AnotherControl', $overrideCreateControl->getComponent('unknown', true));
58+
assertType('PHPStan\Type\Nette\Data\ComponentModel\AnotherControl', $overrideCreateControl->getComponent('unknown', $bool));

0 commit comments

Comments
 (0)