Required::get()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 4
nc 2
nop 1
crap 3
1
<?php
2
3
namespace Habu\ComposerScriptUtils\Configuration\Handler;
4
5
use Habu\ComposerScriptUtils\Configuration\AbstractConfigurationHandler;
6
7
/**
8
 * Required configuration handler.
9
 *
10
 * This handler will throw an exception if a key defined within your default configuration
11
 * definition is not found upon accessing the key in the actual configuration.
12
 *
13
 * @author Ruben Knol <[email protected]>
14
 */
15
class Required extends AbstractConfigurationHandler
16
{
17
    /**
18
     * Return the value or throw an exception if the value is empty.
19
     *
20
     * @param mixed $value
21
     *
22
     * @return mixed
23
     */
24 7
    public function get($value)
25
    {
26 7
        if (empty($value) && $value !== '0') {
27 5
            throw new \InvalidArgumentException(sprintf("Configuration key %s is required.", $this->getKey()));
28
        }
29
30 2
        return $value;
31
    }
32
}
33