AbstractTask::setOptions()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 1
rs 10
1
<?php
2
3
/*
4
 * This file is part of the Magallanes package.
5
 *
6
 * (c) Andrés Montañez <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Mage\Task;
13
14
use Mage\Runtime\Runtime;
15
16
/**
17
 * Abstract base class for Magallanes Tasks
18
 *
19
 * @author Andrés Montañez <[email protected]>
20
 */
21
abstract class AbstractTask
22
{
23
    /** @var array<string, string|int|null> */
24
    protected array $options = [];
25
26
    protected Runtime $runtime;
27
28
    /**
29
     * Get the Name/Code of the Task
30
     */
31
    abstract public function getName(): string;
32
33
    /**
34
     * Get a short Description of the Task
35
     */
36
    abstract public function getDescription(): string;
37
38
    /**
39
     * Executes the Command
40
     */
41
    abstract public function execute(): bool;
42
43
    /**
44
     * Set additional Options for the Task
45
     *
46
     * @param array<string, string|int|null> $options
47
     */
48 66
    public function setOptions(array $options = []): self
49
    {
50 66
        $this->options = array_merge($this->getDefaults(), $options);
51 66
        return $this;
52
    }
53
54
    /**
55
     * Set the Runtime instance
56
     */
57 77
    public function setRuntime(Runtime $runtime): self
58
    {
59 77
        $this->runtime = $runtime;
60 77
        return $this;
61
    }
62
63
    /**
64
     * Return Default options
65
     *
66
     * @return array<string, string|int|null>
67
     */
68 45
    public function getDefaults(): array
69
    {
70 45
        return [];
71
    }
72
}
73