PatcherStateManager   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 22
c 0
b 0
f 0
dl 0
loc 52
rs 10
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A registerAppliedPatches() 0 34 4
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\Managers;
7
8
use Composer\Repository\WritableRepositoryInterface;
9
10
use Vaimo\ComposerPatches\Config as PluginConfig;
11
use Vaimo\ComposerPatches\Composer\Constraint;
12
13
class PatcherStateManager
14
{
15
    /**
16
     * @var \Vaimo\ComposerPatches\Patch\DefinitionList\Transformer
17
     */
18
    private $patchListTransformer;
19
20
    /**
21
     * @var \Vaimo\ComposerPatches\Utils\PackageUtils
22
     */
23
    private $packageUtils;
24
25
    public function __construct()
26
    {
27
        $this->patchListTransformer = new \Vaimo\ComposerPatches\Patch\DefinitionList\Transformer();
28
        $this->packageUtils = new \Vaimo\ComposerPatches\Utils\PackageUtils();
29
    }
30
31
    public function registerAppliedPatches(WritableRepositoryInterface $repository, array $patches)
32
    {
33
        $packages = array();
34
35
        $patchQueue = $this->patchListTransformer->createSimplifiedList(
36
            array($patches)
37
        );
38
39
        foreach ($patchQueue as $target => $items) {
40
            $package = $repository->findPackage($target, Constraint::ANY);
41
42
            if (!$package) {
43
                continue;
44
            }
45
46
            /** @var \Composer\Package\CompletePackage $package */
47
            $package = $this->packageUtils->getRealPackage($package);
48
49
            $info = array_replace_recursive(
50
                $package->getExtra(),
51
                array(PluginConfig::APPLIED_FLAG => $items)
52
            );
53
54
            $package->setExtra($info);
55
56
            $packages[] = $package;
57
        }
58
59
        foreach ($packages as $package) {
60
            $extra = $package->getExtra();
61
62
            ksort($extra[PluginConfig::APPLIED_FLAG]);
63
64
            $package->setExtra($extra);
65
        }
66
    }
67
}
68