Skip to content

Commit 488d326

Browse files
committed
Nullable Multiplier stub
1 parent 31a349d commit 488d326

File tree

3 files changed

+62
-1
lines changed

3 files changed

+62
-1
lines changed

extension.neon

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ parameters:
77
stubFiles:
88
- stubs/Application/Routers/RouteList.stub
99
- stubs/Application/UI/Component.stub
10-
- stubs/Application/UI/Multiplier.stub
1110
- stubs/Application/UI/Presenter.stub
1211
- stubs/Caching/Cache.stub
1312
- stubs/ComponentModel/Component.stub
@@ -52,6 +51,11 @@ parameters:
5251
- forward
5352

5453
services:
54+
-
55+
class: PHPStan\Stubs\Nette\Application\StubFilesExtensionLoader
56+
tags:
57+
- phpstan.stubFilesExtension
58+
5559
-
5660
class: PHPStan\Reflection\Nette\HtmlClassReflectionExtension
5761
tags:
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace PHPStan\Stubs\Nette\Application;
4+
5+
use Composer\InstalledVersions;
6+
use OutOfBoundsException;
7+
use PHPStan\PhpDoc\StubFilesExtension;
8+
use function class_exists;
9+
use function dirname;
10+
use function version_compare;
11+
12+
class StubFilesExtensionLoader implements StubFilesExtension
13+
{
14+
15+
public function getFiles(): array
16+
{
17+
$path = dirname(dirname(dirname(dirname(__DIR__)))) . '/stubs';
18+
19+
try {
20+
$applicationVersion = class_exists(InstalledVersions::class)
21+
? InstalledVersions::getVersion('nette/application')
22+
: null;
23+
} catch (OutOfBoundsException $e) {
24+
$applicationVersion = null;
25+
}
26+
27+
$files = [];
28+
29+
if ($applicationVersion !== null && version_compare($applicationVersion, '3.2.5', '>=')) {
30+
$files[] = $path . '/Application/UI/NullableMultiplier.stub';
31+
} else {
32+
$files[] = $path . '/Application/UI/Multiplier.stub';
33+
}
34+
35+
return $files;
36+
}
37+
38+
}
Lines changed: 19 additions & 0 deletions
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|null) $factory
12+
*/
13+
public function __construct(callable $factory);
14+
15+
/**
16+
* @return T|null
17+
*/
18+
protected function createComponent(string $name): ?\Nette\ComponentModel\IComponent;
19+
}

0 commit comments

Comments
 (0)