Completed
Push — master ( faad46...c87772 )
by Brent
02:23
created

ValueObjectError::unknownPublicProperty()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

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