Skip to content

Commit 4369616

Browse files
committed
Nette\Application\UI\Multiplier factory can return null
1 parent 3320991 commit 4369616

File tree

3 files changed

+59
-1
lines changed

3 files changed

+59
-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\Application\StubFilesExtensionLoader
56+
tags:
57+
- phpstan.stubFilesExtension
58+
5559
-
5660
class: PHPStan\Reflection\Nette\HtmlClassReflectionExtension
5761
tags:
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace PHPStan\Stubs\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+
public function getFiles(): array {
15+
$path = dirname(dirname(dirname(__DIR__))) . '/stubs';
16+
17+
try {
18+
$applicationVersion = class_exists(InstalledVersions::class)
19+
? InstalledVersions::getVersion('nette/application')
20+
: null;
21+
} catch (OutOfBoundsException $e) {
22+
$applicationVersion = null;
23+
}
24+
25+
$files = [];
26+
27+
if ($applicationVersion !== null && version_compare($applicationVersion, '3.2.5', '>=')) {
28+
$files[] = $path . '/Application/UI/Multiplier1.stub';
29+
} else {
30+
$files[] = $path . '/Application/UI/Multiplier.stub';
31+
}
32+
33+
return $files;
34+
}
35+
}
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|null
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+
}

0 commit comments

Comments
 (0)