-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0340705
commit 23eac57
Showing
5 changed files
with
77 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
namespace Nette\Application\UI; | ||
|
||
/** | ||
* @template T of \Nette\ComponentModel\IComponent | ||
*/ | ||
final class Multiplier extends Component | ||
{ | ||
/** | ||
* @param callable(string, self<T>) : T $factory | ||
*/ | ||
public function __construct(callable $factory); | ||
|
||
/** | ||
* @return T | ||
*/ | ||
protected function createComponent(string $name): \Nette\ComponentModel\IComponent; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace PHPStan\Type\Nette; | ||
|
||
use PHPStan\Testing\TypeInferenceTestCase; | ||
|
||
class MultiplierTest extends TypeInferenceTestCase | ||
{ | ||
|
||
/** @return iterable<mixed> */ | ||
public function dataFileAsserts(): iterable | ||
{ | ||
yield from $this->gatherAssertTypes(__DIR__ . '/data/multiplier.php'); | ||
} | ||
|
||
/** | ||
* @dataProvider dataFileAsserts | ||
* @param mixed ...$args | ||
*/ | ||
public function testFileAsserts( | ||
string $assertType, | ||
string $file, | ||
...$args | ||
): void | ||
{ | ||
$this->assertFileAsserts($assertType, $file, ...$args); | ||
} | ||
|
||
public static function getAdditionalConfigFiles(): array | ||
{ | ||
return [ | ||
__DIR__ . '/../../../extension.neon', | ||
]; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
use Nette\Application\UI\Form; | ||
use Nette\Application\UI\Multiplier; | ||
|
||
use function PHPStan\Testing\assertType; | ||
|
||
/** @var Multiplier<Form> $multiplier */ | ||
$multiplier = new Multiplier(function (string $name): Form { | ||
return new Form(); | ||
}); | ||
|
||
assertType('Nette\Application\UI\Multiplier<Nette\Application\UI\Form>', $multiplier); | ||
|
||
$form = $multiplier->createComponent('foo'); | ||
|
||
assertType(Form::class, $form); |