LabelVersionConfigComponent   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 16
c 0
b 0
f 0
dl 0
loc 41
rs 10
wmc 8

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A shouldProcess() 0 12 3
A explode() 0 15 4
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\ExploderComponents;
7
8
use Vaimo\ComposerPatches\Patch\Definition as PatchDefinition;
9
10
class LabelVersionConfigComponent implements \Vaimo\ComposerPatches\Interfaces\DefinitionExploderComponentInterface
11
{
12
    /**
13
     * @var \Vaimo\ComposerPatches\Patch\Definition\Value\Analyser
14
     */
15
    private $valueAnalyser;
16
17
    public function __construct()
18
    {
19
        $this->valueAnalyser = new \Vaimo\ComposerPatches\Patch\Definition\Value\Analyser();
20
    }
21
22
    public function shouldProcess($label, $data)
23
    {
24
        if (!is_array($data)) {
25
            return $this->valueAnalyser->isConstraint($data);
26
        }
27
28
        $dataKeys = array_keys($data);
29
        if (in_array(PatchDefinition::SOURCE, $dataKeys)) {
30
            return false;
31
        }
32
33
        return $this->valueAnalyser->isConstraint(reset($data));
34
    }
35
36
    public function explode($label, $data)
37
    {
38
        $items = array();
39
40
        $versions = is_array($data) ? $data : array($data);
41
42
        foreach ($versions as $version) {
43
            if (!$this->valueAnalyser->isConstraint($version)) {
44
                continue;
45
            }
46
47
            $items[] = array($label, array(PatchDefinition::VERSION => $version));
48
        }
49
50
        return $items;
51
    }
52
}
53