BaseAction   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%
Metric Value
wmc 7
lcom 1
cbo 1
dl 0
loc 49
ccs 17
cts 17
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getArguments() 0 4 1
A setArguments() 0 6 1
A parseArguments() 0 16 4
1
<?php
2
3
namespace Thruster\Component\Actions\Action;
4
5
use Thruster\Component\Actions\ActionInterface;
6
use Thruster\Component\Actions\ExecutorInterface;
7
8
/**
9
 * Class BaseAction
10
 *
11
 * @package Thruster\Component\Actions\Action
12
 * @author  Aurimas Niekis <[email protected]>
13
 */
14
abstract class BaseAction implements ActionInterface
15
{
16
    /**
17
     * @var array
18
     */
19
    protected $arguments;
20
21 14
    public function __construct()
22
    {
23 14
        $this->arguments = func_get_args();
24 14
    }
25
26
    /**
27
     * @inheritdoc
28
     */
29 11
    public function getArguments() : array
30
    {
31 11
        return $this->arguments;
32
    }
33
34
    /**
35
     * @param array $arguments
36
     *
37
     * @return $this
38
     */
39 3
    public function setArguments(array $arguments) : self
40
    {
41 3
        $this->arguments = $arguments;
42
43 3
        return $this;
44
    }
45
46 8
    public function parseArguments(ExecutorInterface $executor) : array
47
    {
48 8
        $result = [];
49
50 8
        foreach ($this->getArguments() as $argument) {
51 8
            if ($argument instanceof ActionInterface) {
52 3
                $result[] = $executor->execute($argument);
53 8
            } elseif (is_callable($argument)) {
54 4
                $result[] = call_user_func($argument);
55
            } else {
56 7
                $result[] = $argument;
57
            }
58
        }
59
60 7
        return $result;
61
    }
62
}
63