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
2declare( strict_types = 1 );
3
4/**
5 * @private
6 */
7abstract class Less_Configurable {
8
9    /**
10     * Array of options
11     *
12     * @var array
13     */
14    protected $options = [];
15
16    /**
17     * Array of default options
18     *
19     * @var array
20     */
21    protected $defaultOptions = [];
22
23    /**
24     * @param array $options
25     */
26    public function setOptions( $options ) {
27        $options = array_intersect_key( $options, $this->defaultOptions );
28        $this->options = array_merge( $this->defaultOptions, $this->options, $options );
29    }
30
31    /**
32     * Get an option value by name
33     *
34     * If the option is empty or not set a NULL value will be returned.
35     *
36     * @param string $name
37     * @param mixed $default Default value if confiuration of $name is not present
38     * @return mixed
39     */
40    public function getOption( $name, $default = null ) {
41        if ( isset( $this->options[$name] ) ) {
42            return $this->options[$name];
43        }
44        return $default;
45    }
46
47    /**
48     * Set an option
49     *
50     * @param string $name
51     * @param mixed $value
52     */
53    public function setOption( $name, $value ) {
54        $this->options[$name] = $value;
55    }
56
57}