StepsBuilder   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 69
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
c 0
b 0
f 0
lcom 1
cbo 0
dl 0
loc 69
ccs 17
cts 17
cp 1
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __call() 0 4 1
A addStep() 0 4 1
A addStepWithEvents() 0 6 1
A pullSteps() 0 8 1
A getSteps() 0 4 1
1
<?php
2
3
/*
4
 * This file is part of Rocketeer
5
 *
6
 * (c) Maxime Fabre <[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
13
namespace Rocketeer\Services;
14
15
/**
16
 * Saves in an array methods the call signatures
17
 * of the methods called on it.
18
 */
19
class StepsBuilder
20
{
21
    /**
22
     * The extisting steps.
23
     *
24
     * @var array
25
     */
26
    protected $steps = [];
27
28
    /**
29
     * Add a step.
30
     *
31
     * @param string $name
32
     * @param array  $arguments
33
     */
34 28
    public function __call($name, $arguments)
35
    {
36 28
        $this->addStep($name, $arguments);
37 28
    }
38
39
    /**
40
     * Add a callable to the steps.
41
     *
42
     * @param string|callable $callable
43
     * @param array           $arguments
44
     */
45 31
    public function addStep($callable, $arguments = [])
46
    {
47 31
        $this->steps[] = [$callable, $arguments];
48 31
    }
49
50
    /**
51
     * Add a step and fire an event before/after.
52
     *
53
     * @param string          $event
54
     * @param string|callable $callable
55
     * @param array           $arguments
56
     */
57 1
    public function addStepWithEvents($event, $callable, $arguments = [])
58
    {
59 1
        $this->addStep('fireEvent', [$event.'.before']);
60 1
        $this->addStep($callable, $arguments);
61 1
        $this->addStep('fireEvent', [$event.'.after']);
62 1
    }
63
64
    /**
65
     * Get and clear the steps.
66
     *
67
     * @return array
68
     */
69 31
    public function pullSteps()
70
    {
71 31
        $steps = $this->steps;
72
73 31
        $this->steps = [];
74
75 31
        return $steps;
76
    }
77
78
    /**
79
     * Get the steps to execute.
80
     *
81
     * @return array
82
     */
83 1
    public function getSteps()
84
    {
85 1
        return $this->steps;
86
    }
87
}
88