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 — develop ( bab24d...a5be90 )
by David
13:57
created

Context::setPayload()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 10
rs 9.4285
cc 2
eloc 6
nc 2
nop 2
1
<?php
2
3
/**
4
 * Workflow library.
5
 *
6
 * @package    workflow
7
 * @author     David Molineus <[email protected]>
8
 * @copyright  2014-2017 netzmacht David Molineus
9
 * @license    LGPL 3.0 https://github.com/netzmacht/workflow
10
 * @filesource
11
 */
12
13
declare(strict_types=1);
14
15
namespace Netzmacht\Workflow\Flow;
16
17
use Netzmacht\Workflow\Data\ErrorCollection;
18
19
/**
20
 * Class Context provides extra information for a transition.
21
 *
22
 * @package Netzmacht\Workflow\Flow
23
 */
24
class Context
25
{
26
    const NAMESPACE_DEFAULT = 'default';
27
28
    const NAMESPACE_ENTITY = 'entity';
29
30
    /**
31
     * Properties which will be stored as state data.
32
     *
33
     * @var array
34
     */
35
    private $properties = array();
36
37
    /**
38
     * Transition payload.
39
     *
40
     * @var array
41
     */
42
    private $payload = array();
43
44
    /**
45
     * Error collection.
46
     *
47
     * @var ErrorCollection
48
     */
49
    private $errorCollection;
50
51
    /**
52
     * Construct.
53
     *
54
     * @param array                $properties      The properties to be stored.
55
     * @param array                $payload         The given parameters.
56
     * @param ErrorCollection|null $errorCollection Error collection.
57
     */
58
    public function __construct(array $properties = [], array $payload = [], ErrorCollection $errorCollection = null)
59
    {
60
        $this->properties      = $properties;
61
        $this->payload         = $payload;
62
        $this->errorCollection = $errorCollection ?: new ErrorCollection();
63
    }
64
65
    /**
66
     * Set a property value.
67
     *
68
     * @param string $name      Name of the property.
69
     * @param mixed  $value     Value of the property.
70
     * @param string $namespace Namespace the property belongs to.
71
     *
72
     * @return $this
73
     */
74
    public function setProperty(string $name, $value, string $namespace = self::NAMESPACE_DEFAULT): self
75
    {
76
        $this->properties[$namespace][$name] = $value;
77
78
        return $this;
79
    }
80
81
    /**
82
     * Get the property value.
83
     *
84
     * @param string $name      Property name.
85
     * @param string $namespace Namespace the property belongs to.
86
     *
87
     * @return mixed
88
     */
89
    public function getProperty(string $name, string $namespace = self::NAMESPACE_DEFAULT)
90
    {
91
        if ($this->hasProperty($name, $namespace)) {
92
            return $this->properties[$namespace][$name];
93
        }
94
95
        return null;
96
    }
97
98
    /**
99
     * Consider if property is set.
100
     *
101
     * @param string $name      Property name.
102
     * @param string $namespace Namespace the property belongs to.
103
     *
104
     * @return bool
105
     */
106
    public function hasProperty(string $name, string $namespace = self::NAMESPACE_DEFAULT): bool
107
    {
108
        return isset($this->properties[$namespace][$name]);
109
    }
110
111
    /**
112
     * Get all properties. If namespace isset only properties of a namespace.
113
     *
114
     * @param string $namespace Namespace the property belongs to.
115
     *
116
     * @return array
117
     */
118
    public function getProperties(?string $namespace = null): array
119
    {
120
        if (!$namespace) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $namespace of type string|null is loosely compared to false; this is ambiguous if the string can be empty. You might want to explicitly use === null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
121
            return $this->properties;
122
        }
123
124
        if (isset($this->properties[$namespace])) {
125
            return $this->properties[$namespace];
126
        }
127
128
        return array();
129
    }
130
131
    /**
132
     * Set a parameter.
133
     *
134
     * @param string $name      Param name.
135
     * @param mixed  $value     Param value.
136
     * @param string $namespace Namespace the param belongs to.
137
     *
138
     * @return $this
139
     */
140
    public function setParam(string $name, $value, string $namespace = self::NAMESPACE_DEFAULT): self
141
    {
142
        $this->payload[$namespace][$name] = $value;
143
144
        return $this;
145
    }
146
147
    /**
148
     * Consider if a param isset.
149
     *
150
     * @param string $name      Param name.
151
     * @param string $namespace Namespace the param belongs to.
152
     *
153
     * @return bool
154
     */
155
    public function hasParam(string $name, string $namespace = self::NAMESPACE_DEFAULT): bool
156
    {
157
        return isset($this->payload[$namespace][$name]);
158
    }
159
160
    /**
161
     * Get all params.
162
     *
163
     * If namespace is given only a specific namespace is returned. Otherwise all namespaces are returned.
164
     *
165
     * @param string|null $namespace Optional namespace.
166
     *
167
     * @return array
168
     */
169
    public function getPayload(?string $namespace = null): array
170
    {
171
        if ($namespace) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $namespace of type string|null is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
172
            if (isset($this->payload[$namespace])) {
173
                return $this->payload[$namespace];
174
            }
175
176
            return array();
177
        }
178
179
        return $this->payload;
180
    }
181
182
    /**
183
     * Get a param by name.
184
     *
185
     * @param string $name      Param name.
186
     * @param string $namespace Namespace the param belongs to.
187
     *
188
     * @return mixed
189
     */
190
    public function getParam(string $name, ?string $namespace = self::NAMESPACE_DEFAULT)
191
    {
192
        if ($this->hasParam($name, $namespace)) {
193
            return $this->payload[$namespace][$name];
194
        }
195
196
        return null;
197
    }
198
199
    /**
200
     * Set multiple params.
201
     *
202
     * @param array  $params    Array of params.
203
     * @param string $namespace Namespace the params belongs to.
204
     *
205
     * @return $this
206
     */
207
    public function setPayload(array $params, ?string $namespace = null): self
208
    {
209
        if ($namespace) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $namespace of type string|null is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
210
            $this->payload[$namespace] = $params;
211
        } else {
212
            $this->payload = $params;
213
        }
214
215
        return $this;
216
    }
217
218
    /**
219
     * Get error collection.
220
     *
221
     * @return ErrorCollection
222
     */
223
    public function getErrorCollection(): ErrorCollection
224
    {
225
        return $this->errorCollection;
226
    }
227
228
    /**
229
     * Add an error.
230
     *
231
     * @param string          $message    Error message.
232
     * @param array           $params     Params for the error message.
233
     * @param ErrorCollection $collection Option. Child collection of the error.
234
     *
235
     * @return self
236
     */
237
    public function addError(string $message, array $params = array(), ErrorCollection $collection = null): self
238
    {
239
        $this->errorCollection->addError($message, $params, $collection);
240
241
        return $this;
242
    }
243
244
    /**
245
     * Get a new context with an empty error collection.
246
     *
247
     * @return Context
248
     */
249
    public function withEmptyErrorCollection(): Context
250
    {
251
        return new Context($this->properties, $this->payload, new ErrorCollection());
252
    }
253
}
254