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 ( e1de2b...8de3c6 )
by David
11:04
created

Properties::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
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\Context;
16
17
/**
18
 * Class Properties
19
 */
20
class Properties
21
{
22
    const NAMESPACE_DEFAULT = 'default';
23
24
    const NAMESPACE_ENTITY = 'entity';
25
26
    /**
27
     * Properties.
28
     *
29
     * @var array
30
     */
31
    private $properties = [];
32
33
    /**
34
     * Properties constructor.
35
     *
36
     * @param array $properties Properties.
37
     */
38
    public function __construct(array $properties = null)
39
    {
40
        $this->properties = $properties;
0 ignored issues
show
Documentation Bug introduced by
It seems like $properties can be null. However, the property $properties is declared as array. Maybe change the type of the property to array|null or add a type check?

Our type inference engine has found an assignment of a scalar value (like a string, an integer or null) to a property which is an array.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property.

To type hint that a parameter can be either an array or null, you can set a type hint of array and a default value of null. The PHP interpreter will then accept both an array or null for that parameter.

function aContainsB(array $needle = null, array  $haystack) {
    if (!$needle) {
        return false;
    }

    return array_intersect($haystack, $needle) == $haystack;
}

The function can be called with either null or an array for the parameter $needle but will only accept an array as $haystack.

Loading history...
41
    }
42
43
    /**
44
     * Get properties.
45
     *
46
     * @param null|string $namespace Property namespace.
47
     *
48
     * @return array
49
     */
50
    public function getProperties(?string $namespace = null): array
51
    {
52
        if (!$namespace) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $namespace of type null|string 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...
53
            return $this->properties;
54
        }
55
56
        if (isset($this->properties[$namespace])) {
57
            return $this->properties[$namespace];
58
        }
59
60
        return array();
61
    }
62
63
    /**
64
     * Check if a property exists.
65
     *
66
     * @param string $propertyName Name of the property.
67
     * @param string $namespace    Property namespace.
68
     *
69
     * @return bool
70
     */
71
    public function hasProperty(string $propertyName, string $namespace = self::NAMESPACE_DEFAULT): bool
72
    {
73
        if (!array_key_exists($namespace, $this->properties)) {
74
            return false;
75
        }
76
77
        return array_key_exists($propertyName, $this->properties[self::NAMESPACE_DEFAULT]);
78
    }
79
80
    /**
81
     * Set a property value.
82
     *
83
     * @param string $propertyName Name of the property.
84
     * @param string $value        Value of the property.
85
     * @param string $namespace    Property namespace.
86
     *
87
     * @return Properties
88
     */
89
    public function setProperty(string $propertyName, $value, string $namespace = self::NAMESPACE_DEFAULT): self
90
    {
91
        $this->properties[$namespace][$propertyName] = $value;
92
93
        return $this;
94
    }
95
96
    /**
97
     * Get the property value. If property does not exist, null is returned.
98
     *
99
     * @param string $propertyName Name of the property.
100
     * @param string $namespace    Property namespace.
101
     *
102
     * @return mixed
103
     */
104
    public function getProperty(string $propertyName, string $namespace = self::NAMESPACE_DEFAULT)
105
    {
106
        if (isset($this->properties[$namespace][$propertyName])) {
107
            return $this->properties[$namespace][$propertyName];
108
        }
109
110
        return null;
111
    }
112
}
113