Completed
Push — master ( 8b8afe...5f2bbe )
by Greg
02:21
created

src/Config/Config.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
namespace Robo\Config;
3
4
use Consolidation\Config\Util\ConfigOverlay;
5
use Consolidation\Config\ConfigInterface;
6
7
class Config extends ConfigOverlay implements GlobalOptionDefaultValuesInterface
0 ignored issues
show
Deprecated Code introduced by
The interface Robo\Config\GlobalOptionDefaultValuesInterface has been deprecated with message: Use robo.yml instead robo.yml: options: simulated: false progress-delay: 2 etc.

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
8
{
9
    const PROGRESS_BAR_AUTO_DISPLAY_INTERVAL = 'options.progress-delay';
10
    const DEFAULT_PROGRESS_DELAY = 2;
11
    const SIMULATE = 'options.simulate';
12
13
    // Read-only configuration properties; changing these has no effect.
14
    const INTERACTIVE = 'options.interactive';
15
    const DECORATED = 'options.decorated';
16
17
    /**
18
     * Create a new configuration object, and initialize it with
19
     * the provided nested array containing configuration data.
20
     */
21
    public function __construct(array $data = null)
22
    {
23
        parent::__construct();
24
25
        $this->import($data);
26
        $this->defaults = $this->getGlobalOptionDefaultValues();
27
    }
28
29
    /**
30
     * {@inheritdoc}
31
     */
32
    public function import($data)
33
    {
34
        return $this->replace($data);
35
    }
36
37
    /**
38
     * {@inheritdoc}
39
     */
40
    public function replace($data)
41
    {
42
        $this->getContext(ConfigOverlay::DEFAULT_CONTEXT)->replace($data);
43
        return $this;
44
    }
45
46
    /**
47
     * {@inheritdoc}
48
     */
49
    public function combine($data)
50
    {
51
        $this->getContext(ConfigOverlay::DEFAULT_CONTEXT)->combine($data);
52
        return $this;
53
    }
54
55
    /**
56
     * Return an associative array containing all of the global configuration
57
     * options and their default values.
58
     *
59
     * @return array
60
     */
61
    public function getGlobalOptionDefaultValues()
62
    {
63
        $globalOptions =
64
        [
65
            self::PROGRESS_BAR_AUTO_DISPLAY_INTERVAL => self::DEFAULT_PROGRESS_DELAY,
66
            self::SIMULATE => false,
67
        ];
68
        return $this->trimPrefixFromGlobalOptions($globalOptions);
69
    }
70
71
    /**
72
     * Remove the 'options.' prefix from the global options list.
73
     */
74
    protected function trimPrefixFromGlobalOptions($globalOptions)
75
    {
76
        $result = [];
77
        foreach ($globalOptions as $option => $value) {
78
            $option = str_replace('options.', '', $option);
79
            $result[$option] = $value;
80
        }
81
        return $result;
82
    }
83
84
    /**
85
     * @deprecated Use $config->get(Config::SIMULATE)
86
     *
87
     * @return bool
88
     */
89
    public function isSimulated()
90
    {
91
        return $this->get(self::SIMULATE);
92
    }
93
94
    /**
95
     * @deprecated Use $config->set(Config::SIMULATE, true)
96
     *
97
     * @param bool $simulated
98
     *
99
     * @return $this
100
     */
101
    public function setSimulated($simulated = true)
102
    {
103
        return $this->set(self::SIMULATE, $simulated);
104
    }
105
106
    /**
107
     * @deprecated Use $config->get(Config::INTERACTIVE)
108
     *
109
     * @return bool
110
     */
111
    public function isInteractive()
112
    {
113
        return $this->get(self::INTERACTIVE);
114
    }
115
116
    /**
117
     * @deprecated Use $config->set(Config::INTERACTIVE, true)
118
     *
119
     * @param bool $interactive
120
     *
121
     * @return $this
122
     */
123
    public function setInteractive($interactive = true)
124
    {
125
        return $this->set(self::INTERACTIVE, $interactive);
126
    }
127
128
    /**
129
     * @deprecated Use $config->get(Config::DECORATED)
130
     *
131
     * @return bool
132
     */
133
    public function isDecorated()
134
    {
135
        return $this->get(self::DECORATED);
136
    }
137
138
    /**
139
     * @deprecated Use $config->set(Config::DECORATED, true)
140
     *
141
     * @param bool $decorated
142
     *
143
     * @return $this
144
     */
145
    public function setDecorated($decorated = true)
146
    {
147
        return $this->set(self::DECORATED, $decorated);
148
    }
149
150
    /**
151
     * @deprecated Use $config->set(Config::PROGRESS_BAR_AUTO_DISPLAY_INTERVAL, $interval)
152
     *
153
     * @param int $interval
154
     *
155
     * @return $this
156
     */
157
    public function setProgressBarAutoDisplayInterval($interval)
158
    {
159
        return $this->set(self::PROGRESS_BAR_AUTO_DISPLAY_INTERVAL, $interval);
160
    }
161
}
162