Completed
Push — master ( 9c1f83...0c1135 )
by Paulo Rodrigues
10:00
created

Manifest/Loader/AbstractManifestLoader.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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 16
    public function __construct($path, $rootKey = null)
15
    {
16 16
        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 16
        $this->path = $path;
21 16
        $this->rootKey = $rootKey;
22 16
    }
23
24
    /**
25
     * {@inheritdoc}
26
     */
27 14
    public function load()
28
    {
29 14
        $entries = $this->parse($this->path);
30
31 14
        if (!empty($this->rootKey)) {
32 4
            if (!isset($entries[$this->rootKey])) {
33 2
                throw new \InvalidArgumentException('Manifest file contains no '.$this->rootKey.' key');
34
            }
35
36 2
            $entries = $entries[$this->rootKey];
37
        }
38
39 12
        return new Manifest($entries);
40
    }
41
42
    /**
43
     * {@inheritdoc}
44
     */
45 8
    public function getPath()
46
    {
47 8
        return $this->path;
48
    }
49
}
50