1 | <?php |
||
2 | |||
3 | declare(strict_types=1); |
||
4 | |||
5 | /* |
||
6 | * This file is part of the box project. |
||
7 | * |
||
8 | * (c) Kevin Herrera <[email protected]> |
||
9 | * Théo Fidry <[email protected]> |
||
10 | * |
||
11 | * This source file is subject to the MIT license that is bundled |
||
12 | * with this source code in the file LICENSE. |
||
13 | */ |
||
14 | |||
15 | namespace KevinGH\Box\Composer\Artifact; |
||
16 | |||
17 | use KevinGH\Box\Composer\Package\Extensions; |
||
18 | use KevinGH\Box\Composer\Package\PackageInfo; |
||
19 | use function array_column; |
||
20 | use function array_map; |
||
21 | |||
22 | /** |
||
23 | * @private |
||
24 | */ |
||
25 | final readonly class ComposerLock |
||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
26 | { |
||
27 | /** |
||
28 | * @param array $decodedContents Decoded JSON contents of the `composer.lock` file |
||
29 | */ |
||
30 | public function __construct( |
||
31 | public string $path, |
||
32 | public array $decodedContents, |
||
33 | ) { |
||
34 | } |
||
35 | |||
36 | public function isEmpty(): bool |
||
37 | { |
||
38 | return [] === $this->decodedContents; |
||
39 | } |
||
40 | |||
41 | public function getRequiredPhpVersion(): ?string |
||
42 | { |
||
43 | return $this->decodedContents['platform']['php'] ?? null; |
||
44 | } |
||
45 | |||
46 | public function hasRequiredPhpVersion(): bool |
||
47 | { |
||
48 | return null !== $this->getRequiredPhpVersion(); |
||
49 | } |
||
50 | |||
51 | public function getPlatformExtensions(): Extensions |
||
52 | { |
||
53 | return PackageInfo::parseExtensions($this->decodedContents['platform'] ?? []); |
||
54 | } |
||
55 | |||
56 | /** |
||
57 | * @return PackageInfo[] |
||
58 | */ |
||
59 | public function getPackages(): array |
||
60 | { |
||
61 | return array_map( |
||
62 | static fn (array $package) => new PackageInfo($package), |
||
63 | $this->decodedContents['packages'] ?? [], |
||
64 | ); |
||
65 | } |
||
66 | |||
67 | /** |
||
68 | * @return string[] Names of the dev packages |
||
69 | */ |
||
70 | public function getDevPackageNames(): array |
||
71 | { |
||
72 | return array_column($this->decodedContents['packages-dev'] ?? [], 'name'); |
||
73 | } |
||
74 | } |
||
75 |