ChangesListResolver   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A resolvePatchesQueue() 0 3 1
A resolveInitialState() 0 32 6
A resolveRelevantPatches() 0 3 1
A __construct() 0 6 1
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