Passed
Pull Request — master (#14)
by
unknown
08:37
created

PhpLoader   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 26
ccs 0
cts 19
cp 0
rs 10
c 0
b 0
f 0
wmc 6

3 Methods

Rating   Name   Duplication   Size   Complexity  
A load() 0 8 2
A isSupported() 0 3 1
A unload() 0 9 3
1
<?php
2
declare(strict_types=1);
3
4
namespace Northwoods\Config\Loader;
5
6
class PhpLoader implements LoaderInterface
7
{
8
    public static function isSupported(): bool
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines before function; 0 found
Loading history...
9
    {
10
        return true;
11
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
12
13
    public function load(string $path): array
14
    {
15
        if (is_file("$path.php")) {
16
            $path = $path;
17
            return require "$path.php";
18
        }
19
20
        return [];
21
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
22
23
    public function unload(string $path, array $data)
24
    {
0 ignored issues
show
Coding Style introduced by
Expected 0 blank lines after opening function brace; 1 found
Loading history...
25
26
        if ( is_file("{$path}.php") && !copy("{$path}.php", "{$path}.backup.php") ) {
0 ignored issues
show
Coding Style introduced by
First condition of a multi-line IF statement must directly follow the opening parenthesis
Loading history...
Coding Style introduced by
There must be a single space after a NOT operator; 0 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
27
            throw LoaderException::backupFail(static::class);
28
        }
29
        $filename = basename($path);
30
        
31
        file_put_contents("{$path}.php" , "<?php " . PHP_EOL . " return " . \Northwoods\Config\varexport($data[$filename], true) . ';' . PHP_EOL);
0 ignored issues
show
Coding Style introduced by
Space found before comma in function call
Loading history...
32
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 0 found
Loading history...
33
}
34