Required   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A get() 0 8 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