Completed
Pull Request — master (#82)
by Jan Philipp
01:36
created

BashScriptParser   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 3
dl 0
loc 25
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A parseContent() 0 12 3
1
<?php declare(strict_types=1);
2
3
namespace Shopware\Psh\ScriptRuntime\ScriptLoader;
4
5
use Shopware\Psh\Listing\Script;
6
use Shopware\Psh\ScriptRuntime\BashCommand;
7
8
class BashScriptParser implements ScriptParser
9
{
10
    const TYPE_DIRECT_EXECUTE = '<PSH_EXECUTE_THROUGH_CMD>';
11
12
    /**
13
     * @todo add validation and notice
14
     */
15
    const SHOULD_BE_PRESENT = "\nset -euo pipefail\n";
16
17
    /**
18
     * {@inheritdoc}
19
     */
20
    public function parseContent(string $content, Script $script): array
21
    {
22
        if (strpos($content, self::TYPE_DIRECT_EXECUTE) === false) {
23
            throw new ScriptNotSupportedByParser('Marker for execution missing');
24
        }
25
26
        if (!is_executable($script->getPath())) {
27
            throw new \RuntimeException('Bash scripts can only be executed if they are executable please execute chmod + ' . $script->getPath());
28
        }
29
30
        return [new BashCommand($script)];
31
    }
32
}
33