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.
Passed
Branch dev (d5e133)
by Андрей
20:27 queued 13s
created

Metadata   B

Complexity

Total Complexity 45

Size/Duplication

Total Lines 499
Duplicated Lines 7.21 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 45
lcom 1
cbo 1
dl 36
loc 499
rs 8.3673
c 2
b 0
f 0

24 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A isWorkflowDispatch() 0 4 1
A setWorkflowDispatch() 0 6 1
A getWorkflowRunType() 0 4 1
A setWorkflowRunType() 10 10 2
A isFlagRunPrepareData() 0 4 1
A setFlagRunPrepareData() 0 6 1
A getPrepareDataMethod() 0 4 1
A setPrepareDataMethod() 10 10 2
A getPrepareDataHandler() 0 4 1
A setPrepareDataHandler() 0 6 1
A getFlagHasConditions() 0 4 1
A setFlagHasConditions() 0 6 1
A getConditions() 0 4 1
A addConditions() 0 7 2
A getWorkflowManagerNameRouterParam() 0 4 1
A setWorkflowManagerNameRouterParam() 0 6 1
A getWorkflowActionNameRouterParam() 0 4 1
A setWorkflowActionNameRouterParam() 0 6 1
A getWorkflowNameRouterParam() 0 4 1
A setWorkflowNameRouterParam() 0 6 1
A getEntryIdRouterParam() 0 4 1
A setEntryIdRouterParam() 0 6 1
C validate() 16 61 19

How to fix   Duplicated Code    Complexity   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

Complex Class

 Tip:   Before tackling complexity, make sure that you eliminate any duplication first. This often can reduce the size of classes significantly.

Complex classes like Metadata often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use Metadata, and based on these observations, apply Extract Interface, too.

1
<?php
2
/**
3
 * @link https://github.com/old-town/workflow-zf2-dispatch
4
 * @author  Malofeykin Andrey  <[email protected]>
5
 */
6
namespace OldTown\Workflow\ZF2\Dispatch\Metadata\Storage;
7
8
use SplObjectStorage;
9
10
/**
11
 * Class Metadata
12
 *
13
 * @package OldTown\Workflow\ZF2\Dispatch\Metadata\Storage
14
 */
15
class Metadata implements MetadataInterface
16
{
17
    /**
18
     * @var string
19
     */
20
    const WORKFLOW_RUN_TYPE_DO_ACTION = 'doAction';
21
22
    /**
23
     * @var string
24
     */
25
    const WORKFLOW_RUN_INITIALIZE = 'initialize';
26
27
    /**
28
     * @var string
29
     */
30
    const PREPARE_DATA_RUN_TYPE_METHOD = 'method';
31
32
    /**
33
     * Имя параметра роуетра, значение которого определяет имя используемого менеджера workflow
34
     *
35
     * @var string
36
     */
37
    const WORKFLOW_MANAGER_NAME_ROUTER_PARAM = 'workflowManagerName';
38
39
    /**
40
     *  Имя параметра роуетра, значение которого определяет имя действия в workflow
41
     *
42
     * @var string
43
     */
44
    const WORKFLOW_ACTION_NAME_ROUTER_PARAM = 'workflowActionName';
45
46
    /**
47
     *  Имя параметра роуетра, значение которого определяет имя workflow
48
     *
49
     * @var string
50
     */
51
    const WORKFLOW_NAME_ROUTER_PARAM = 'workflowName';
52
53
    /**
54
     *  Имя параметра роуетра, значение которого определяет id процесса workflow
55
     *
56
     * @var string
57
     */
58
    const ENTRY_ID_ROUTER_PARAM = 'entryId';
59
60
    /**
61
     * Флаг определят нужно ли запускать workflow
62
     *
63
     * @var boolean
64
     */
65
    protected $workflowDispatch = false;
66
67
    /**
68
     * Определяет что мы хотим сделать с workflow. Запустить новый процесс (initialize), или инициировать переход в уже
69
     * запущенном процессе (doAction)
70
     *
71
     * @var string
72
     */
73
    protected $workflowRunType;
74
75
    /**
76
     * Флаг определят нужно вызвать метод или сервис, с целью подготовки данных, которые в дальнейшем передаются в workflow
77
     *
78
     * @var bool
79
     */
80
    protected $flagRunPrepareData = false;
81
82
    /**
83
     * Значение определяет что является обработчиком подготавливающим данные (метод контроллера, сервис и т.д.)
84
     *
85
     * @var string
86
     */
87
    protected $prepareDataMethod;
88
89
    /**
90
     * Строка содержащая имя обработчика (имя метода контроллера или имя сервиса) в котором происходит подготовка данных
91
     *
92
     * @var string
93
     */
94
    protected $prepareDataHandler;
95
96
    /**
97
     * Флаг указывает на то что есть условия для запуска workflow
98
     *
99
     * @var bool
100
     */
101
    protected $flagHasConditions = false;
102
103
    /**
104
     * Метаданные, содержащии информацию о том как вызвать условия, для проверка нужно ли запускать workflow
105
     *
106
     * @var DispatchConditionMetadata[]|SplObjectStorage
107
     */
108
    protected $conditions;
109
110
    /**
111
     * Имя параметра в роуетере, значение которого - имя менеджера workflow
112
     *
113
     * @var string
114
     */
115
    protected $workflowManagerNameRouterParam = self::WORKFLOW_MANAGER_NAME_ROUTER_PARAM;
116
117
    /**
118
     * Имя параметра в роуетере, значение которого имя вызываемого действия
119
     *
120
     * @var string
121
     */
122
    protected $workflowActionNameRouterParam = self::WORKFLOW_ACTION_NAME_ROUTER_PARAM;
123
124
    /**
125
     * Имя параметра в роуетере, значение которого имя workflow
126
     *
127
     * @var string
128
     */
129
    protected $workflowNameRouterParam = self::WORKFLOW_NAME_ROUTER_PARAM;
130
131
    /**
132
     * Имя параметра в роуетере, значение которого id запущенного процесса
133
     *
134
     * @var string
135
     */
136
    protected $entryIdRouterParam = self::ENTRY_ID_ROUTER_PARAM;
137
138
    /**
139
     * Разрешенные типы запуска workflow
140
     *
141
     * @var array
142
     */
143
    protected $allowWorkflowRunType = [
144
        self::WORKFLOW_RUN_TYPE_DO_ACTION => self::WORKFLOW_RUN_TYPE_DO_ACTION,
145
        self::WORKFLOW_RUN_INITIALIZE => self::WORKFLOW_RUN_INITIALIZE,
146
    ];
147
148
    /**
149
     * Разрешенные способы запука обработчика отвечающего за подготовку данных для wf
150
     *
151
     * @var array
152
     */
153
    protected $allowPrepareDataMethod = [
154
        self::PREPARE_DATA_RUN_TYPE_METHOD => self::PREPARE_DATA_RUN_TYPE_METHOD
155
    ];
156
157
    /**
158
     *
159
     */
160
    public function __construct()
161
    {
162
        $this->conditions = new SplObjectStorage();
163
    }
164
165
    /**
166
     * Флаг определят нужно ли запускать workflow
167
     *
168
     * @return boolean
169
     */
170
    public function isWorkflowDispatch()
171
    {
172
        return $this->workflowDispatch;
173
    }
174
175
    /**
176
     * Устанавливает флаг определяющий нужно ли запускать workflow
177
     *
178
     * @param boolean $workflowDispatch
179
     *
180
     * @return $this
181
     */
182
    public function setWorkflowDispatch($workflowDispatch)
183
    {
184
        $this->workflowDispatch = (boolean)$workflowDispatch;
185
186
        return $this;
187
    }
188
189
    /**
190
     * Определяет что мы хотим сделать с workflow. Запустить новый процесс (initialize), или инициировать переход в уже
191
     * запущенном процессе (doAction)
192
     *
193
     * @return string
194
     */
195
    public function getWorkflowRunType()
196
    {
197
        return $this->workflowRunType;
198
    }
199
200
    /**
201
     *
202
     * Определяет что мы хотим сделать с workflow. Запустить новый процесс (initialize), или инициировать переход в уже
203
     * запущенном процессе (doAction)
204
     *
205
     * @param string $workflowRunType
206
     *
207
     * @return $this
208
     *
209
     * @throws Exception\InvalidMetadataException
210
     */
211 View Code Duplication
    public function setWorkflowRunType($workflowRunType)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
212
    {
213
        if (!array_key_exists($workflowRunType, $this->allowWorkflowRunType)) {
214
            $errMsg = sprintf('Not allowed type %s', $workflowRunType);
215
            throw new Exception\InvalidMetadataException($errMsg);
216
        }
217
        $this->workflowRunType = (string)$workflowRunType;
218
219
        return $this;
220
    }
221
222
    /**
223
     *  Флаг определят нужно вызвать метод или сервис, с целью подготовки данных, которые в дальнейшем передаются в workflow
224
     *
225
     * @return boolean
226
     */
227
    public function isFlagRunPrepareData()
228
    {
229
        return $this->flagRunPrepareData;
230
    }
231
232
    /**
233
     * Устанавливает флаг определяющий нужно вызвать метод или сервис, с целью подготовки данных, которые в дальнейшем
234
     * передаются в workflow
235
     *
236
     * @param boolean $flagRunPrepareData
237
     *
238
     * @return $this
239
     */
240
    public function setFlagRunPrepareData($flagRunPrepareData)
241
    {
242
        $this->flagRunPrepareData = (boolean)$flagRunPrepareData;
243
244
        return $this;
245
    }
246
247
    /**
248
     * Значение определяет что является обработчиком подготавливающим данные (метод контроллера, сервис и т.д.)
249
     *
250
     * @return string
251
     */
252
    public function getPrepareDataMethod()
253
    {
254
        return $this->prepareDataMethod;
255
    }
256
257
    /**
258
     * Устанавливает значение определяющие что является обработчиком подготавливающим данные
259
     * (метод контроллера, сервис и т.д.)
260
     *
261
     * @param string $prepareDataMethod
262
     *
263
     * @return $this
264
     */
265 View Code Duplication
    public function setPrepareDataMethod($prepareDataMethod)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
266
    {
267
        if (!array_key_exists($prepareDataMethod, $this->allowPrepareDataMethod)) {
268
            $errMsg = sprintf('Not allowed prepare data method %s', $prepareDataMethod);
269
            throw new Exception\InvalidMetadataException($errMsg);
270
        }
271
        $this->prepareDataMethod = (string)$prepareDataMethod;
272
273
        return $this;
274
    }
275
276
    /**
277
     *  Строка содержащая имя обработчика (имя метода контроллера или имя сервиса) в котором происходит подготовка данных
278
     *
279
     * @return string
280
     */
281
    public function getPrepareDataHandler()
282
    {
283
        return $this->prepareDataHandler;
284
    }
285
286
    /**
287
     * Устанавлвивает строку содержащую имя обработчика (имя метода контроллера или имя сервиса)
288
     * в котором происходит подготовка данных
289
     *
290
     * @param string $prepareDataHandler
291
     *
292
     * @return $this
293
     */
294
    public function setPrepareDataHandler($prepareDataHandler)
295
    {
296
        $this->prepareDataHandler = (string)$prepareDataHandler;
297
298
        return $this;
299
    }
300
301
    /**
302
     * Флаг указывает на то что есть условия для запуска workflow
303
     *
304
     * @return boolean
305
     */
306
    public function getFlagHasConditions()
307
    {
308
        return $this->flagHasConditions;
309
    }
310
311
    /**
312
     * Устанавливает флаг указываеющий на то что есть условия для запуска workflow
313
     *
314
     * @param boolean $flagHasConditions
315
     *
316
     * @return $this
317
     */
318
    public function setFlagHasConditions($flagHasConditions)
319
    {
320
        $this->flagHasConditions = (boolean)$flagHasConditions;
321
322
        return $this;
323
    }
324
325
    /**
326
     * Возвращает метаданные, содержащии информацию о том как вызвать условия, для проверка нужно ли запускать workflow
327
     *
328
     * @return DispatchConditionMetadata[]|SplObjectStorage
329
     */
330
    public function getConditions()
331
    {
332
        return $this->conditions;
333
    }
334
335
    /**
336
     * Добавляет метаданные, содержащии информацию о том как вызвать условия, для проверка нужно ли запускать workflow
337
     *
338
     * @param DispatchConditionMetadata $condition
339
     *
340
     * @return $this
341
     */
342
    public function addConditions(DispatchConditionMetadata $condition)
343
    {
344
        if (!$this->conditions->contains($condition)) {
345
            $this->conditions->attach($condition);
346
        }
347
        return $this;
348
    }
349
350
    /**
351
     * Имя параметра в роуетере, значение которого - имя менеджера workflow
352
     *
353
     * @return string
354
     */
355
    public function getWorkflowManagerNameRouterParam()
356
    {
357
        return $this->workflowManagerNameRouterParam;
358
    }
359
360
    /**
361
     * Устаналвивает имя параметра в роуетере, значение которого - имя менеджера workflow
362
     *
363
     * @param string $workflowManagerNameRouterParam
364
     *
365
     * @return $this
366
     */
367
    public function setWorkflowManagerNameRouterParam($workflowManagerNameRouterParam)
368
    {
369
        $this->workflowManagerNameRouterParam = $workflowManagerNameRouterParam;
370
371
        return $this;
372
    }
373
374
    /**
375
     * Имя параметра в роуетере, значение которого имя вызываемого действия
376
     *
377
     * @return string
378
     */
379
    public function getWorkflowActionNameRouterParam()
380
    {
381
        return $this->workflowActionNameRouterParam;
382
    }
383
384
    /**
385
     * Устанавливает имя параметра в роуетере, значение которого - имя вызываемого действия
386
     *
387
     * @param string $workflowActionNameRouterParam
388
     *
389
     * @return $this
390
     */
391
    public function setWorkflowActionNameRouterParam($workflowActionNameRouterParam)
392
    {
393
        $this->workflowActionNameRouterParam = $workflowActionNameRouterParam;
394
395
        return $this;
396
    }
397
398
    /**
399
     * Имя параметра в роуетере, значение которого имя workflow
400
     *
401
     * @return string
402
     */
403
    public function getWorkflowNameRouterParam()
404
    {
405
        return $this->workflowNameRouterParam;
406
    }
407
408
    /**
409
     * Устанавливает имя параметра в роуетере, значение которого имя workflow
410
     *
411
     * @param string $workflowNameRouterParam
412
     *
413
     * @return $this
414
     */
415
    public function setWorkflowNameRouterParam($workflowNameRouterParam)
416
    {
417
        $this->workflowNameRouterParam = $workflowNameRouterParam;
418
419
        return $this;
420
    }
421
422
    /**
423
     * Имя параметра в роуетере, значение которого id запущенного процесса
424
     *
425
     * @return string
426
     */
427
    public function getEntryIdRouterParam()
428
    {
429
        return $this->entryIdRouterParam;
430
    }
431
432
    /**
433
     * Устанавливает имя параметра в роуетере, значение которого id запущенного процесса
434
     *
435
     * @param string $entryIdRouterParam
436
     *
437
     * @return $this
438
     */
439
    public function setEntryIdRouterParam($entryIdRouterParam)
440
    {
441
        $this->entryIdRouterParam = (string)$entryIdRouterParam;
442
443
        return $this;
444
    }
445
446
447
    /**
448
     * Проверка метаданных
449
     *
450
     * @throws Exception\InvalidMetadataException
451
     */
452
    public function validate()
453
    {
454
        if ($this->isWorkflowDispatch() && null === $this->getWorkflowRunType()) {
455
            $errMsg = 'workflowRunType not specified';
456
            throw new Exception\InvalidMetadataException($errMsg);
457
        }
458
459
        if ($this->isFlagRunPrepareData()) {
460
            if (null === $this->getPrepareDataMethod()) {
461
                $errMsg = 'prepareDataMethod not specified';
462
                throw new Exception\InvalidMetadataException($errMsg);
463
            }
464
            if (null === $this->getPrepareDataMethod()) {
465
                $errMsg = 'prepareDataMethod not specified';
466
                throw new Exception\InvalidMetadataException($errMsg);
467
            }
468
        }
469
470
        if ($this->getFlagHasConditions()) {
471
            if (0 === count($this->getConditions())) {
472
                $errMsg = 'empty conditions';
473
                throw new Exception\InvalidMetadataException($errMsg);
474
            }
475
476
            foreach ($this->getConditions() as $condition) {
477
                $condition->validate();
478
            }
479
        }
480
481
        $workflowManagerNameRouterParam = $this->getWorkflowManagerNameRouterParam();
482
        $workflowManagerNameRouterParam = trim($workflowManagerNameRouterParam);
483
        if (empty($workflowManagerNameRouterParam) || null === $workflowManagerNameRouterParam) {
484
            $errMsg = 'Invalid workflowManagerNameRouterParam';
485
            throw new Exception\InvalidMetadataException($errMsg);
486
        }
487
488
        $workflowActionNameRouterParam = $this->getWorkflowActionNameRouterParam();
489
        $workflowActionNameRouterParam = trim($workflowActionNameRouterParam);
490
        if (empty($workflowActionNameRouterParam) || null === $workflowActionNameRouterParam) {
491
            $errMsg = 'Invalid workflowActionNameRouterParam';
492
            throw new Exception\InvalidMetadataException($errMsg);
493
        }
494
495 View Code Duplication
        if (static::WORKFLOW_RUN_INITIALIZE === $this->getWorkflowRunType()) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
496
            $workflowNameRouterParam = $this->getWorkflowNameRouterParam();
497
            $workflowNameRouterParam = trim($workflowNameRouterParam);
498
            if (empty($workflowNameRouterParam) || null === $workflowNameRouterParam) {
499
                $errMsg = 'Invalid workflowNameRouterParam';
500
                throw new Exception\InvalidMetadataException($errMsg);
501
            }
502
        }
503
504 View Code Duplication
        if (static::WORKFLOW_RUN_TYPE_DO_ACTION === $this->getWorkflowRunType()) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
505
            $entryIdRouterParam = $this->getEntryIdRouterParam();
506
            $entryIdRouterParam = trim($entryIdRouterParam);
507
            if (empty($entryIdRouterParam) || null === $entryIdRouterParam) {
508
                $errMsg = 'Invalid entryIdRouterParam';
509
                throw new Exception\InvalidMetadataException($errMsg);
510
            }
511
        }
512
    }
513
}
514