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:42 queued 39s
created

InvalidTypeDtoException   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 12
dl 0
loc 31
rs 10
c 0
b 0
f 0
wmc 6

3 Methods

Rating   Name   Duplication   Size   Complexity  
A resolveExpectedTypes() 0 3 1
A __construct() 0 7 1
A resolveTypeFromValue() 0 15 4
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