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

TConfigure   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 70%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 3
c 3
b 0
f 0
lcom 1
cbo 1
dl 0
loc 33
rs 10
ccs 7
cts 10
cp 0.7

1 Method

Rating   Name   Duplication   Size   Complexity  
A configure() 0 14 3
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