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

PhpLoader::unload()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
cc 3
eloc 4
nc 2
nop 2
dl 0
loc 9
ccs 0
cts 7
cp 0
crap 12
rs 10
c 0
b 0
f 0
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