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

AbstractRepository   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 83.33%

Importance

Changes 0
Metric Value
dl 0
loc 39
c 0
b 0
f 0
wmc 3
lcom 1
cbo 1
rs 10
ccs 5
cts 6
cp 0.8333

2 Methods

Rating   Name   Duplication   Size   Complexity  
A loadJson() 0 8 2
A resource() 0 4 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