Test Failed
Push — master ( 34c614...ede9b5 )
by Dawid
05:49
created

HydratorException   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 8
dl 0
loc 43
rs 10
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
3
namespace Igni\Storage\Exception;
4
5
use Igni\Storage\Hydration\Hydrator;
6
7
class HydratorException extends StorageException
8
{
9
    public static function forNonRegisteredHydrator(string $entityClass): HydratorException
10
    {
11
        return new self("Hydrator for entity ${entityClass} was not registered.");
12
    }
13
14
    public static function forUndefinedSchema(string $entity): HydratorException
15
    {
16
        return new self("Entity ${entity} has no schema attached. Please define schema first.");
17
    }
18
19
    public static function forNotSetStrategyArgument(string $argument): HydratorException
20
    {
21
        return new self("Strategy defines no value for argument ${argument}.");
22
    }
23
24
    public static function forMissingHydrateMethod(Hydrator $hydrator, string $property): HydratorException
25
    {
26
        $class = get_class($hydrator);
27
        return new self("Hydrator ${class} is missing hydration method for property ${property}.");
28
    }
29
30
    public static function forMissingExtractMethod(Hydrator $hydrator, string $property): HydratorException
31
    {
32
        $class = get_class($hydrator);
33
        return new self("Hydrator ${class} is missing extraction method for property ${property}.");
34
    }
35
36
    public static function forInvalidNamingStrategy(Hydrator $hydrator): HydratorException
37
    {
38
        $class = get_class($hydrator);
39
        return new self("Hydrator ${class} provides invalid naming strategy.");
40
    }
41
42
    public static function forMissingIdentity(string $entityClass): HydratorException
43
    {
44
        return new self("Cannot hydrate ${entityClass} its schema is missing valid identity.");
45
    }
46
47
    public static function forMissingProperty(string $entityClass, string $property): HydratorException
48
    {
49
        return new self("Trying to hydrate property `${property}`, seems like it does not exists in entity `${entityClass}`");
50
    }
51
}
52