Completed
Push — master ( 20b8af...e1bd53 )
by Mikael
01:59
created

ConfigureTrait::configure()   B

Complexity

Conditions 6
Paths 8

Size

Total Lines 25
Code Lines 15

Duplication

Lines 14
Ratio 56 %

Code Coverage

Tests 15
CRAP Score 6.0585

Importance

Changes 0
Metric Value
cc 6
eloc 15
nc 8
nop 1
dl 14
loc 25
ccs 15
cts 17
cp 0.8824
crap 6.0585
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 4
    public function configure($what)
29
    {
30 4
        if (is_array($what)) {
31 2
            $this->config = $what;
32 2
            return $this;
33
        }
34
35 2 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 2
            $path = ANAX_APP_PATH . "/config/$what";
37 2
            if (is_readable($path)) {
38 1
                $this->config = require $path;
39 1
                return $this;
40
            }
41 1
        }
42
43 1 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 1
            $path = ANAX_INSTALL_PATH . "/config/$what";
45 1
            if (is_readable($path)) {
46
                $this->config = require $path;
47
                return $this;
48
            }
49 1
        }
50
51 1
        throw new ConfigurationException("Configure item '$what' is not an array nor a readable file.");
52
    }
53
}
54