Completed
Push — master ( 91cd10...dc7d5f )
by Brent
09:16
created

ValueObjectException   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 0
dl 0
loc 29
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A unknownPublicProperty() 0 4 1
A invalidType() 0 16 3
A uninitialisedProperty() 0 4 1
1
<?php
2
3
namespace Spatie\ValueObject;
4
5
use Exception;
6
7
class ValueObjectException extends Exception
8
{
9
    public static function unknownPublicProperty(string $name, string $className): ValueObjectException
10
    {
11
        return new self("Public property {$name} not found on {$className}");
12
    }
13
14
    public static function invalidType(
15
        string $propertyName,
16
        string $className,
17
        string $expectedType,
18
        $value
19
    ): ValueObjectException {
20
        if ($value === null) {
21
            $value = 'null';
22
        }
23
24
        if (is_object($value)) {
25
            $value = get_class($value);
26
        }
27
28
        return new self("Invalid type: expected {$className}::{$propertyName} to be of type {$expectedType}; instead got value `{$value}`.");
29
    }
30
31
    public static function uninitialisedProperty(string $name): ValueObjectException
32
    {
33
        return new self("Non-nullable property `{$name}` has not been initialised.");
34
    }
35
}
36