ShopwareCommandDispatcher   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
c 1
b 0
f 0
dl 0
loc 43
ccs 0
cts 9
cp 0
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A canDispatchTaskDefinition() 0 3 1
A __construct() 0 3 1
A dispatch() 0 14 1
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
}