| 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 (!\is_file($filePath)) { |
||
| 26 | throw new FileNotFoundException('Sorry! This file was not found or does not exist'); |
||
| 27 | } |
||
| 28 | |||
| 29 | if (false === $content = \file_get_contents($filePath)) { |
||
| 30 | throw new FileContentExeption('An error has occured while reading your file !'); |
||
| 31 | } |
||
| 32 | |||
| 33 | $data = \json_decode($content, 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 |