VersionRangesConfigComponent   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
eloc 17
c 1
b 1
f 0
dl 0
loc 43
rs 10
wmc 8

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A shouldProcess() 0 17 5
A explode() 0 12 2
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 VersionRangesConfigComponent 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 false;
26
        }
27
28
        if (!isset($data[PatchDefinition::VERSION]) || isset($data[PatchDefinition::DEPENDS])) {
29
            return false;
30
        }
31
32
        $version = $data[PatchDefinition::VERSION];
33
34
        if (!is_array($version)) {
35
            return false;
36
        }
37
38
        return $this->valueAnalyser->isConstraint(key($version));
39
    }
40
41
    public function explode($label, $data)
42
    {
43
        $items = array();
44
45
        foreach ($data[PatchDefinition::VERSION] as $version) {
46
            $items[] = array(
47
                $label,
48
                array_replace($data, array(PatchDefinition::VERSION => $version))
49
            );
50
        }
51
52
        return $items;
53
    }
54
}
55