DefaultValue::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Habu\ComposerScriptUtils\Configuration\Handler;
4
5
use Habu\ComposerScriptUtils\Configuration\AbstractConfigurationHandler;
6
7
/**
8
 * DefaultValue configuration handler.
9
 *
10
 * This handler lets you define a default value to be returned for a configuration
11
 * key defined within your default configuration definition, that's not present in
12
 * the actual configuration.
13
 *
14
 * @author Ruben Knol <[email protected]>
15
 */
16
class DefaultValue extends AbstractConfigurationHandler
17
{
18
    /**
19
     * @var mixed
20
     */
21
    private $defaultValue;
22
23
    /**
24
     * DefaultValue constructor.
25
     *
26
     * @param mixed $defaultValue
27
     */
28 7
    public function __construct($defaultValue)
29
    {
30 7
        $this->defaultValue = $defaultValue;
31 7
    }
32
33
    /**
34
     * Return either the actual value (if it's not empty) or the
35
     * defined default value.
36
     *
37
     * @param mixed $value
38
     *
39
     * @return mixed
40
     */
41 2
    public function get($value)
42
    {
43 2
        return !empty($value) || $value === '0' ? $value : $this->defaultValue;
44
    }
45
}
46