Completed
Pull Request — master (#2)
by Pol
10:48
created

BaseTask   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 19
dl 0
loc 49
rs 10
c 0
b 0
f 0
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getTaskArguments() 0 24 4
A setTaskArguments() 0 5 1
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace PhpTaskman\Core\Plugin;
6
7
use PhpTaskman\Core\Contract\TaskInterface;
8
use Robo\Common\BuilderAwareTrait;
9
use Robo\Contract\BuilderAwareInterface;
10
use Robo\TaskAccessor;
11
12
abstract class BaseTask extends \Robo\Task\BaseTask implements TaskInterface, BuilderAwareInterface
13
{
14
    use TaskAccessor;
15
16
    public const ARGUMENTS = [];
17
    public const NAME = 'NULL';
18
19
    /**
20
     * @var array
21
     */
22
    private $arguments;
23
24
    /**
25
     * {@inheritdoc}
26
     */
27
    public function getTaskArguments()
28
    {
29
        $arguments = $this->arguments;
30
31
        unset($arguments['task']);
32
33
        $argumentsAllowed = \array_combine(
34
            static::ARGUMENTS,
35
            static::ARGUMENTS
36
        );
37
38
        if (empty($argumentsAllowed)) {
39
            return $arguments;
40
        }
41
42
        foreach ($arguments as $key => $value) {
43
            if (isset($argumentsAllowed[$key])) {
44
                continue;
45
            }
46
47
            unset($arguments[$key]);
48
        }
49
50
        return $arguments;
51
    }
52
53
    /**
54
     * {@inheritdoc}
55
     */
56
    public function setTaskArguments(array $arguments = [])
57
    {
58
        $this->arguments = $arguments;
59
60
        return $this;
61
    }
62
}
63