JsonLoader::test()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 2
nc 2
nop 1
dl 0
loc 4
ccs 2
cts 2
cp 1
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
namespace Wandu\Config\Loader;
3
4
use Wandu\Config\Contracts\Loader;
5
6
class JsonLoader implements Loader
7
{
8
    /** @var string */
9
    protected $pattern;
10
11 3
    public function __construct(string $pattern = '~^[a-z_][a-z0-9_]*\.json$~')
12
    {
13 3
        $this->pattern = $pattern;
14 3
    }
15
16
    /**
17
     * {@inheritdoc}
18
     */
19 3
    public function test(string $path): bool
20
    {
21 3
        return file_exists($path) && preg_match($this->pattern, pathinfo($path)['basename']);
22
    }
23
24
    /**
25
     * {@inheritdoc}
26
     */
27 3
    public function load(string $path)
28
    {
29 3
        return json_decode(file_get_contents($path), true);
30
    }
31
}
32