ConfigurableTrait   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 1
dl 0
loc 28
rs 10
c 0
b 0
f 0
ccs 13
cts 13
cp 1

1 Method

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