-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update ComponentModel\Container stub for component-model 3.1.0
That version changes the return type to array when `$deep` argument is `false` (default): nette/component-model@7f613ee It also deprecates the arguments but we cannot add deprecated annotation to those. nette/component-model@4e0946a
- Loading branch information
Showing
3 changed files
with
73 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace PHPStan\Stubs\Nette; | ||
|
||
use Composer\InstalledVersions; | ||
use OutOfBoundsException; | ||
use PHPStan\PhpDoc\StubFilesExtension; | ||
use function class_exists; | ||
use function dirname; | ||
use function version_compare; | ||
|
||
class StubFilesExtensionLoader implements StubFilesExtension | ||
{ | ||
|
||
public function getFiles(): array | ||
{ | ||
$stubsDir = dirname(dirname(dirname(__DIR__))) . '/stubs'; | ||
$path = $stubsDir; | ||
|
||
$files = []; | ||
|
||
$componentModelVersion = self::getInstalledVersion('nette/component-model'); | ||
if ($componentModelVersion !== null && version_compare($componentModelVersion, '3.1.0', '>=')) { | ||
$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; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
namespace Nette\ComponentModel; | ||
|
||
class Container extends Component implements IContainer | ||
{ | ||
|
||
/** | ||
* @template T of \Nette\ComponentModel\IComponent | ||
* @phpstan-param null|class-string<T> $filterType | ||
* @phpstan-return ( | ||
* $deep is true | ||
* ? ($filterType is null ? array<int|string, \Nette\ComponentModel\IComponent> : array<int|string, T>) | ||
* : ($filterType is null ? \Iterator<int|string, \Nette\ComponentModel\IComponent> : \Iterator<int|string, T>) | ||
* ) | ||
*/ | ||
public function getComponents(bool $deep = false, string $filterType = null): iterable | ||
{ | ||
// nothing | ||
} | ||
} |