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

AbstractRepository::resource()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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