Processor::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 6
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;
7
8
use Composer\Repository\WritableRepositoryInterface as Repository;
9
10
use Vaimo\ComposerPatches\Repository\PatchesApplier as Applier;
11
use Vaimo\ComposerPatches\Patch\DefinitionList\Loader;
12
13
class Processor
14
{
15
    /**
16
     * @var \Vaimo\ComposerPatches\Logger
17
     */
18
    private $logger;
19
20
    /**
21
     * @var \Vaimo\ComposerPatches\Utils\PatchListUtils
22
     */
23
    private $patchListUtils;
24
25
    /**
26
     * @param \Vaimo\ComposerPatches\Logger $logger
27
     */
28
    public function __construct(
29
        \Vaimo\ComposerPatches\Logger $logger
30
    ) {
31
        $this->logger = $logger;
32
33
        $this->patchListUtils = new \Vaimo\ComposerPatches\Utils\PatchListUtils();
34
    }
35
36
    public function process(Repository $repository, Loader $loader, Applier $applier)
37
    {
38
        $this->logger->write('info', 'Processing patches configuration');
39
40
        $patches = $loader->loadFromPackagesRepository($repository);
41
42
        $loggerIndentation = $this->logger->push('-');
43
44
        try {
45
            $packagesUpdated = $applier->apply($repository, $patches);
46
        } catch (\Vaimo\ComposerPatches\Exceptions\PatchFailureException $exception) {
47
            $this->logger->reset($loggerIndentation);
48
49
            $this->patchListUtils->sanitizeFileSystem($patches);
50
51
            return false;
52
        }
53
54
        $this->logger->reset($loggerIndentation);
55
56
        $type = '';
57
        $message = 'Nothing to patch';
58
59
        if ($packagesUpdated) {
60
            $type = 'info';
61
            $message = 'Writing patch info to install file';
62
        }
63
64
        $this->logger->write($type, $message);
65
66
        $this->patchListUtils->sanitizeFileSystem($patches);
67
68
        return true;
69
    }
70
}
71