Completed
Push — master ( 6695d4...9bc3b7 )
by Harry
04:41
created

GetOptionTrait   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 1
cbo 0
dl 0
loc 34
ccs 6
cts 6
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getOption() 0 4 2
A requireOption() 0 7 2
1
<?php
2
3
namespace Graze\DataFile\Helper;
4
5
use InvalidArgumentException;
6
7
trait GetOptionTrait
8
{
9
    /**
10
     * @var array
11
     */
12
    protected $options = [];
13
14
    /**
15
     * Get an option value
16
     *
17
     * @param string $name
18
     * @param mixed  $default
19
     *
20
     * @return mixed
21
     */
22 65
    protected function getOption($name, $default)
23
    {
24 65
        return (isset($this->options[$name])) ? $this->options[$name] : $default;
25
    }
26
27
    /**
28
     * @param string $name
29
     *
30
     * @return mixed
31
     * @throws InvalidArgumentException
32
     */
33 15
    protected function requireOption($name)
34
    {
35 15
        if (!isset($this->options[$name])) {
36 5
            throw new InvalidArgumentException("The option: '$name' is required");
37
        }
38 11
        return $this->options[$name];
39
    }
40
}
41