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
Pull Request — master (#159)
by Roman
01:51
created

Alias::getName()   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 0
1
<?php declare(strict_types=1);
2
3
namespace OpenStack\Common\Resource;
4
5
/**
6
 * @package OpenStack\Common\Resource
7
 */
8
class Alias
9
{
10
    /**
11
     * @var bool
12
     */
13
    private $_isList;
14
15
    /**
16
     * @var string
17
     */
18
    private $_className;
19
20
    /**
21
     * @var string
22
     */
23
    private $_propertyName;
24
25
    /**
26
     * Alias constructor.
27
     *
28
     * @param string      $propertyName
29
     * @param string|null $className
30
     * @param bool        $list
31
     */
32
    public function __construct(string $propertyName, string $className = null, bool $list = false)
33
    {
34
        $this->_isList = $list;
35
        $this->_propertyName = $propertyName;
36
        $this->_className = (($className && class_exists($className)) ? $className : null);
0 ignored issues
show
Bug Best Practice introduced by
The expression $className of type null|string 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...
37
    }
38
39
    /**
40
     * @return string
41
     */
42
    public function getName()
43
    {
44
        return $this->_propertyName;
45
    }
46
47
    /**
48
     * @param ResourceInterface $resource
49
     * @param mixed             $value
50
     *
51
     * @return mixed
52
     */
53
    public function getValue(ResourceInterface $resource, $value)
54
    {
55
        $class = $this->_className;
56
57
        if ($value === null || !$class) {
58
            return $value;
59
        } elseif ($this->_isList && is_array($value)) {
60
            $array = [];
61
            foreach ($value as $subVal) {
62
                $array[] = $resource->model($class, $subVal);
63
            }
64
            return $array;
65
        } elseif ($class === \DateTimeImmutable::class) {
66
            return new \DateTimeImmutable($value);
67
        }
68
69
        return $resource->model($class, $value);
70
    }
71
}
72