Completed
Push — master ( 26ecbc...8c0c5d )
by Maciej
14s
created

PersistentCollectionException   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 1
dl 0
loc 64
ccs 0
cts 55
cp 0
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A directoryNotWritable() 0 4 1
A directoryRequired() 0 4 1
A namespaceRequired() 0 4 1
A invalidParameterTypeHint() 0 17 1
A invalidReturnTypeHint() 0 12 1
A parentClassRequired() 0 10 1
A ownerRequiredToLoadCollection() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\ODM\MongoDB\PersistentCollection;
6
7
use Doctrine\ODM\MongoDB\MongoDBException;
8
use Throwable;
9
use function sprintf;
10
11
/**
12
 * MongoDB ODM PersistentCollection Exception.
13
 */
14
class PersistentCollectionException extends MongoDBException
15
{
16
    public static function directoryNotWritable() : self
17
    {
18
        return new self('Your PersistentCollection directory must be writable.');
19
    }
20
21
    public static function directoryRequired() : self
22
    {
23
        return new self('You must configure a PersistentCollection directory. See docs for details.');
24
    }
25
26
    public static function namespaceRequired() : self
27
    {
28
        return new self('You must configure a PersistentCollection namespace. See docs for details');
29
    }
30
31
    public static function invalidParameterTypeHint(
32
        string $className,
33
        string $methodName,
34
        string $parameterName,
35
        ?Throwable $previous = null
36
    ) : self {
37
        return new self(
38
            sprintf(
39
                'The type hint of parameter "%s" in method "%s" in class "%s" is invalid.',
40
                $parameterName,
41
                $methodName,
42
                $className
43
            ),
44
            0,
45
            $previous
46
        );
47
    }
48
49
    public static function invalidReturnTypeHint(string $className, string $methodName, ?Throwable $previous = null) : self
50
    {
51
        return new self(
52
            sprintf(
53
                'The return type of method "%s" in class "%s" is invalid.',
54
                $methodName,
55
                $className
56
            ),
57
            0,
58
            $previous
59
        );
60
    }
61
62
    public static function parentClassRequired(string $className, string $methodName) : self
63
    {
64
        return new self(
65
            sprintf(
66
                'The method "%s" in class "%s" defines a parent return type, but the class does not extend any class.',
67
                $methodName,
68
                $className
69
            )
70
        );
71
    }
72
73
    public static function ownerRequiredToLoadCollection() : self
74
    {
75
        return new self('Cannot load persistent collection without an owner.');
76
    }
77
}
78