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.

DataTransferObjectError   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 10
lcom 0
cbo 0
dl 0
loc 59
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A unknownProperties() 0 6 1
A invalidTypes() 0 8 2
A invalidTypeMessage() 0 30 5
A uninitialized() 0 4 1
A immutable() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Spatie\DataTransferObject;
6
7
use TypeError;
8
9
class DataTransferObjectError extends TypeError
10
{
11
    public static function unknownProperties(array $properties, string $className): DataTransferObjectError
12
    {
13
        $propertyNames = implode('`, `', $properties);
14
15
        return new self("Public properties `{$propertyNames}` not found on {$className}");
0 ignored issues
show
Unused Code introduced by
The call to DataTransferObjectError::__construct() has too many arguments starting with "Public properties `{$pr... found on {$className}".

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
16
    }
17
18
    public static function invalidTypes(array $invalidTypes): DataTransferObjectError
19
    {
20
        $msg = count($invalidTypes) > 1
21
            ? "The following invalid types were encountered:\n" . implode("\n", $invalidTypes) . "\n"
22
            : "Invalid type: {$invalidTypes[0]}.";
23
24
        throw new self($msg);
0 ignored issues
show
Unused Code introduced by
The call to DataTransferObjectError::__construct() has too many arguments starting with $msg.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
25
    }
26
27
    public static function invalidTypeMessage(
28
        string $class,
29
        string $field,
30
        array $expectedTypes,
31
        $value
32
    ): string {
33
        $currentType = gettype($value);
34
35
        if ($value === null) {
36
            $value = 'null';
37
        }
38
39
        if (is_object($value)) {
40
            $value = get_class($value);
41
        }
42
43
        if (is_array($value)) {
44
            $value = 'array';
45
        }
46
47
        $expectedTypes = implode(', ', $expectedTypes);
48
49
        if ($value === $currentType) {
50
            $instead = "instead got value `{$value}`.";
51
        } else {
52
            $instead = "instead got value `{$value}`, which is {$currentType}.";
53
        }
54
55
        return "expected `{$class}::{$field}` to be of type `{$expectedTypes}`, {$instead}";
56
    }
57
58
    public static function uninitialized(string $class, string $field): DataTransferObjectError
59
    {
60
        return new self("Non-nullable property `{$class}::{$field}` has not been initialized.");
0 ignored issues
show
Unused Code introduced by
The call to DataTransferObjectError::__construct() has too many arguments starting with "Non-nullable property `... not been initialized.".

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
61
    }
62
63
    public static function immutable(string $property): DataTransferObjectError
64
    {
65
        return new self("Cannot change the value of property {$property} on an immutable data transfer object");
0 ignored issues
show
Unused Code introduced by
The call to DataTransferObjectError::__construct() has too many arguments starting with "Cannot change the value...e data transfer object".

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
66
    }
67
}
68