ChangesListResolver::resolvePatchesQueue()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
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\Repository\PatchesApplier\ListResolvers;
7
8
use Vaimo\ComposerPatches\Patch\Definition as Patch;
9
10
class ChangesListResolver implements \Vaimo\ComposerPatches\Interfaces\ListResolverInterface
11
{
12
    /**
13
     * @var \Vaimo\ComposerPatches\Interfaces\ListResolverInterface
14
     */
15
    private $baseResolver;
16
17
    /**
18
     * @var \Vaimo\ComposerPatches\Patch\DefinitionList\Transformer
19
     */
20
    private $patchListTransformer;
21
22
    /**
23
     * @param \Vaimo\ComposerPatches\Interfaces\ListResolverInterface $baseResolver
24
     */
25
    public function __construct(
26
        \Vaimo\ComposerPatches\Interfaces\ListResolverInterface $baseResolver
27
    ) {
28
        $this->baseResolver = $baseResolver;
29
30
        $this->patchListTransformer = new \Vaimo\ComposerPatches\Patch\DefinitionList\Transformer();
31
    }
32
33
    public function resolvePatchesQueue(array $patches)
34
    {
35
        return $this->baseResolver->resolvePatchesQueue($patches);
36
    }
37
38
    public function resolveRelevantPatches(array $patches, array $subset)
39
    {
40
        return $this->baseResolver->resolveRelevantPatches($patches, $subset);
41
    }
42
43
    public function resolveInitialState(array $patches, array $state)
44
    {
45
        $patchesByTarget = $this->patchListTransformer->groupItemsByTarget($patches);
46
        $unpackedState = $this->patchListTransformer->createDetailedList($state);
47
48
        $matches = array();
49
50
        foreach ($patchesByTarget as $target => $items) {
51
            foreach ($items as $path => $item) {
52
                if (!isset($unpackedState[$target][$path])) {
53
                    continue;
54
                }
55
56
                $stateItem = $unpackedState[$target][$path];
57
58
                if ($stateItem[Patch::HASH] === $item[Patch::HASH]) {
59
                    continue;
60
                }
61
62
                unset($unpackedState[$target][$path]);
63
64
                if (!isset($matches[$target])) {
65
                    $matches[$target] = array();
66
                }
67
68
                $matches[$target][$path] = $item;
69
            }
70
        }
71
72
        $state = $this->patchListTransformer->createSimplifiedList($unpackedState);
73
74
        return $this->baseResolver->resolveInitialState($matches, $state);
75
    }
76
}
77