DefaultValue   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 1
dl 0
loc 30
ccs 5
cts 5
cp 1
rs 10
c 0
b 0
f 0

2 Methods

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