PathNormalizerComponent   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 14
dl 0
loc 43
rs 10
c 0
b 0
f 0
wmc 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
A process() 0 22 5
A __construct() 0 4 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\DefinitionList\LoaderComponents;
7
8
use Vaimo\ComposerPatches\Patch\Definition as PatchDefinition;
9
10
class PathNormalizerComponent implements \Vaimo\ComposerPatches\Interfaces\DefinitionListLoaderComponentInterface
11
{
12
    /**
13
     * @var \Vaimo\ComposerPatches\Package\InfoResolver
14
     */
15
    private $packageInfoResolver;
16
17
    /**
18
     * @param \Vaimo\ComposerPatches\Package\InfoResolver $packageInfoResolver
19
     */
20
    public function __construct(
21
        \Vaimo\ComposerPatches\Package\InfoResolver $packageInfoResolver
22
    ) {
23
        $this->packageInfoResolver = $packageInfoResolver;
24
    }
25
26
    /**
27
     * @param array $patches
28
     * @param \Composer\Package\PackageInterface[] $packagesByName
29
     * @return array
30
     */
31
    public function process(array $patches, array $packagesByName)
32
    {
33
        foreach ($patches as &$packagePatches) {
34
            foreach ($packagePatches as &$data) {
35
                if ($data[PatchDefinition::URL]) {
36
                    continue;
37
                }
38
39
                $patchOwner = $data[PatchDefinition::OWNER];
40
41
                if (!isset($packagesByName[$patchOwner])) {
42
                    continue;
43
                }
44
45
                $ownerPath = $this->packageInfoResolver->getSourcePath($packagesByName[$patchOwner]);
46
                $path = $data[PatchDefinition::SOURCE];
47
48
                $data[PatchDefinition::PATH] = $ownerPath . DIRECTORY_SEPARATOR . $path;
49
            }
50
        }
51
52
        return $patches;
53
    }
54
}
55