ValidatorComponent   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 19
dl 0
loc 39
rs 10
c 0
b 0
f 0
wmc 5

1 Method

Rating   Name   Duplication   Size   Complexity  
A process() 0 32 5
1
<?php
2
/**
3
 * Copyright © Vaimo Group. All rights reserved.
4
 * See LICENSE_VAIMO.txt for license details.
5
 */
6
namespace Vaimo\ComposerPatches\Patch\DefinitionList\LoaderComponents;
7
8
use Vaimo\ComposerPatches\Patch\Definition as PatchDefinition;
9
10
class ValidatorComponent implements \Vaimo\ComposerPatches\Interfaces\DefinitionListLoaderComponentInterface
11
{
12
    /**
13
     * @param array $patches
14
     * @param \Composer\Package\PackageInterface[] $packagesByName
15
     * @return array
16
     */
17
    public function process(array $patches, array $packagesByName)
18
    {
19
        $validatedPatches = array();
20
21
        foreach ($patches as $patchTarget => $packagePatches) {
22
            $validItems = array();
23
24
            foreach ($packagePatches as $data) {
25
                $path = $data[PatchDefinition::PATH];
26
27
                $uidSources = array(
28
                    file_exists($path) ? md5_file($path) : '',
29
                    md5($data['source']),
30
                    serialize($data[PatchDefinition::DEPENDS]),
31
                    serialize($data[PatchDefinition::TARGETS]),
32
                    serialize($data[PatchDefinition::CONFIG]),
33
                    $data[PatchDefinition::LABEL]
34
                );
35
36
                $data[PatchDefinition::HASH] = md5(implode('|', $uidSources));
37
38
                $validItems[] = $data;
39
            }
40
41
            if (!$validItems) {
42
                continue;
43
            }
44
45
            $validatedPatches[$patchTarget] = $validItems;
46
        }
47
48
        return $validatedPatches;
49
    }
50
}
51