Config::__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;
7
8
class Config
9
{
10
    const PACKAGE_CONFIG_FILE = 'composer.json';
11
    const CONFIG_ROOT = 'extra';
12
13
    const PREFIX = 'patches-';
14
15
    const DEFINITIONS_LIST = 'patches';
16
    const DEFINITIONS_FILE = 'patches-file';
17
    const DEFINITIONS_SEARCH = 'patches-search';
18
19
    const DEV_DEFINITIONS_LIST = 'patches-dev';
20
    const DEV_DEFINITIONS_FILE = 'patches-file-dev';
21
    const DEV_DEFINITIONS_SEARCH = 'patches-search-dev';
22
23
    const EXCLUDED_PATCHES = 'patches-exclude';
24
25
    const APPLIED_FLAG = 'patches_applied';
26
27
    const PATCHER_CONFIG_ROOT = 'patcher';
28
    const PATCHER_APPLIERS = 'appliers';
29
    const PATCHER_OPERATIONS = 'operations';
30
    const PATCHER_SANITY = 'operations:sanity';
31
    const PATCHER_FAILURES = 'operation-failures';
32
    const PATCHER_SEQUENCE = 'sequence';
33
    const PATCHER_LEVELS = 'levels';
34
    const PATCHER_SOURCES = 'sources';
35
    const PATCHER_SECURE_HTTP = 'secure-http';
36
    const PATCHER_GRACEFUL = 'graceful';
37
38
    const OS_DEFAULT = 'default';
39
    const APPLIER_DEFAULT = 'DEFAULT';
40
41
    const PATCHER_FORCE_RESET = 'force-reset';
42
43
    const PATCHER_TARGETS = 'depends';
44
    const PATCHER_BASE_PATHS = 'paths';
45
    const PATCHER_FILE = 'file';
46
    const PATCHER_FILE_DEV = 'file-dev';
47
    const PATCHER_SEARCH = 'search';
48
    const PATCHES_IGNORE = 'ignore';
49
    const PATCHER_SEARCH_DEV = 'search-dev';
50
51
    const PATCHES_DEPENDS = 'patches-depend';
52
    const PATCHES_BASE = 'patches-base';
53
54
    const PATCHES_BASE_DEFAULT = 'default';
55
56
    const PATCHES_CONFIG_DEFAULT = 'default';
57
58
    const PATCHER_ARG_LEVEL = 'level';
59
    const PATCHER_ARG_FILE = 'file';
60
    const PATCHER_ARG_CWD = 'cwd';
61
62
    const PATCH_FILE_REGEX_MATCHER = '.+\.patch$';
63
64
    const PATCHER_FROM_SOURCE = 'from-source';
65
    const PATCHER_FORCE_REAPPLY = 'force-reapply';
66
    /**
67
     * @var array
68
     */
69
    private $config;
70
71
    /**
72
     * @var \Vaimo\ComposerPatches\Utils\ConfigUtils
73
     */
74
    private $configUtils;
75
76
    /**
77
     * @param array $config
78
     */
79
    public function __construct(
80
        array $config
81
    ) {
82
        $this->config = $config;
83
84
        $this->configUtils = new \Vaimo\ComposerPatches\Utils\ConfigUtils();
85
    }
86
87
    public function shouldExitOnFirstFailure()
88
    {
89
        return !$this->config[self::PATCHER_GRACEFUL];
90
    }
91
92
    public function shouldPreferOwnerPackageConfig()
93
    {
94
        return (bool)$this->config[self::PATCHER_FROM_SOURCE];
95
    }
96
97
    public function shouldForcePackageReset()
98
    {
99
        return $this->config[self::PATCHER_FORCE_RESET] || (bool)getenv(Environment::FORCE_RESET);
100
    }
101
102
    public function shouldResetEverything()
103
    {
104
        return (bool)$this->config[self::PATCHER_FORCE_REAPPLY];
105
    }
106
107
    public function getPatcherConfig(array $overrides = array())
108
    {
109
        $config = $this->configUtils->mergeApplierConfig($this->config, $overrides);
110
111
        return $this->configUtils->sortApplierConfig($config);
112
    }
113
}
114