-
Notifications
You must be signed in to change notification settings - Fork 223
Expand file tree
/
Copy pathComposerPackageResource.php
More file actions
45 lines (37 loc) · 1.1 KB
/
ComposerPackageResource.php
File metadata and controls
45 lines (37 loc) · 1.1 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
<?php
declare(strict_types=1);
namespace OpenTelemetry\Config\SDK\Configuration\Internal;
use Composer\InstalledVersions;
use Symfony\Component\Config\Resource\SelfCheckingResourceInterface;
/**
* @internal
*/
final readonly class ComposerPackageResource implements SelfCheckingResourceInterface
{
public string $packageName;
public string|false $version;
public function __construct(string $packageName)
{
$this->packageName = $packageName;
$this->version = self::getVersion($packageName);
}
#[\Override]
public function isFresh(int $timestamp): bool
{
return $this->version === self::getVersion($this->packageName);
}
#[\Override]
public function __toString(): string
{
return 'composer.' . $this->packageName;
}
/**
* @psalm-suppress NullableReturnStatement,InvalidNullableReturnType
*/
private static function getVersion(string $packageName): string|false
{
return InstalledVersions::isInstalled($packageName)
? InstalledVersions::getVersion($packageName)
: false;
}
}