Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
83.33% covered (warning)
83.33%
5 / 6
66.67% covered (warning)
66.67%
2 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
Less_Configurable
83.33% covered (warning)
83.33%
5 / 6
66.67% covered (warning)
66.67%
2 / 3
4.07
0.00% covered (danger)
0.00%
0 / 1
 setOptions
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getOption
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
2
 setOption
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2/**
3 * @private
4 */
5abstract class Less_Configurable {
6
7    /**
8     * Array of options
9     *
10     * @var array
11     */
12    protected $options = [];
13
14    /**
15     * Array of default options
16     *
17     * @var array
18     */
19    protected $defaultOptions = [];
20
21    /**
22     * @param array $options
23     */
24    public function setOptions( $options ) {
25        $options = array_intersect_key( $options, $this->defaultOptions );
26        $this->options = array_merge( $this->defaultOptions, $this->options, $options );
27    }
28
29    /**
30     * Get an option value by name
31     *
32     * If the option is empty or not set a NULL value will be returned.
33     *
34     * @param string $name
35     * @param mixed $default Default value if confiuration of $name is not present
36     * @return mixed
37     */
38    public function getOption( $name, $default = null ) {
39        if ( isset( $this->options[$name] ) ) {
40            return $this->options[$name];
41        }
42        return $default;
43    }
44
45    /**
46     * Set an option
47     *
48     * @param string $name
49     * @param mixed $value
50     */
51    public function setOption( $name, $value ) {
52        $this->options[$name] = $value;
53    }
54
55}