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

EnvLoader::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

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