BaseAction::__construct()   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
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
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