Skip to content

Commit 23eac57

Browse files
MartinMystikJonasondrejmirtes
authored andcommitted
Multiplier generics
1 parent 0340705 commit 23eac57

File tree

5 files changed

+77
-0
lines changed

5 files changed

+77
-0
lines changed

Diff for: composer.json

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
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",

Diff for: extension.neon

+4
Original file line numberDiff line numberDiff 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

Diff for: stubs/Application/UI/Multiplier.stub

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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+
}

Diff for: tests/Type/Nette/MultiplierTest.php

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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+
}

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

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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);

0 commit comments

Comments
 (0)