Processor   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 23
c 3
b 0
f 0
dl 0
loc 56
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A process() 0 33 3
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