Passed
Push — master ( 6046d2...3d03c1 )
by Arjan
39s
created

AbstractRepository::loadJson()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2.0625

Importance

Changes 0
Metric Value
dl 0
loc 8
c 0
b 0
f 0
rs 9.4285
ccs 3
cts 4
cp 0.75
cc 2
eloc 4
nc 2
nop 1
crap 2.0625
1
<?php
2
3
namespace ArjanSchouten\HtmlMinifier\Repositories;
4
5
use ArjanSchouten\HtmlMinifier\Exception\FileNotFoundException;
6
7
abstract class AbstractRepository
8
{
9
    /**
10
     * The resource directory name.
11
     *
12
     * @var string
13
     */
14
    protected $resourceDir = 'resources';
15
16
    /**
17
     * Load a json file and decode it.
18
     *
19
     * @param string $path
20
     *
21
     * @throws \ArjanSchouten\HtmlMinifier\Exception\FileNotFoundException
22
     *
23
     * @return mixed
24
     */
25 2
    protected function loadJson($path)
26
    {
27 2
        if (!file_exists($path)) {
28
            throw new FileNotFoundException();
29
        }
30
31 2
        return json_decode(file_get_contents($path));
32
    }
33
34
    /**
35
     * Get the absolute path to the given resource file.
36
     *
37
     * @param string $file
38
     *
39
     * @return string
40
     */
41 2
    protected function resource($file)
42
    {
43 2
        return __DIR__.'/'.$this->resourceDir.'/'.$file;
44
    }
45
}
46