BaseComponent::extractValue()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 3
dl 0
loc 5
rs 10
c 0
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\NormalizerComponents;
7
8
use Vaimo\ComposerPatches\Patch\Definition as Patch;
9
10
class BaseComponent implements \Vaimo\ComposerPatches\Interfaces\DefinitionNormalizerComponentInterface
11
{
12
    public function normalize($target, $label, array $data, array $ownerConfig)
13
    {
14
        return array(
15
            Patch::ISSUE => $this->extractValue($data, Patch::ISSUE, false),
16
            Patch::LINK => $this->extractValue($data, Patch::LINK, false),
17
            Patch::LABEL => $this->extractValue($data, Patch::LABEL, $label),
18
            Patch::CWD => $this->extractValue($data, Patch::CWD, Patch::CWD_INSTALL),
19
            Patch::LEVEL => $this->extractValue($data, Patch::LEVEL),
20
            Patch::CATEGORY => $this->extractValue($data, Patch::CATEGORY),
21
            Patch::LOCAL => $this->extractValue($data, Patch::LOCAL, false),
22
            Patch::TARGETS => isset($data[Patch::TARGETS]) && $target === Patch::BUNDLE_TARGET
23
                ? $data[Patch::TARGETS]
24
                : array($target)
25
        );
26
    }
27
28
    private function extractValue(array $data, $key, $default = null)
29
    {
30
        return isset($data[$key])
31
            ? $data[$key]
32
            : $default;
33
    }
34
}
35