PipelineAction::parseArguments()   C
last analyzed

Complexity

Conditions 7
Paths 17

Size

Total Lines 27
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 15
CRAP Score 7
Metric Value
dl 0
loc 27
ccs 15
cts 15
cp 1
rs 6.7273
cc 7
eloc 16
nc 17
nop 1
crap 7
1
<?php
2
3
namespace Thruster\Component\Actions\Action;
4
5
use Thruster\Component\Actions\ActionInterface;
6
use Thruster\Component\Actions\ExecutorInterface;
7
use Thruster\Component\Actions\ExecutorLessInterface;
8
use function Funct\null;
9
10
/**
11
 * Class PipelineAction
12
 *
13
 * @package Thruster\Component\Actions\Action
14
 * @author  Aurimas Niekis <[email protected]>
15
 */
16
class PipelineAction extends BaseAction implements ExecutorLessInterface
17
{
18
    /**
19
     * @inheritDoc
20
     */
21 1
    public function getName() : string
22
    {
23 1
        return 'thruster_pipeline';
24
    }
25
26 5
    public function parseArguments(ExecutorInterface $executor)
27
    {
28 5
        $first = true;
29 5
        $value = null;
30
31 5
        foreach ($this->getArguments() as $argument) {
32 5
            $arguments = null($value) ? [] : [$value];
33
34 5
            if ($argument instanceof ActionInterface) {
35 3
                if (false === $first) {
36 3
                    $argument->setArguments($arguments);
37
                }
38
39 3
                $value = $executor->execute($argument);
40 4
            } elseif (is_callable($argument)) {
41 3
                $value = call_user_func_array($argument, $arguments);
42
            } else {
43 4
                $value = $argument;
44
            }
45
46 5
            if (true === $first) {
47 5
                $first = false;
48
            }
49
        }
50
51 5
        return $value;
52
    }
53
}
54