Passed
Push — master ( 1f0b7e...5bb3b6 )
by Allan
02:45
created

Bootstrap::applyPatchesWithConfig()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 7
nc 1
nop 2
dl 0
loc 13
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;
7
8
use Vaimo\ComposerPatches\Config as PluginConfig;
9
use Vaimo\ComposerPatches\Factories;
10
11
class Bootstrap
12
{
13
    /**
14
     * @var \Composer\Composer
15
     */
16
    private $composer;
17
18
    /**
19
     * @var \Vaimo\ComposerPatches\Factories\ConfigFactory
20
     */
21
    private $configFactory;
22
23
    /**
24
     * @var \Vaimo\ComposerPatches\Factories\PatchesLoaderFactory
25
     */
26
    private $loaderFactory;
27
28
    /**
29
     * @var \Vaimo\ComposerPatches\Factories\PatchesApplierFactory
30
     */
31
    private $applierFactory;
32
33
    /**
34
     * @var \Vaimo\ComposerPatches\Repository\Processor
35
     */
36
    private $repositoryProcessor;
37
38
    /**
39
     * @var \Vaimo\ComposerPatches\Patch\DefinitionList\Loader\ComponentPool
40
     */
41
    private $loaderComponents;
42
43
    /**
44
     * @var \Vaimo\ComposerPatches\Interfaces\ListResolverInterface
45
     */
46
    private $listResolver;
47
48
    /**
49
     * @var \Vaimo\ComposerPatches\Strategies\OutputStrategy
50
     */
51
    private $outputStrategy;
52
53
    /**
54
     * @param \Composer\Composer $composer
55
     * @param \Composer\IO\IOInterface $cliIO
56
     * @param \Vaimo\ComposerPatches\Factories\ConfigFactory $configFactory
57
     * @param \Vaimo\ComposerPatches\Interfaces\ListResolverInterface $listResolver
58
     * @param \Vaimo\ComposerPatches\Strategies\OutputStrategy $outputStrategy
59
     */
60
    public function __construct(
61
        \Composer\Composer $composer,
62
        \Composer\IO\IOInterface $cliIO,
63
        \Vaimo\ComposerPatches\Factories\ConfigFactory $configFactory,
64
        \Vaimo\ComposerPatches\Interfaces\ListResolverInterface $listResolver = null,
65
        \Vaimo\ComposerPatches\Strategies\OutputStrategy $outputStrategy = null
66
    ) {
67
        $this->composer = $composer;
68
        $this->configFactory = $configFactory;
69
        
70
        $logger = new \Vaimo\ComposerPatches\Logger($cliIO);
71
72
        $this->listResolver = $listResolver;
73
        
74
        $this->outputStrategy = $outputStrategy;
75
        
76
        $this->loaderComponents = new \Vaimo\ComposerPatches\Patch\DefinitionList\Loader\ComponentPool(
77
            $composer,
78
            $cliIO
79
        );
80
81
        $this->loaderFactory = new Factories\PatchesLoaderFactory($composer);
82
83
        $this->applierFactory = new Factories\PatchesApplierFactory($composer, $logger);
84
        
85
        $this->repositoryProcessor = new \Vaimo\ComposerPatches\Repository\Processor($logger);
86
    }
87
    
88
    public function applyPatches($devMode = false)
89
    {
90
        $this->applyPatchesWithConfig(
91
            $this->configFactory->create(),
92
            $devMode
93
        );
94
    }
95
96
    public function stripPatches($devMode = false)
97
    {
98
        $configSources = array(
99
            array(\Vaimo\ComposerPatches\Config::PATCHER_SOURCES => false)
100
        );
101
        
102
        $this->applyPatchesWithConfig(
103
            $this->configFactory->create($configSources),
104
            $devMode
105
        );
106
    }
107
108
    private function applyPatchesWithConfig(PluginConfig $config, $devMode = false)
109
    {
110
        $repository = $this->composer->getRepositoryManager()->getLocalRepository();
111
112
        $patchesLoader = $this->loaderFactory->create($this->loaderComponents, $config, $devMode);
113
        
114
        $patchesApplier = $this->applierFactory->create(
115
            $config,
116
            $this->listResolver,
117
            $this->outputStrategy
118
        );
119
120
        $this->repositoryProcessor->process($repository, $patchesLoader, $patchesApplier);
121
    }
122
}
123