GetOptionTrait::requireOption()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 7
c 0
b 0
f 0
ccs 4
cts 4
cp 1
rs 9.4285
cc 2
eloc 4
nc 2
nop 1
crap 2
1
<?php
2
/**
3
 * This file is part of graze/data-file
4
 *
5
 * Copyright (c) 2016 Nature Delivered Ltd. <https://www.graze.com>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 *
10
 * @license https://github.com/graze/data-file/blob/master/LICENSE.md
11
 * @link    https://github.com/graze/data-file
12
 */
13
14
namespace Graze\DataFile\Helper;
15
16
use InvalidArgumentException;
17
18
trait GetOptionTrait
19
{
20
    /**
21
     * @var array
22
     */
23
    protected $options = [];
24
25
    /**
26
     * Get an option value
27
     *
28
     * @param string $name
29
     * @param mixed  $default
30
     *
31
     * @return mixed
32
     */
33 86
    protected function getOption($name, $default)
34
    {
35 86
        return (isset($this->options[$name])) ? $this->options[$name] : $default;
36
    }
37
38
    /**
39
     * @param string $name
40
     *
41
     * @return mixed
42
     * @throws InvalidArgumentException
43
     */
44 16
    protected function requireOption($name)
45
    {
46 16
        if (!isset($this->options[$name])) {
47 5
            throw new InvalidArgumentException("The option: '$name' is required");
48
        }
49 12
        return $this->options[$name];
50
    }
51
}
52