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

HydratorException::__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\Hydrator;
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 Hydrator Exception
15
 *
16
 * @final
17
 */
18
class HydratorException 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 hydratorDirectoryNotWritable() : self
29
    {
30
        return new self('Your hydrator directory must be writable.');
31
    }
32
33
    public static function hydratorDirectoryRequired() : self
34
    {
35
        return new self('You must configure a hydrator directory. See docs for details.');
36
    }
37
38
    public static function hydratorNamespaceRequired() : self
39
    {
40
        return new self('You must configure a hydrator namespace. See docs for details');
41
    }
42
}
43