Normalizer::process()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 18
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 9
c 0
b 0
f 0
nc 3
nop 4
dl 0
loc 18
rs 9.9666
1
<?php
2
/**
3
 * Copyright © Vaimo Group. All rights reserved.
4
 * See LICENSE_VAIMO.txt for license details.
5
 */
6
namespace Vaimo\ComposerPatches\Patch\Definition;
7
8
class Normalizer
9
{
10
    /**
11
     * @var \Vaimo\ComposerPatches\Interfaces\DefinitionNormalizerComponentInterface[]
12
     */
13
    private $components;
14
15
    /**
16
     * @var  \Vaimo\ComposerPatches\Patch\Definition\SourceResolver
17
     */
18
    private $sourceResolver;
19
20
    /**
21
     * @param \Vaimo\ComposerPatches\Interfaces\DefinitionNormalizerComponentInterface[] $components
22
     */
23
    public function __construct(
24
        array $components
25
    ) {
26
        $this->components = $components;
27
        $this->sourceResolver = new \Vaimo\ComposerPatches\Patch\Definition\SourceResolver();
28
    }
29
30
    public function process($target, $label, $data, array $ownerConfig)
31
    {
32
        $data = $this->sourceResolver->updateSourceDeclaration($label, $data);
33
34
        $config = array();
35
36
        foreach ($this->components as $component) {
37
            $updates = $component->normalize($target, $label, $data, $ownerConfig);
38
39
            if (empty($updates)) {
40
                continue;
41
            }
42
43
            $config = array_replace($config, $updates);
44
            $data = array_replace($data, $updates);
45
        }
46
47
        return $config;
48
    }
49
}
50