Completed
Pull Request — master (#17)
by
unknown
02:55
created

TConfigure::configure()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 14
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 3.243

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
dl 0
loc 14
rs 9.4285
ccs 7
cts 10
cp 0.7
cc 3
eloc 10
nc 3
nop 1
crap 3.243
1
<?php
2
3
namespace Anax;
4
5
/**
6
 * Trait implementing reading from config-file and storing options in $this->config.
7
 *
8
 */
9
trait TConfigure
10
{
11
12
    /**
13
     * Properties
14
     *
15
     */
16
    private $config = [];  // Store all config as an array
17
18
19
20
    /**
21
     * Read configuration from file or array'.
22
     *
23
     * @param array/string $what is an array with key/value config options or a file
0 ignored issues
show
Documentation introduced by
The doc-type array/string could not be parsed: Unknown type name "array/string" at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
24
     *      to be included which returns such an array.
25
     * @return $this for chaining.
26
     */
27 2
    public function configure($what)
28
    {
29 2
        if (is_array($what)) {
30
            $options = $what;
31 2
        } elseif (is_readable($what)) {
32 2
            $options = include $what;
33 2
        } else {
34
            throw new Exception("Configure item '" . htmlentities($what)
35
                . "' is not an array nor a readable file.");
36
        }
37
38 2
        $this->config = array_merge($this->config, $options);
39 2
        return $this->config;
40
    }
41
}
42