Passed
Pull Request — master (#40)
by Chema
03:06
created

PhpConfigReader   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 19
ccs 8
cts 8
cp 1
rs 10
c 0
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A canRead() 0 5 1
A read() 0 10 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Gacela\Framework\Config\ConfigReader;
6
7
use Gacela\Framework\Config\ConfigReaderInterface;
8
9
final class PhpConfigReader implements ConfigReaderInterface
10
{
11 3
    public function canRead(string $absolutePath): bool
12
    {
13 3
        $extension = pathinfo($absolutePath, PATHINFO_EXTENSION);
14
15 3
        return 'php' === $extension;
16
    }
17
18 3
    public function read(string $absolutePath): array
19
    {
20 3
        if (!file_exists($absolutePath)) {
21 1
            return [];
22
        }
23
24
        /** @var null|array $content */
25 3
        $content = include $absolutePath;
26
27 3
        return is_array($content) ? $content : [];
28
    }
29
}
30