GroupVersionConfigComponent   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 23
dl 0
loc 51
rs 10
c 0
b 0
f 0
wmc 9

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
B shouldProcess() 0 24 7
A explode() 0 6 1
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 GroupVersionConfigComponent implements \Vaimo\ComposerPatches\Interfaces\DefinitionExploderComponentInterface
11
{
12
    /**
13
     * @var \Vaimo\ComposerPatches\Patch\Definition\Value\Analyser
14
     */
15
    private $valueAnalyser;
16
17
    /**
18
     * @var PatchDefinition\Constraint\Exploder
19
     */
20
    private $constraintExploder;
21
22
    public function __construct()
23
    {
24
        $this->valueAnalyser = new \Vaimo\ComposerPatches\Patch\Definition\Value\Analyser();
25
        $this->constraintExploder = new \Vaimo\ComposerPatches\Patch\Definition\Constraint\Exploder();
26
    }
27
28
    public function shouldProcess($label, $data)
29
    {
30
        if (!is_array($data)) {
31
            return false;
32
        }
33
34
        if (!isset($data[PatchDefinition::SOURCE])) {
35
            return false;
36
        }
37
38
        $source = $data[PatchDefinition::SOURCE];
39
40
        if (!is_array($source)) {
41
            return false;
42
        }
43
44
        $key = key($source);
45
        $value = reset($source);
46
47
        return $this->valueAnalyser->isConstraint($key)
48
            && !isset($data[PatchDefinition::DEPENDS], $data[PatchDefinition::VERSION])
49
            && (
50
                !is_array($value)
51
                || !isset($value[PatchDefinition::VERSION], $value[PatchDefinition::DEPENDS])
52
            );
53
    }
54
55
    public function explode($label, $data)
56
    {
57
        return $this->constraintExploder->process(
58
            $label,
59
            $data[PatchDefinition::SOURCE],
60
            array_diff_key($data, array(PatchDefinition::SOURCE => true))
61
        );
62
    }
63
}
64