Completed
Push — master ( b31514...603a9f )
by Changwan
06:16
created

EnvLoader   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

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 1

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 M1\Env\Parser;
5
use Wandu\Config\Contracts\Loader;
6
7
class EnvLoader implements Loader
8
{
9
    /** @var string */
10
    protected $pattern;
11
12 3
    public function __construct(string $pattern = '~^[a-z_][a-z0-9_]*\.env$~')
13
    {
14 3
        $this->pattern = $pattern;
15 3
    }
16
17
    /**
18
     * {@inheritdoc}
19
     */
20 3
    public function test(string $path): bool
21
    {
22 3
        return file_exists($path) && preg_match($this->pattern, pathinfo($path)['basename']);
23
    }
24
25
    /**
26
     * {@inheritdoc}
27
     */
28 3
    public function load(string $path)
29
    {
30 3
        return (new Parser(file_get_contents($path)))->getContent();
31
    }
32
}
33