| Total Complexity | 7 |
| Total Lines | 65 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 8 | class ComposerRequirements |
||
| 9 | { |
||
| 10 | /** |
||
| 11 | * @var bool |
||
| 12 | */ |
||
| 13 | private $dev; |
||
| 14 | |||
| 15 | /** |
||
| 16 | * ComposerDependencies constructor. |
||
| 17 | * |
||
| 18 | * @param bool $dev |
||
| 19 | */ |
||
| 20 | public function __construct(bool $dev = false) |
||
| 21 | { |
||
| 22 | $this->dev = $dev; |
||
| 23 | } |
||
| 24 | |||
| 25 | /** |
||
| 26 | * Retrieve an array of composer package dependencies from the composer.json. |
||
| 27 | * |
||
| 28 | * @return Collection |
||
| 29 | */ |
||
| 30 | public function get(): Collection |
||
| 31 | { |
||
| 32 | // If development packages are included, merge require & require-dev |
||
| 33 | $dependencies = $this->dev ? array_merge(self::require(), self::requireDev()) : self::require(); |
||
| 34 | |||
| 35 | // Retrieve 'require' array from composer.json with only package names (the keys |
||
| 36 | // todo: remove keys? |
||
| 37 | return collect(array_keys($dependencies)) |
||
| 38 | |||
| 39 | // Remove 'php' & php extensions from the packages array |
||
| 40 | ->filter(function (string $dep) { |
||
| 41 | return $dep != 'php' && ! (new StringHelpers($dep))->inString('ext'); |
||
| 42 | }); |
||
| 43 | } |
||
| 44 | |||
| 45 | /** |
||
| 46 | * Return the file contents of a composer.json file decoded as json array. |
||
| 47 | * |
||
| 48 | * @return array |
||
| 49 | */ |
||
| 50 | private static function composerJson(): array |
||
| 51 | { |
||
| 52 | return json_decode(file_get_contents(config('dependencies.composer_json_path')), true); |
||
| 53 | } |
||
| 54 | |||
| 55 | /** |
||
| 56 | * Retrieve an array of the composer package dependencies. |
||
| 57 | * |
||
| 58 | * @return array |
||
| 59 | */ |
||
| 60 | private static function require(): array |
||
| 63 | } |
||
| 64 | |||
| 65 | /** |
||
| 66 | * Retrieve an array of the composer package development dependencies. |
||
| 67 | * |
||
| 68 | * @return array |
||
| 69 | */ |
||
| 70 | private static function requireDev(): array |
||
| 73 | } |
||
| 74 | } |
||
| 75 |