ValueObjectError::invalidType()   A
last analyzed

Complexity

Conditions 4
Paths 8

Size

Total Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 18
rs 9.6666
c 0
b 0
f 0
cc 4
nc 8
nop 2
1
<?php
2
3
namespace Spatie\ValueObject;
4
5
use TypeError;
6
7
class ValueObjectError extends TypeError
8
{
9
    public static function unknownProperties(array $properties, string $className): ValueObjectError
10
    {
11
        $propertyNames = implode('`, `', $properties);
12
13
        return new self("Public properties `{$propertyNames}` not found on {$className}");
0 ignored issues
show
Unused Code introduced by
The call to ValueObjectError::__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...
14
    }
15
16
    public static function invalidType(Property $property, $value): ValueObjectError
17
    {
18
        if ($value === null) {
19
            $value = 'null';
20
        }
21
22
        if (is_object($value)) {
23
            $value = get_class($value);
24
        }
25
26
        if (is_array($value)) {
27
            $value = 'array';
28
        }
29
30
        $expectedTypes = implode(', ', $property->getTypes());
31
32
        return new self("Invalid type: expected {$property->getFqn()} to be of type {$expectedTypes}, instead got value `{$value}`.");
0 ignored issues
show
Unused Code introduced by
The call to ValueObjectError::__construct() has too many arguments starting with "Invalid type: expected ... got value `{$value}`.".

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...
33
    }
34
35
    public static function uninitialized(Property $property): ValueObjectError
36
    {
37
        return new self("Non-nullable property {$property->getFqn()} has not been initialized.");
0 ignored issues
show
Unused Code introduced by
The call to ValueObjectError::__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...
38
    }
39
}
40