Completed
Push — master ( 3f57f7...bacaac )
by Brent
33:36 queued 02:38
created

ValueObjectException::uninitialisedProperty()   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 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
        if (is_array($value)) {
29
            $value = 'array';
30
        }
31
32
        return new self("Invalid type: expected {$className}::{$propertyName} to be of type {$expectedType}; instead got value `{$value}`.");
33
    }
34
35
    public static function uninitialisedProperty(string $name): ValueObjectException
36
    {
37
        return new self("Non-nullable property `{$name}` has not been initialised.");
38
    }
39
}
40