Completed
Pull Request — master (#26)
by Paulo Rodrigues
04:47
created

AbstractManifestLoader::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2.0185

Importance

Changes 0
Metric Value
dl 0
loc 9
c 0
b 0
f 0
rs 9.6666
ccs 5
cts 6
cp 0.8333
cc 2
eloc 5
nc 2
nop 2
crap 2.0185
1
<?php
2
3
namespace Rj\FrontendBundle\Manifest\Loader;
4
5
use Rj\FrontendBundle\Manifest\Manifest;
6
7
abstract class AbstractManifestLoader implements ManifestLoaderInterface
8
{
9
    private $path;
10
    private $rootKey;
11
12
    abstract protected function parse($path);
13
14 3
    public function __construct($path, $rootKey = null)
15
    {
16 3
        if (!is_file($path)) {
17
            throw new \InvalidArgumentException("The manifest file '$path' could not be found");
0 ignored issues
show
Coding Style Best Practice introduced by
As per coding-style, please use concatenation or sprintf for the variable $path instead of interpolation.

It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.

// Instead of
$x = "foo $bar $baz";

// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
Loading history...
18
        }
19
20 3
        $this->path = $path;
21 3
        $this->rootKey = $rootKey;
22 3
    }
23
24
    /**
25
     * {@inheritdoc}
26
     */
27 3
    public function load()
28
    {
29 3
        $entries = $this->parse($this->path);
30
31 3
        if (!empty($this->rootKey)) {
32
            if (!isset($entries[$this->rootKey])) {
33
                throw new \InvalidArgumentException('Manifest file contains no '.$this->rootKey.' key');
34
            }
35
36
            $entries = $entries[$this->rootKey];
37
        }
38
39 3
        return new Manifest($entries);
40
    }
41
42
    /**
43
     * {@inheritdoc}
44
     */
45 3
    public function getPath()
46
    {
47 3
        return $this->path;
48
    }
49
}
50