ValueObjectError   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 1
dl 0
loc 33
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A unknownProperties() 0 6 1
A invalidType() 0 18 4
A uninitialized() 0 4 1
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