-
Notifications
You must be signed in to change notification settings - Fork 44
Expand file tree
/
Copy pathStubFilesExtensionLoader.php
More file actions
47 lines (36 loc) · 1.06 KB
/
Copy pathStubFilesExtensionLoader.php
File metadata and controls
47 lines (36 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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;
}
}