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

DispatchConditionMetadata::setHandler()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 6
rs 9.4285
c 1
b 0
f 0
cc 2
eloc 3
nc 2
nop 1
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
/**
9
 * Interface MetadataInterface
10
 *
11
 * @package OldTown\Workflow\ZF2\Dispatch\Metadata
12
 */
13
class DispatchConditionMetadata
14
{
15
    /**
16
     * @var string
17
     */
18
    const CONDITION_RUN_TYPE_SERVICE = 'service';
19
20
    /**
21
     * @var string
22
     */
23
    const CONDITION_RUN_TYPE_METHOD = 'method';
24
25
    /**
26
     * Разрешенные типы запуска workflow
27
     *
28
     * @var array
29
     */
30
    protected $allowConditionRunType = [
31
        self::CONDITION_RUN_TYPE_SERVICE => self::CONDITION_RUN_TYPE_SERVICE,
32
        self::CONDITION_RUN_TYPE_METHOD => self::CONDITION_RUN_TYPE_METHOD
33
    ];
34
35
    /**
36
     * Тип запуска обработчика проверки условий
37
     *
38
     * @var string
39
     */
40
    protected $type;
41
42
    /**
43
     * Определяет обработчик для провекри условий
44
     *
45
     * @var string
46
     *
47
     */
48
    protected $handler;
49
50
    /**
51
     * Параметры обработчика
52
     *
53
     * @var array
54
     */
55
    protected $params = [];
56
57
    /**
58
     * @param       $type
59
     * @param       $handler
60
     * @param array $params
61
     */
62
    public function __construct($type, $handler, array $params = [])
63
    {
64
        $this->setType($type);
65
        $this->setHandler($handler);
66
        $this->setParams($params);
67
    }
68
69
    /**
70
     * Тип запуска обработчика проверки условий
71
     *
72
     * @return string
73
     */
74
    public function getType()
75
    {
76
        return $this->type;
77
    }
78
79
    /**
80
     * Устанавливает тип запуска обработчика проверки условий
81
     *
82
     * @param string $type
83
     *
84
     * @return $this
85
     */
86 View Code Duplication
    public function setType($type)
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...
87
    {
88
        if (!array_key_exists($type, $this->allowConditionRunType)) {
89
            $errMsg = sprintf('Not allowed type %s', $type);
90
            throw new Exception\InvalidMetadataException($errMsg);
91
        }
92
        $this->type = $type;
93
94
        return $this;
95
    }
96
97
    /**
98
     * Определяет обработчик для провекри условий
99
     *
100
     * @return string
101
     */
102
    public function getHandler()
103
    {
104
        return $this->handler;
105
    }
106
107
    /**
108
     * Устанавливает обработчик для провекри условий
109
     *
110
     * @param string $handler
111
     *
112
     * @return $this
113
     */
114
    public function setHandler($handler = null)
115
    {
116
        $this->handler = null !== $handler ? (string)$handler: $handler;
117
118
        return $this;
119
    }
120
121
    /**
122
     * @return array
123
     */
124
    public function getParams()
125
    {
126
        return $this->params;
127
    }
128
129
    /**
130
     * @param array $params
131
     *
132
     * @return $this
133
     */
134
    public function setParams(array $params = [])
135
    {
136
        $this->params = $params;
137
138
        return $this;
139
    }
140
141
    /**
142
     *
143
     * @throws Exception\InvalidMetadataException
144
     */
145
    public function validate()
146
    {
147
        if (null === $this->getType()) {
148
            $errMsg = 'Condition run type not specified';
149
            throw new Exception\InvalidMetadataException($errMsg);
150
        }
151
152
153
        $handler = $this->getHandler();
154
        $handler = trim($handler);
155
        if (empty($handler) || null === $handler) {
156
            $errMsg = 'Condition handler not specified';
157
            throw new Exception\InvalidMetadataException($errMsg);
158
        }
159
    }
160
}
161