GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — 3.0 ( 6d983c...443341 )
by Vermeulen
01:58
created

RunTasks   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 168
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
dl 0
loc 168
rs 10
c 0
b 0
f 0

10 Methods

Rating   Name   Duplication   Size   Complexity  
A hp$0 ➔ __construct() 0 5 1
A __construct() 0 5 1
A getRunSteps() 0 4 1
A setRunSteps() 0 5 1
A addToRunSteps() 0 5 1
A getNotifyPrefix() 0 4 1
A setNotifyPrefix() 0 5 1
A run() 0 29 5
A sendNotify() 0 16 1
A generateStepItem() 0 13 1
1
<?php
2
3
namespace BFW;
4
5
class RunTasks extends Subject
6
{
7
    /**
8
     * @var object[] $runSteps All steps used for run the application
9
     */
10
    protected $runSteps;
11
    
12
    /**
13
     * @var string $notifyPrefix A prefix to use for task name
14
     */
15
    protected $notifyPrefix;
16
    
17
    /**
18
     * Constructor
19
     * 
20
     * @param object[] $runSteps All step to call
21
     * @param string $notifyPrefix The prefix to use for task name
22
     */
23
    public function __construct(array $runSteps, string $notifyPrefix)
24
    {
25
        $this->runSteps     = $runSteps;
26
        $this->notifyPrefix = $notifyPrefix;
27
    }
28
    
29
    /**
30
     * Getter to access to the run step array
31
     * 
32
     * @return object[]
33
     */
34
    public function getRunSteps(): array
35
    {
36
        return $this->runSteps;
37
    }
38
    
39
    /**
40
     * Setter to re-define the run step array
41
     * 
42
     * @param object[] $runSteps The new list of run steps
43
     * 
44
     * @return $this
45
     */
46
    public function setRunSteps(array $runSteps): self
47
    {
48
        $this->runSteps = $runSteps;
49
        return $this;
50
    }
51
    
52
    /**
53
     * Add a new run step to the list
54
     * 
55
     * @param string $name          The name of the new run step
56
     * @param object $runStepsToAdd The run step to add
57
     * 
58
     * @return $this
59
     */
60
    public function addToRunSteps(string $name, $runStepsToAdd): self
61
    {
62
        $this->runSteps[$name] = $runStepsToAdd;
63
        return $this;
64
    }
65
    
66
    /**
67
     * Getter to property notifyPrefix
68
     * 
69
     * @return string
70
     */
71
    public function getNotifyPrefix(): string
72
    {
73
        return $this->notifyPrefix;
74
    }
75
    
76
    /**
77
     * Setter to re-define the notifyPrefix
78
     * 
79
     * @param string $notifyPrefix
80
     * 
81
     * @return $this
82
     */
83
    public function setNotifyPrefix(string$notifyPrefix): self
84
    {
85
        $this->notifyPrefix = $notifyPrefix;
86
        return $this;
87
    }
88
    
89
    /**
90
     * Run all steps declared and notify for each step
91
     * Call the callback if declared for each step
92
     * 
93
     * @return void
94
     */
95
    public function run()
96
    {
97
        $prefix = $this->notifyPrefix;
98
        
99
        $this->addNotification($prefix.'_start_run_tasks');
100
        
101
        foreach ($this->runSteps as $actionName => $stepInfos) {
102
            $context = null;
103
            if ($stepInfos->context !== null) {
104
                $context = $stepInfos->context;
105
            }
106
            
107
            if ($stepInfos->callback === null) {
108
                $this->addNotification($prefix.'_exec_'.$actionName, $context);
109
                continue;
110
            }
111
            
112
            $this->addNotification($prefix.'_run_'.$actionName, $context);
113
114
            if (is_callable($stepInfos->callback)) {
115
                $callback = $stepInfos->callback;
116
                $callback();
117
            }
118
119
            $this->addNotification($prefix.'_done_'.$actionName, $context);
120
        }
121
        
122
        $this->addNotification($prefix.'_end_run_tasks');
123
    }
124
    
125
    /**
126
     * Send a notification to all observers connected to the subject
127
     * 
128
     * @param string $action The action name
129
     * @param mixed $context (default null) The context to pass to the subject
130
     * 
131
     * @return void
132
     */
133
    public function sendNotify(string $action, $context = null)
134
    {
135
        \BFW\Application::getInstance()
0 ignored issues
show
Documentation Bug introduced by
The method getMonolog does not exist on object<BFW\Application>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
136
            ->getMonolog()
137
            ->getLogger()
138
            ->debug(
139
                'RunTask notify',
140
                [
141
                    'prefix' => $this->notifyPrefix,
142
                    'action' => $action
143
                ]
144
            )
145
        ;
146
        
147
        $this->addNotification($action, $context);
148
    }
149
    
150
    /**
151
     * Generate the anonymous class with the structure to use for each item
152
     * 
153
     * @param mixed $context The context to add to the notify
154
     * @param callable|null $callback The callback to call when
155
     *  the task is runned
156
     * 
157
     * @return object
158
     */
159
    public static function generateStepItem($context = null, $callback = null)
160
    {
161
        return new class ($context, $callback) {
162
            public $context;
163
            public $callback;
164
            
165
            public function __construct($context, $callback)
166
            {
167
                $this->context  = $context;
168
                $this->callback = $callback;
169
            }
170
        };
171
    }
172
}
173