Test Failed
Branch v5 (12d602)
by Alexey
04:51
created

ConfigTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 85
Duplicated Lines 29.41 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
dl 25
loc 85
rs 10
c 0
b 0
f 0
wmc 5
lcom 0
cbo 2

5 Methods

Rating   Name   Duplication   Size   Complexity  
A testSystem() 0 18 1
A testCustom() 0 14 1
A testApp() 12 12 1
A testShare() 0 21 1
A testModule() 13 13 1

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
use  Inji\Config;
0 ignored issues
show
Coding Style introduced by
There must be a single space after the USE keyword
Loading history...
4
5
class ConfigTest extends \PHPUnit\Framework\TestCase {
6
7
    public function testSystem() {
8
        $config = Config::system(true);
9
        $this->assertNotEmpty($config);
10
11
        $config = Config::system();
12
        $this->assertNotEmpty($config);
13
14
        $time = time();
15
16
        $config['test'] = $time;
17
        Config::save('system', $config);
18
19
        $config = Config::system(true);
20
        $this->assertEquals($time, $config['test']);
21
22
        $config = \Inji\Config::system(true, 'notExist');
23
        $this->assertEmpty($config);
24
    }
25
26
    public function testCustom() {
27
        $temp = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'testConf.php';
28
        $time = time();
29
30
        Config::save($temp, ['test' => $time]);
31
        $config = Config::custom($temp, true);
32
        $this->assertEquals(['test' => $time], $config);
33
34
        $config = Config::custom($temp);
35
        $this->assertEquals(["test" => $time], $config);
36
37
        $config = Config::custom('notExist');
38
        $this->assertEmpty($config);
39
    }
40
41 View Code Duplication
    public function testApp() {
42
        $time = time();
43
        Config::save('app', ['test' => $time]);
44
        $config = Config::app(false, true);
0 ignored issues
show
Documentation introduced by
false is of type boolean, but the function expects a object<Inji\App>|null.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
45
        $this->assertEquals(["test" => $time], $config);
46
47
        $config = Config::app();
48
        $this->assertEquals(["test" => $time], $config);
49
50
        $config = Config::app(new \Inji\App(['path' => 'notExits']));
51
        $this->assertEmpty($config);
52
    }
53
54
    public function testShare() {
55
        $time = time();
56
        Config::save('share', ['test' => $time]);
57
58
        $config = Config::share('', true);
59
        $this->assertEquals(["test" => $time], $config);
60
61
        $config = Config::share();
62
        $this->assertEquals(["test" => $time], $config);
63
64
        Config::save('share', ['test' => $time], 'TestModule');
65
66
        $config = Config::share('TestModule', true);
67
        $this->assertEquals(["test" => $time], $config);
68
69
        $config = Config::share('TestModule');
70
        $this->assertEquals(["test" => $time], $config);
71
72
        $config = Config::share('notExist');
73
        $this->assertEmpty($config);
74
    }
75
76 View Code Duplication
    public function testModule() {
77
        $time = time();
78
        Config::save('module', ['test' => $time], 'TestModule');
79
80
        $config = Config::module('TestModule', null, true);
81
        $this->assertEquals(["test" => $time], $config);
82
83
        $config = Config::module('TestModule');
84
        $this->assertEquals(["test" => $time], $config);
85
86
        $config = Config::module('notExist');
87
        $this->assertEmpty($config);
88
    }
89
}