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

UrlComponent   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 22
rs 10
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A normalize() 0 10 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\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