Completed
Branch master (d7ed14)
by Benjamin
08:11 queued 03:45
created

AbstractTypo3Task::getDescription()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
/**
3
 * This file is part of the teamneusta/magallanes-task-typo3 package.
4
 *
5
 * Copyright (c) 2017 neusta GmbH | Ein team neusta Unternehmen
6
 *
7
 * For the full copyright and license information, please view the LICENSE file that was distributed with this source code.
8
 *
9
 * @license http://www.opensource.org/licenses/mit-license.html  MIT License
10
 */
11
declare(strict_types=1);
12
13
namespace TeamNeusta\Magallanes\Task\TYPO3;
14
15
use Mage\Task\AbstractTask;
16
use Symfony\Component\Process\Process;
17
18
/**
19
 * Class AbstractTypo3Task
20
 *
21
 * @author Benjamin Kluge <[email protected]>
22
 * @package TeamNeusta\Magallanes\Task\TYPO3
23
 */
24
abstract class AbstractTypo3Task extends AbstractTask
25
{
26
    /**
27
     * namePrefix
28
     *
29
     * @var string
30
     */
31
    protected $namePrefix = 'typo3/';
32
33
    /**
34
     * name
35
     *
36
     * @var string
37
     */
38
    protected $name;
39
40
    /**
41
     * description
42
     *
43
     * @var string
44
     */
45
    protected $description;
46
47
    /**
48
     * getName
49
     *
50
     * @return string
51
     */
52
    public function getName(): string
53
    {
54
        return $this->namePrefix.$this->name;
55
    }
56
57
    /**
58
     * getDescription
59
     *
60
     * @return string
61
     */
62
    public function getDescription(): string
63
    {
64
        return $this->description;
65
    }
66
67
    /**
68
     * getContextCommand
69
     *
70
     * @param $cmd
71
     * @param array $options
72
     * @return string
73
     */
74
    protected function getContextCommand($cmd, array $options): string
75
    {
76
        if (!empty($options['context'])) {
77
            return sprintf(
78
                       'export TYPO3_CONTEXT="%s" && ',
79
                       $options['context']
80
                   ).$cmd;
81
        }
82
83
        return $cmd;
84
    }
85
86
    /**
87
     * getOptions
88
     *
89
     * @param array $defaults
90
     * @return array
91
     */
92
    protected function getOptions(array $defaults): array
93
    {
94
        $options = array_merge(
95
            ['context' => null],
96
            $defaults,
97
            $this->runtime->getMergedOption('typo3')
98
        );
99
100
        return array_filter($options);
101
    }
102
103
    /**
104
     * executeCommand
105
     *
106
     * @param $command
107
     * @return bool
108
     */
109
    protected function executeCommand($command): bool
110
    {
111
        /** @var Process $process */
112
        $process = $this->runtime->runCommand(trim($command));
113
114
        return $process->isSuccessful();
115
    }
116
}
117