RootPatchComponent::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 6
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\DefinitionList\LoaderComponents;
7
8
use Vaimo\ComposerPatches\Patch\Definition as PatchDefinition;
9
10
class RootPatchComponent implements \Vaimo\ComposerPatches\Interfaces\DefinitionListLoaderComponentInterface
11
{
12
    /**
13
     * @var \Composer\Package\PackageInterface
14
     */
15
    private $package;
16
17
    /**
18
     * @var \Vaimo\ComposerPatches\Utils\PatchListUtils
19
     */
20
    private $patchListUtils;
21
22
    /**
23
     * @param \Composer\Package\PackageInterface $package
24
     */
25
    public function __construct(
26
        \Composer\Package\PackageInterface $package
27
    ) {
28
        $this->package = $package;
29
30
        $this->patchListUtils = new \Vaimo\ComposerPatches\Utils\PatchListUtils();
31
    }
32
33
    /**
34
     * @param array $patches
35
     * @param \Composer\Package\PackageInterface[] $packagesByName
36
     * @return array
37
     */
38
    public function process(array $patches, array $packagesByName)
39
    {
40
        $packageName = $this->package->getName();
41
42
        return $this->patchListUtils->applyDefinitionFilter(
43
            $patches,
44
            function ($patchData) use ($packageName) {
45
                if (!$patchData[PatchDefinition::LOCAL]) {
46
                    return true;
47
                }
48
49
                if ($packageName === $patchData[PatchDefinition::OWNER]) {
50
                    return true;
51
                }
52
53
                return false;
54
            }
55
        );
56
    }
57
}
58