Completed
Push — master ( b772ac...ad9c8d )
by Anton
01:25
created

CollectAction::addDefaultRepository()   B

Complexity

Conditions 8
Paths 9

Size

Total Lines 30

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 30
rs 8.1954
c 0
b 0
f 0
cc 8
nc 9
nop 1
1
<?php
2
3
/*
4
 * This file is part of Laravel Paket.
5
 *
6
 * (c) Anton Komarev <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace Cog\Laravel\Paket\Http\Controllers\Api\Repositories;
15
16
use Illuminate\Contracts\Support\Responsable as ResponsableContract;
17
use MCStreetguy\ComposerParser\Factory as ComposerParser;
18
19
final class CollectAction
20
{
21
    public function __invoke(): ResponsableContract
22
    {
23
        $repositories = $this->getRepositories();
24
25
        return new CollectResponse($repositories);
26
    }
27
28
    private function getRepositories(): array
29
    {
30
        $jsonFile = ComposerParser::parseComposerJson(base_path('composer.json'));
31
32
        $repositories = $jsonFile->getRepositories();
33
        $output = [];
34
35
        foreach ($repositories as $key => $repository) {
36
            $package = $repository->getPackage();
37
38
            $output[$key] = [
39
                'type' => $repository->getType(),
40
                'url' => $repository->getUrl(),
41
                'options' => $repository->getOptions(),
42
                'package' => is_null($package) ? null : $package->toArray(),
43
            ];
44
        }
45
46
        return $output;
47
    }
48
}
49