Completed
Push — master ( 4dd9bb...1d5a37 )
by Allan
03:20 queued 12s
created

UrlComponent::normalize()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 6
c 1
b 0
f 0
nc 4
nop 4
dl 0
loc 10
rs 10
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 PatchDefinition;
9
10
class UrlComponent implements \Vaimo\ComposerPatches\Interfaces\DefinitionNormalizerComponentInterface
11
{
12
    /**
13
     * @var \Vaimo\ComposerPatches\Utils\DataUtils
14
     */
15
    private $dataUtils;
16
    
17
    public function __construct()
18
    {
19
        $this->dataUtils = new \Vaimo\ComposerPatches\Utils\DataUtils();
20
    }
21
22
    public function normalize($target, $label, array $data, array $ownerConfig)
23
    {
24
        $source = $data[PatchDefinition::SOURCE];
25
26
        $pathInfo = parse_url($source);
27
        $includesScheme = isset($pathInfo['scheme']) && $pathInfo['scheme'];
28
        
29
        return array(
30
            PatchDefinition::URL => $includesScheme ? $source : false,
31
            PatchDefinition::CHECKSUM => $this->dataUtils->extractValue($data, 'sha1', '') ?: ''
32
        );
33
    }
34
}
35