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

ConfigureTrait   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 45
Duplicated Lines 31.11 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 88.24%

Importance

Changes 0
Metric Value
dl 14
loc 45
ccs 15
cts 17
cp 0.8824
rs 10
c 0
b 0
f 0
wmc 6
lcom 1
cbo 1

1 Method

Rating   Name   Duplication   Size   Complexity  
B configure() 14 25 6

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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