Completed
Pull Request — master (#86)
by Jan Philipp
01:57
created

ScriptLoader   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 3
dl 0
loc 34
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A loadScript() 0 14 3
1
<?php declare(strict_types=1);
2
3
4
namespace Shopware\Psh\ScriptRuntime\ScriptLoader;
5
6
use Shopware\Psh\Listing\Script;
7
use Shopware\Psh\ScriptRuntime\Command;
8
9
/**
10
 * Load scripts and parse it into commands
11
 */
12
class ScriptLoader
13
{
14
    /**
15
     * @var ScriptParser[]
16
     */
17
    private $parsers;
18
19
    /**
20
     * @param ScriptParser ...$parsers
21
     */
22
    public function __construct(ScriptParser ... $parsers)
23
    {
24
        $this->parsers = $parsers;
25
    }
26
27
    /**
28
     * @param Script $script
29
     * @return Command[]
30
     */
31
    public function loadScript(Script $script): array
32
    {
33
        $content = $this->loadFileContents($script->getPath());
0 ignored issues
show
Bug introduced by
The method loadFileContents() does not seem to exist on object<Shopware\Psh\Scri...iptLoader\ScriptLoader>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
34
35
        foreach ($this->parsers as $parser) {
36
            try {
37
                return $parser->parseContent($content, $script, $this);
38
            } catch (ScriptNotSupportedByParser $e) {
39
                //nth
40
            }
41
        }
42
43
        throw new ScriptNotSupportedByParser('Can not find a parser able to parse ' . $script->getPath());
44
    }
45
}
46