Exploder::process()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 20
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 11
nc 3
nop 3
dl 0
loc 20
rs 9.9
c 1
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\Definition\Constraint;
7
8
use Vaimo\ComposerPatches\Patch\Definition as PatchDefinition;
9
10
class Exploder
11
{
12
    /**
13
     * @var \Vaimo\ComposerPatches\Patch\Definition\Value\Analyser
14
     */
15
    private $valueAnalyser;
16
17
    /**
18
     * @var PatchDefinition\Exploder\ItemBuilder
19
     */
20
    private $itemBuilder;
21
22
    public function __construct()
23
    {
24
        $this->valueAnalyser = new \Vaimo\ComposerPatches\Patch\Definition\Value\Analyser();
25
        $this->itemBuilder = new \Vaimo\ComposerPatches\Patch\Definition\Exploder\ItemBuilder();
26
    }
27
28
    public function process($label, array $items, array $defaults = array())
29
    {
30
        $result = array();
31
32
        foreach ($items as $constraint => $source) {
33
            if (!$this->valueAnalyser->isConstraint($constraint)) {
34
                continue;
35
            }
36
37
            $result[] = $this->itemBuilder->createItem(
38
                $label,
39
                $defaults,
40
                array(
41
                    PatchDefinition::VERSION => $constraint,
42
                    PatchDefinition::SOURCE => $source
43
                )
44
            );
45
        }
46
47
        return $result;
48
    }
49
}
50