Trait_RuleWithOptions   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 45
ccs 18
cts 18
cp 1
rs 10
c 0
b 0
f 0
wmc 7
lcom 1
cbo 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setOptions() 0 6 2
A getOption() 0 6 2
A getOptions() 0 16 3
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