Conditions | 7 |
Paths | 6 |
Total Lines | 26 |
Code Lines | 13 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
23 | public static function parse(string $filePath): PackageCollection |
||
24 | { |
||
25 | if (strcmp(pathinfo($filePath)['basename'], 'composer.lock') !== 0) { |
||
26 | throw new InvalidComposerLockFileException(); |
||
27 | } |
||
28 | |||
29 | if (false === \file_exists($filePath)) { |
||
30 | throw new FileNotFoundException(); |
||
31 | } |
||
32 | |||
33 | $data = \json_decode(\file_get_contents($filePath), true, 512, JSON_THROW_ON_ERROR); |
||
34 | |||
35 | if (empty($data)) { |
||
36 | return new PackageCollection(); |
||
37 | } |
||
38 | |||
39 | $packages = new PackageCollection(); |
||
40 | |||
41 | if (!$data || !isset($data['packages'])) { |
||
42 | return new PackageCollection(); |
||
43 | } |
||
44 | |||
45 | foreach ($data['packages'] as $package) { |
||
46 | $packages[] = Package::factory($package); |
||
47 | } |
||
48 | return $packages; |
||
49 | } |
||
51 |