Collector   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 15
dl 0
loc 40
rs 10
c 0
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A collect() 0 17 3
1
<?php
2
/**
3
 * Copyright © Vaimo Group. All rights reserved.
4
 * See LICENSE_VAIMO.txt for license details.
5
 */
6
namespace Vaimo\ComposerPatches\Package;
7
8
use Composer\Repository\WritableRepositoryInterface;
9
10
class Collector
11
{
12
    /**
13
     * @var array|\Composer\Package\PackageInterface[]
14
     */
15
    private $extraPackages;
16
17
    /**
18
     * @var \Vaimo\ComposerPatches\Utils\PackageUtils
19
     */
20
    private $packageUtils;
21
22
    /**
23
     * @param \Composer\Package\PackageInterface[] $extraPackages
24
     */
25
    public function __construct(
26
        array $extraPackages = array()
27
    ) {
28
        $this->extraPackages = $extraPackages;
29
30
        $this->packageUtils = new \Vaimo\ComposerPatches\Utils\PackageUtils();
31
    }
32
33
    public function collect(WritableRepositoryInterface $repository)
34
    {
35
        $packages = $this->extraPackages;
36
37
        foreach ($repository->getPackages() as $package) {
38
            $packages[] = $this->packageUtils->getRealPackage($package);
39
        }
40
41
        return array_combine(
42
            array_map(
43
                function (\Composer\Package\PackageInterface $package) {
44
                    return $package->getName();
45
                },
46
                $packages
47
            ),
48
            $packages
49
        ) ?: array();
50
    }
51
}
52