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
Pull Request — master (#56)
by Arthur
01:12
created

InvalidTypeDtoException::resolveExpectedTypes()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Spatie\DataTransferObject\Exceptions;
4
5
use TypeError;
6
use Spatie\DataTransferObject\Contracts\PropertyContract;
7
8
class InvalidTypeDtoException extends TypeError
9
{
10
    public function __construct(PropertyContract $property, $value)
11
    {
12
        $value = $this->resolveTypeFromValue($value);
13
14
        $expectedTypes = $this->resolveExpectedTypes($property);
15
16
        parent::__construct("Invalid type: expected {$property->getFqn()} to be of type {$expectedTypes}, instead got value `{$value}`.");
17
    }
18
19
    protected function resolveTypeFromValue($value): string
20
    {
21
        if ($value === null) {
22
            $value = 'null';
23
        }
24
25
        if (is_object($value)) {
26
            $value = get_class($value);
27
        }
28
29
        if (is_array($value)) {
30
            $value = 'array';
31
        }
32
33
        return $value;
34
    }
35
36
    protected function resolveExpectedTypes(PropertyContract $property)
37
    {
38
        return implode(', ', $property->getTypes());
39
    }
40
}
41