ShopwareCommandDispatcher::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
1
<?php
2
3
namespace Deployee\Plugins\ShopwareTasks\Dispatcher;
4
5
use Deployee\Plugins\Deploy\Definitions\Tasks\TaskDefinitionInterface;
6
use Deployee\Plugins\Deploy\Dispatcher\AbstractTaskDefinitionDispatcher;
7
use Deployee\Plugins\Deploy\Dispatcher\DispatchResultInterface;
8
use Deployee\Plugins\ShellTasks\Definitions\ShellTaskDefinition;
9
use Deployee\Plugins\ShellTasks\Helper\ExecutableFinder;
10
use Deployee\Plugins\ShopwareTasks\Definitions\ShopwareCommandDefinition;
11
12
class ShopwareCommandDispatcher extends AbstractTaskDefinitionDispatcher
13
{
14
    /**
15
     * @var ExecutableFinder
16
     */
17
    private $execFinder;
18
19
    /**
20
     * @param ExecutableFinder $execFinder
21
     */
22
    public function __construct(ExecutableFinder $execFinder)
23
    {
24
        $this->execFinder = $execFinder;
25
    }
26
27
    /**
28
     * @param TaskDefinitionInterface $taskDefinition
29
     * @return bool
30
     */
31
    public function canDispatchTaskDefinition(TaskDefinitionInterface $taskDefinition): bool
32
    {
33
        return $taskDefinition instanceof ShopwareCommandDefinition;
34
    }
35
36
    /**
37
     * @param TaskDefinitionInterface $taskDefinition
38
     * @return DispatchResultInterface
39
     * @throws \Deployee\Plugins\Deploy\Exception\DispatcherException
40
     */
41
    public function dispatch(TaskDefinitionInterface $taskDefinition): DispatchResultInterface
42
    {
43
        $parameter = $taskDefinition->define();
44
        $shellTask = new ShellTaskDefinition('php');
45
        $shellTask->arguments(
46
            sprintf(
47
                '%s %s %s',
48
                $this->execFinder->find('swconsole'),
49
                $parameter->get('command'),
50
                $parameter->get('arguments')
51
            )
52
        );
53
54
        return $this->delegate($shellTask);
55
    }
56
57
}