|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace PHPStan\Type\Nette\Data\ComponentModel; |
| 4 | + |
| 5 | +use Nette\Application\UI\Control; |
| 6 | +use function PHPStan\Testing\assertType; |
| 7 | + |
| 8 | +class SomeControl extends Control { |
| 9 | + |
| 10 | + public function createComponentSome(): self { |
| 11 | + return new SomeControl(); |
| 12 | + } |
| 13 | + |
| 14 | +} |
| 15 | + |
| 16 | +class AnotherControl extends Control { |
| 17 | + |
| 18 | + public function createComponentAnother(): AnotherControl { |
| 19 | + return new AnotherControl(); |
| 20 | + } |
| 21 | + |
| 22 | + public function createComponentSome(): SomeControl { |
| 23 | + return new SomeControl(); |
| 24 | + } |
| 25 | + |
| 26 | +} |
| 27 | + |
| 28 | +class OverrideCreateControl extends Control { |
| 29 | + |
| 30 | + public function createComponent(string $name): AnotherControl { |
| 31 | + return new AnotherControl(); |
| 32 | + } |
| 33 | + |
| 34 | +} |
| 35 | + |
| 36 | +$someControl = new SomeControl(); |
| 37 | +assertType('PHPStan\Type\Nette\Data\ComponentModel\SomeControl', $someControl->getComponent('some')); |
| 38 | +assertType('Nette\ComponentModel\IComponent|null', $someControl->getComponent('unknown')); |
| 39 | + |
| 40 | +$anotherControl = new AnotherControl(); |
| 41 | +assertType('PHPStan\Type\Nette\Data\ComponentModel\AnotherControl', $anotherControl->getComponent('another')); |
| 42 | +assertType('PHPStan\Type\Nette\Data\ComponentModel\SomeControl', $anotherControl->getComponent('some')); |
| 43 | +assertType('Nette\ComponentModel\IComponent|null', $anotherControl->getComponent('unknown')); |
| 44 | + |
| 45 | +$overrideCreateControl = new OverrideCreateControl(); |
| 46 | +assertType('PHPStan\Type\Nette\Data\ComponentModel\AnotherControl', $overrideCreateControl->getComponent('some')); |
| 47 | +assertType('PHPStan\Type\Nette\Data\ComponentModel\AnotherControl', $overrideCreateControl->getComponent('unknown')); |
0 commit comments