diff --git a/extension.neon b/extension.neon index c8c147f..e09c7df 100644 --- a/extension.neon +++ b/extension.neon @@ -9,7 +9,6 @@ parameters: - stubs/Application/UI/Component.stub - stubs/Application/UI/Multiplier.stub - stubs/ComponentModel/Component.stub - - stubs/ComponentModel/Container.stub - stubs/ComponentModel/IComponent.stub - stubs/ComponentModel/IContainer.stub - stubs/Database/ResultSet.stub @@ -110,3 +109,8 @@ services: class: PHPStan\Rule\Nette\PresenterInjectedPropertiesExtension tags: - phpstan.properties.readWriteExtension + + - + class: PHPStan\Stubs\Nette\StubFilesExtensionLoader + tags: + - phpstan.stubFilesExtension diff --git a/src/Stubs/Nette/StubFilesExtensionLoader.php b/src/Stubs/Nette/StubFilesExtensionLoader.php new file mode 100644 index 0000000..342ffb0 --- /dev/null +++ b/src/Stubs/Nette/StubFilesExtensionLoader.php @@ -0,0 +1,47 @@ +=')) { + $files[] = $path . '/ComponentModel/Container_3_1.stub'; + } else { + $files[] = $path . '/ComponentModel/Container.stub'; + } + + return $files; + } + + private static function getInstalledVersion(string $package): ?string + { + if (!class_exists(InstalledVersions::class)) { + return null; + } + + try { + $installedVersion = InstalledVersions::getVersion($package); + } catch (OutOfBoundsException $e) { + return null; + } + + return $installedVersion; + } + +} diff --git a/stubs/ComponentModel/Container_3_1.stub b/stubs/ComponentModel/Container_3_1.stub new file mode 100644 index 0000000..a737ed9 --- /dev/null +++ b/stubs/ComponentModel/Container_3_1.stub @@ -0,0 +1,21 @@ + $filterType + * @phpstan-return ( + * $deep is true + * ? ($filterType is null ? array : array) + * : ($filterType is null ? \Iterator : \Iterator) + * ) + */ + public function getComponents(bool $deep = false, string $filterType = null): \Iterator + { + // nothing + } +}