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 — master ( a6e2fd...77480b )
by Jamie
12s
created

Alias::getValue()   B

Complexity

Conditions 7
Paths 5

Size

Total Lines 16
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 16
rs 8.2222
c 0
b 0
f 0
cc 7
eloc 11
nc 5
nop 2
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 string
12
     */
13
    public $propertyName;
14
15
    /**
16
     * @var bool
17
     */
18
    private $isList;
19
20
    /**
21
     * @var string
22
     */
23
    private $className;
24
25
    /**
26
     * @param string      $propertyName A name of the property in target resource class
27
     * @param string|null $className    A class name for the property value
28
     * @param bool        $list         Whether value of the property should be treated as a list or not
29
     */
30
    public function __construct(string $propertyName, string $className = null, bool $list = false)
31
    {
32
        $this->isList = $list;
33
        $this->propertyName = $propertyName;
34
        $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...
35
    }
36
37
    /**
38
     * @param ResourceInterface $resource
39
     * @param mixed             $value
40
     *
41
     * @return mixed
42
     */
43
    public function getValue(ResourceInterface $resource, $value)
44
    {
45
        if ($value === null || !$this->className) {
46
            return $value;
47
        } elseif ($this->isList && is_array($value)) {
48
            $array = [];
49
            foreach ($value as $subVal) {
50
                $array[] = $resource->model($this->className, $subVal);
51
            }
52
            return $array;
53
        } elseif ($this->className === \DateTimeImmutable::class) {
54
            return new \DateTimeImmutable($value);
55
        }
56
57
        return $resource->model($this->className, $value);
58
    }
59
}
60