ConfigurableTrait::setOptions()   A
last analyzed

Complexity

Conditions 5
Paths 5

Size

Total Lines 20

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 5

Importance

Changes 0
Metric Value
dl 0
loc 20
rs 9.2888
c 0
b 0
f 0
ccs 13
cts 13
cp 1
cc 5
nc 5
nop 2
crap 5
1
<?php
2
/**
3
 * @author Dmitry Gladyshev <[email protected]>
4
 */
5
6
namespace Rucaptcha;
7
8
use Rucaptcha\Exception\InvalidArgumentException;
9
10
trait ConfigurableTrait
11
{
12
    /**
13
     * @param array $options
14
     * @param bool $ignoreMissingOptions
15
     * @throws InvalidArgumentException
16
     */
17 28
    public function setOptions(array $options, $ignoreMissingOptions = false)
18
    {
19 28
        foreach ($options as $option => $value) {
20 3
            $setter = 'set' . ucfirst($option);
21
22 3
            if (method_exists($this, $setter)) {
23 1
                $this->$setter($value);
24 1
                continue;
25
            }
26
27 2
            if (property_exists($this, $option)) {
28 1
                $this->$option = $value;
29 1
                continue;
30
            }
31
32 1
            if (!$ignoreMissingOptions) {
33 1
                throw new InvalidArgumentException("Property `{$option}` not found in class `" . __CLASS__ . "`.");
34
            }
35 27
        }
36 27
    }
37
}
38