File tree Expand file tree Collapse file tree 5 files changed +77
-0
lines changed Expand file tree Collapse file tree 5 files changed +77
-0
lines changed Original file line number Diff line number Diff line change 1818 "nette/utils" : " <2.3.0"
1919 },
2020 "require-dev" : {
21+ "nette/application" : " ^3.0" ,
2122 "nette/forms" : " ^3.0" ,
2223 "nette/utils" : " ^2.3.0 || ^3.0.0" ,
2324 "nikic/php-parser" : " ^4.13.2" ,
Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ parameters:
77 stubFiles :
88 - stubs/Application/Routers/RouteList.stub
99 - stubs/Application/UI/Component.stub
10+ - stubs/Application/UI/Multiplier.stub
1011 - stubs/ComponentModel/Component.stub
1112 - stubs/ComponentModel/Container.stub
1213 - stubs/ComponentModel/IComponent.stub
@@ -31,6 +32,9 @@ parameters:
3132 - Nette\Http\SessionSection
3233 - Nette\Security\Identity
3334 - Nette\Security\SimpleIdentity
35+ featureToggles :
36+ skipCheckGenericClasses :
37+ - Nette\Application\UI\Multiplier
3438 earlyTerminatingMethodCalls :
3539 Nette\Application\UI\Component :
3640 - error
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Nette\Application\UI;
4+
5+ /**
6+ * @template T of \Nette\ComponentModel\IComponent
7+ */
8+ final class Multiplier extends Component
9+ {
10+ /**
11+ * @param callable(string, self<T>) : T $factory
12+ */
13+ public function __construct(callable $factory);
14+
15+ /**
16+ * @return T
17+ */
18+ protected function createComponent(string $name): \Nette\ComponentModel\IComponent;
19+ }
Original file line number Diff line number Diff line change 1+ <?php declare (strict_types = 1 );
2+
3+ namespace PHPStan \Type \Nette ;
4+
5+ use PHPStan \Testing \TypeInferenceTestCase ;
6+
7+ class MultiplierTest extends TypeInferenceTestCase
8+ {
9+
10+ /** @return iterable<mixed> */
11+ public function dataFileAsserts (): iterable
12+ {
13+ yield from $ this ->gatherAssertTypes (__DIR__ . '/data/multiplier.php ' );
14+ }
15+
16+ /**
17+ * @dataProvider dataFileAsserts
18+ * @param mixed ...$args
19+ */
20+ public function testFileAsserts (
21+ string $ assertType ,
22+ string $ file ,
23+ ...$ args
24+ ): void
25+ {
26+ $ this ->assertFileAsserts ($ assertType , $ file , ...$ args );
27+ }
28+
29+ public static function getAdditionalConfigFiles (): array
30+ {
31+ return [
32+ __DIR__ . '/../../../extension.neon ' ,
33+ ];
34+ }
35+
36+ }
Original file line number Diff line number Diff line change 1+ <?php declare (strict_types = 1 );
2+
3+ use Nette \Application \UI \Form ;
4+ use Nette \Application \UI \Multiplier ;
5+
6+ use function PHPStan \Testing \assertType ;
7+
8+ /** @var Multiplier<Form> $multiplier */
9+ $ multiplier = new Multiplier (function (string $ name ): Form {
10+ return new Form ();
11+ });
12+
13+ assertType ('Nette\Application\UI\Multiplier<Nette\Application\UI\Form> ' , $ multiplier );
14+
15+ $ form = $ multiplier ->createComponent ('foo ' );
16+
17+ assertType (Form::class, $ form );
You can’t perform that action at this time.
0 commit comments