Trait_RuleWithOptions::setOptions()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 1
dl 0
loc 6
ccs 5
cts 5
cp 1
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Trait_RuleWithOptions
4
 *
5
 * @package php-logical-filter
6
 * @author  Jean Claveau
7
 */
8
namespace JClaveau\LogicalFilter\Rule;
9
10
use       JClaveau\LogicalFilter\LogicalFilter;
11
12
/**
13
 * Options are defined in three levels:
14
 * + Current instance
15
 * + Context (e.g. the current running simplification)
16
 * + Default global value handled by LogicalFilter statically
17
 */
18
trait Trait_RuleWithOptions
19
{
20
    /** @var array $options */
21
    protected $options = [];
22
23
    /**
24
     */
25 103
    public function setOptions(array $options)
26
    {
27 103
        foreach ($options as $name => $value) {
28 103
            $this->options[$name] = $value;
29 103
        }
30 103
    }
31
32
    /**
33
     */
34 83
    public function getOption($name, array $contextual_options=[])
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
35
    {
36 83
        $options = $this->getOptions($contextual_options);
37
38 83
        return isset($options[$name]) ? $options[$name] : null;
39
    }
40
41
    /**
42
     * @param $contextual_options
43
     */
44 83
    public function getOptions(array $contextual_options=[])
45
    {
46 83
        $default_options = LogicalFilter::getDefaultOptions();
47
48 83
        $options = $default_options;
49
50 83
        foreach ($this->options as $name => $value) {
51 64
            $options[$name] = $value;
52 83
        }
53
54 83
        foreach ($contextual_options as $name => $value) {
55 52
            $options[$name] = $value;
56 83
        }
57
58 83
        return $options;
59
    }
60
61
    /**/
62
}
63