Completed
Push — master ( 09b86b...ba0798 )
by Andreas
20:05 queued 12s
created

PersistentCollectionException::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 0
cts 7
cp 0
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 3
crap 6
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 const E_USER_DEPRECATED;
10
use function sprintf;
11
use function trigger_error;
12
13
/**
14
 * MongoDB ODM PersistentCollection Exception.
15
 *
16
 * @final
17
 */
18
class PersistentCollectionException extends MongoDBException
19
{
20
    public function __construct($message = '', $code = 0, ?Throwable $previous = null)
21
    {
22
        if (self::class !== static::class) {
23
            @trigger_error(sprintf('The class "%s" extends "%s" which will be final in MongoDB ODM 2.0.', static::class, self::class), E_USER_DEPRECATED);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
24
        }
25
        parent::__construct($message, $code, $previous);
26
    }
27
28
    public static function directoryNotWritable() : self
29
    {
30
        return new self('Your PersistentCollection directory must be writable.');
31
    }
32
33
    public static function directoryRequired() : self
34
    {
35
        return new self('You must configure a PersistentCollection directory. See docs for details.');
36
    }
37
38
    public static function namespaceRequired() : self
39
    {
40
        return new self('You must configure a PersistentCollection namespace. See docs for details');
41
    }
42
43
    public static function invalidParameterTypeHint(
44
        string $className,
45
        string $methodName,
46
        string $parameterName,
47
        ?Throwable $previous = null
48
    ) : self {
49
        return new self(
50
            sprintf(
51
                'The type hint of parameter "%s" in method "%s" in class "%s" is invalid.',
52
                $parameterName,
53
                $methodName,
54
                $className
55
            ),
56
            0,
57
            $previous
58
        );
59
    }
60
61
    public static function invalidReturnTypeHint(string $className, string $methodName, ?Throwable $previous = null) : self
62
    {
63
        return new self(
64
            sprintf(
65
                'The return type of method "%s" in class "%s" is invalid.',
66
                $methodName,
67
                $className
68
            ),
69
            0,
70
            $previous
71
        );
72
    }
73
74
    public static function parentClassRequired(string $className, string $methodName) : self
75
    {
76
        return new self(
77
            sprintf(
78
                'The method "%s" in class "%s" defines a parent return type, but the class does not extend any class.',
79
                $methodName,
80
                $className
81
            )
82
        );
83
    }
84
85
    public static function ownerRequiredToLoadCollection() : self
86
    {
87
        return new self('Cannot load persistent collection without an owner.');
88
    }
89
}
90