Passed
Push — master ( b3a69d...79ebcc )
by Allan
02:21 queued 11s
created

ListNormalizer::createNormalizedList()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 23
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 13
nc 3
nop 3
dl 0
loc 23
rs 9.8333
c 0
b 0
f 0
1
<?php
2
/**
3
 * Copyright © Vaimo Group. All rights reserved.
4
 * See LICENSE_VAIMO.txt for license details.
5
 */
6
namespace Vaimo\ComposerPatches\Patch;
7
8
class ListNormalizer
9
{
10
    /**
11
     * @var \Vaimo\ComposerPatches\Patch\Definition\Exploder
12
     */
13
    private $definitionExploder;
14
15
    /**
16
     * @var \Vaimo\ComposerPatches\Patch\Definition\Normalizer
17
     */
18
    private $definitionNormalizer;
19
20
    /**
21
     * @var \Vaimo\ComposerPatches\Patch\DefinitionList\Sanitizer
22
     */
23
    private $patchListSanitizer;
24
25
    /**
26
     * @param \Vaimo\ComposerPatches\Patch\Definition\Exploder $definitionExploder
27
     * @param \Vaimo\ComposerPatches\Patch\Definition\Normalizer $definitionNormalizer
28
     */
29
    public function __construct(
30
        \Vaimo\ComposerPatches\Patch\Definition\Exploder $definitionExploder,
31
        \Vaimo\ComposerPatches\Patch\Definition\Normalizer $definitionNormalizer
32
    ) {
33
        $this->definitionExploder = $definitionExploder;
34
        $this->definitionNormalizer = $definitionNormalizer;
35
36
        $this->patchListSanitizer = new \Vaimo\ComposerPatches\Patch\DefinitionList\Sanitizer();
37
    }
38
39
    public function normalize(array $list, array $config)
40
    {
41
        $result = array();
42
43
        $sanitizedList = $this->patchListSanitizer->getSanitizedList($list);
44
45
        foreach ($sanitizedList as $target => $packagePatches) {
46
            $result[$target] = $this->createNormalizedList($target, $packagePatches, $config);
47
        }
48
49
        return array_filter(
50
            array_map('array_filter', $result)
51
        );
52
    }
53
54
    private function createNormalizedList($target, $patches, $config)
55
    {
56
        $result = array();
57
58
        foreach ($patches as $patchLabel => $patchConfig) {
59
            $definitionItems = $this->definitionExploder->process(
60
                $patchLabel,
61
                $patchConfig
62
            );
63
64
            foreach ($definitionItems as $patchItem) {
65
                list($label, $data) = $patchItem;
66
67
                $result[] = $this->definitionNormalizer->process(
68
                    $target,
69
                    $label,
70
                    $data,
71
                    $config
72
                );
73
            }
74
        }
75
76
        return $result;
77
    }
78
}
79