Test Failed
Push — master ( 491630...20b8af )
by Mikael
01:52
created

ConfigureTrait::configure()   B

Complexity

Conditions 6
Paths 8

Size

Total Lines 25
Code Lines 15

Duplication

Lines 14
Ratio 56 %

Code Coverage

Tests 7
CRAP Score 9.5384

Importance

Changes 0
Metric Value
cc 6
eloc 15
nc 8
nop 1
dl 14
loc 25
ccs 7
cts 13
cp 0.5385
crap 9.5384
rs 8.439
c 0
b 0
f 0
1
<?php
2
3
namespace Anax\Common;
4
5
/**
6
 * Trait implementing reading from config-file and storing options in
7
 * $this->config.
8
 */
9
trait ConfigureTrait
10
{
11
    /** @var [] $config store the configuration in this array.   */
0 ignored issues
show
Documentation introduced by
The doc-type [] could not be parsed: Unknown type name "" 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...
12
    private $config = [];
13
14
15
16
    /**
17
     * Read configuration from file or array, if a file, first check in
18
     * ANAX_APP_PATH/config and then in ANAX_INSTALL_PATH/config.
19
     *
20
     * @param []|string $what is an array with key/value config options
0 ignored issues
show
Documentation introduced by
The doc-type []|string could not be parsed: Unknown type name "" 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...
21
     *                        or a file to be included which returns such
22
     *                        an array.
23
     *
24
     * @throws Exception when argument if not a filer nor an array.
25
     *
26
     * @return self for chaining.
27
     */
28 1
    public function configure($what)
29
    {
30 1
        if (is_array($what)) {
31 1
            $this->config = $what;
32
            return $this;
33 1
        }
34
35 1 View Code Duplication
        if (defined("ANAX_APP_PATH")) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
36
            $path = ANAX_APP_PATH . "/config/$what";
37 1
            if (is_readable($path)) {
38
                $this->config = require $path;
39
                return $this;
40 1
            }
41
        }
42
43 View Code Duplication
        if (defined("ANAX_INSTALL_PATH")) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
44
            $path = ANAX_INSTALL_PATH . "/config/$what";
45
            if (is_readable($path)) {
46
                $this->config = require $path;
47
                return $this;
48
            }
49
        }
50
51
        throw new ConfigurationException("Configure item '$what' is not an array nor a readable file.");
52
    }
53
}
54