canDispatchTaskDefinition()   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\ShopwareTasks\Definitions\PluginInstallDefinition;
9
use Deployee\Plugins\ShopwareTasks\Definitions\ShopwareCommandDefinition;
10
11
class PluginInstallDispatcher extends AbstractTaskDefinitionDispatcher
12
{
13
    /**
14
     * @param TaskDefinitionInterface $taskDefinition
15
     * @return bool
16
     */
17
    public function canDispatchTaskDefinition(TaskDefinitionInterface $taskDefinition): bool
18
    {
19
        return $taskDefinition instanceof PluginInstallDefinition;
20
    }
21
22
    /**
23
     * @param TaskDefinitionInterface $taskDefinition
24
     * @return DispatchResultInterface
25
     * @throws \Deployee\Plugins\Deploy\Exception\DispatcherException
26
     */
27
    public function dispatch(TaskDefinitionInterface $taskDefinition): DispatchResultInterface
28
    {
29
        $parameter = $taskDefinition->define();
30
        return $this->delegate(
31
            new ShopwareCommandDefinition(
32
                'plugin:install',
33
                sprintf(
34
                    '-n %s %s',
35
                    $parameter->get('activate') === true ? '--activate' : '',
36
                    $parameter->get('plugin')
37
                )
38
            )
39
        );
40
    }
41
}