JsonLoader   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 26
ccs 7
cts 7
cp 1
rs 10
c 0
b 0
f 0
wmc 4
lcom 1
cbo 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A test() 0 4 2
A load() 0 4 1
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