File tree Expand file tree Collapse file tree 3 files changed +82
-1
lines changed Expand file tree Collapse file tree 3 files changed +82
-1
lines changed Original file line number Diff line number Diff line change @@ -9,7 +9,6 @@ parameters:
99 - stubs/Application/UI/Component.stub
1010 - stubs/Application/UI/Multiplier.stub
1111 - stubs/ComponentModel/Component.stub
12- - stubs/ComponentModel/Container.stub
1312 - stubs/ComponentModel/IComponent.stub
1413 - stubs/ComponentModel/IContainer.stub
1514 - stubs/Database/ResultSet.stub
@@ -110,3 +109,8 @@ services:
110109 class : PHPStan\Rule\Nette\PresenterInjectedPropertiesExtension
111110 tags :
112111 - phpstan.properties.readWriteExtension
112+
113+ -
114+ class : PHPStan\Stubs\Nette\StubFilesExtensionLoader
115+ tags :
116+ - phpstan.stubFilesExtension
Original file line number Diff line number Diff line change 1+ <?php declare (strict_types = 1 );
2+
3+ namespace PHPStan \Stubs \Nette ;
4+
5+ use Composer \InstalledVersions ;
6+ use OutOfBoundsException ;
7+ use PHPStan \BetterReflection \Reflector \Reflector ;
8+ use PHPStan \PhpDoc \StubFilesExtension ;
9+ use function class_exists ;
10+ use function dirname ;
11+ use function version_compare ;
12+
13+ class StubFilesExtensionLoader implements StubFilesExtension
14+ {
15+
16+ /** @var Reflector */
17+ private $ reflector ;
18+
19+ public function __construct (Reflector $ reflector )
20+ {
21+ $ this ->reflector = $ reflector ;
22+ }
23+
24+ public function getFiles (): array
25+ {
26+ $ stubsDir = dirname (dirname (dirname (__DIR__ ))) . '/stubs ' ;
27+ $ path = $ stubsDir ;
28+
29+ $ files = [];
30+
31+ $ componentModelVersion = self ::getInstalledVersion ('nette/component-model ' );
32+ if ($ componentModelVersion !== null && version_compare ($ componentModelVersion , '3.1.0 ' , '>= ' )) {
33+ $ files [] = $ path . '/ComponentModel/Container_3_1.stub ' ;
34+ } else {
35+ $ files [] = $ path . '/ComponentModel/Container.stub ' ;
36+ }
37+
38+ return $ files ;
39+ }
40+
41+ private static function getInstalledVersion (string $ package ): ?string
42+ {
43+ if (!class_exists (InstalledVersions::class)) {
44+ return null ;
45+ }
46+
47+ try {
48+ $ installedVersion = InstalledVersions::getVersion ($ package );
49+ } catch (OutOfBoundsException $ e ) {
50+ return null ;
51+ }
52+
53+ return $ installedVersion ;
54+ }
55+
56+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Nette\ComponentModel;
4+
5+ class Container extends Component implements IContainer
6+ {
7+
8+ /**
9+ * @template T of \Nette\ComponentModel\IComponent
10+ * @phpstan-param null|class-string<T> $filterType
11+ * @phpstan-return (
12+ * $deep is true
13+ * ? ($filterType is null ? array<int|string, \Nette\ComponentModel\IComponent> : array<int|string, T>)
14+ * : ($filterType is null ? \Iterator<int|string, \Nette\ComponentModel\IComponent> : \Iterator<int|string, T>)
15+ * )
16+ */
17+ public function getComponents(bool $deep = false, string $filterType = null): \Iterator
18+ {
19+ // nothing
20+ }
21+ }
You can’t perform that action at this time.
0 commit comments