Completed
Pull Request — master (#2076)
by Olivier
01:54
created

HydratorException   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 71.43%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 1
dl 0
loc 40
ccs 15
cts 21
cp 0.7143
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A hydratorDirectoryNotWritable() 0 4 1
A hydratorDirectoryRequired() 0 4 1
A hydratorNamespaceRequired() 0 4 1
A associationTypeMismatch() 0 10 1
A associationItemTypeMismatch() 0 11 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\ODM\MongoDB\Hydrator;
6
7
use Doctrine\ODM\MongoDB\MongoDBException;
8
use function sprintf;
9
10
/**
11
 * MongoDB ODM Hydrator Exception
12
 */
13
final class HydratorException extends MongoDBException
14
{
15
    public static function hydratorDirectoryNotWritable() : self
16
    {
17
        return new self('Your hydrator directory must be writable.');
18
    }
19
20
    public static function hydratorDirectoryRequired() : self
21
    {
22
        return new self('You must configure a hydrator directory. See docs for details.');
23
    }
24
25
    public static function hydratorNamespaceRequired() : self
26
    {
27
        return new self('You must configure a hydrator namespace. See docs for details');
28
    }
29
30 4
    public static function associationTypeMismatch(string $className, string $fieldName, string $expectedType, string $actualType)
31
    {
32 4
        return new self(sprintf(
33 4
            'Expected association for field "%s" in document of type "%s" to be of type "%s", "%s" received.',
34 4
            $fieldName,
35 4
            $className,
36 4
            $expectedType,
37 4
            $actualType
38
        ));
39
    }
40
41 2
    public static function associationItemTypeMismatch(string $className, string $fieldName, $key, string $expectedType, string $actualType)
42
    {
43 2
        return new self(sprintf(
44 2
            'Expected association item with key "%s" for field "%s" in document of type "%s" to be of type "%s", "%s" received.',
45 2
            $key,
46 2
            $fieldName,
47 2
            $className,
48 2
            $expectedType,
49 2
            $actualType
50
        ));
51
    }
52
}
53