InvertedListResolver   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 69
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 25
dl 0
loc 69
rs 10
c 0
b 0
f 0
wmc 9

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A resolveInitialState() 0 25 5
A resolveRelevantPatches() 0 3 1
A resolvePatchesQueue() 0 8 2
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
class InvertedListResolver implements \Vaimo\ComposerPatches\Interfaces\ListResolverInterface
9
{
10
    /**
11
     * @var \Vaimo\ComposerPatches\Patch\DefinitionList\Transformer
12
     */
13
    private $patchListTransformer;
14
15
    /**
16
     * @var \Vaimo\ComposerPatches\Utils\PatchListUtils
17
     */
18
    private $patchListUtils;
19
20
    /**
21
     * @var \Vaimo\ComposerPatches\Interfaces\ListResolverInterface
22
     */
23
    private $baseResolver;
24
25
    /**
26
     * @param \Vaimo\ComposerPatches\Interfaces\ListResolverInterface $baseResolver
27
     */
28
    public function __construct(
29
        \Vaimo\ComposerPatches\Interfaces\ListResolverInterface $baseResolver
30
    ) {
31
        $this->baseResolver = $baseResolver;
32
33
        $this->patchListTransformer = new \Vaimo\ComposerPatches\Patch\DefinitionList\Transformer();
34
        $this->patchListUtils = new \Vaimo\ComposerPatches\Utils\PatchListUtils();
35
    }
36
37
    public function resolvePatchesQueue(array $patches)
38
    {
39
        $exclusions = $this->baseResolver->resolvePatchesQueue($patches);
40
41
        foreach ($exclusions as $target => $items) {
42
            $patches[$target] = array_diff_key($patches[$target], $items);
43
        }
44
        return $patches;
45
    }
46
47
    public function resolveRelevantPatches(array $patches, array $subset)
48
    {
49
        return $this->patchListUtils->intersectListsByPath($patches, $subset);
50
    }
51
52
    public function resolveInitialState(array $patches, array $state)
53
    {
54
        $patchesByTarget = $this->patchListTransformer->groupItemsByTarget($patches);
55
56
        $unpackedState = $this->patchListTransformer->createDetailedList($state);
57
58
        $updates = array();
59
60
        foreach ($patchesByTarget as $target => $group) {
61
            foreach ($group as $path => $item) {
62
                if (isset($unpackedState[$target][$path])) {
63
                    continue;
64
                }
65
66
                if (!isset($updates[$target])) {
67
                    $updates[$target] = array();
68
                }
69
70
                $updates[$target][$path] = $item;
71
            }
72
        }
73
74
        return $this->patchListUtils->mergeLists(
75
            $state,
76
            $this->patchListTransformer->createSimplifiedList($updates)
77
        );
78
    }
79
}
80