From 11e9969a8518b1184be5e9caffd22b4938c93b70 Mon Sep 17 00:00:00 2001 From: Jan Tojnar Date: Sat, 18 May 2024 14:12:38 +0200 Subject: [PATCH] Update ComponentModel\Container stub for component-model 3.1.0 That version changes the return type to array when `$deep` argument is `false` (default): https://github.com/nette/component-model/commit/7f613eed7f5e57b6bde2d0be1bfdbb7e161620b3 It also deprecates the arguments but we cannot add deprecated annotation to those. https://github.com/nette/component-model/commit/4e0946a788b4ac42ea903b761c693ec7dd083a69 --- extension.neon | 6 ++- src/Stubs/Nette/StubFilesExtensionLoader.php | 47 ++++++++++++++++++++ stubs/ComponentModel/Container_3_1.stub | 21 +++++++++ 3 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 src/Stubs/Nette/StubFilesExtensionLoader.php create mode 100644 stubs/ComponentModel/Container_3_1.stub 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 + } +}