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

BashScriptParser::parseContent()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.8666
c 0
b 0
f 0
cc 3
nc 3
nop 2
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