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

DocumentNotFoundException   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 90%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 1
dl 0
loc 19
ccs 9
cts 10
cp 0.9
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 2
A documentNotFound() 0 8 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\ODM\MongoDB;
6
7
use Throwable;
8
use const E_USER_DEPRECATED;
9
use function json_encode;
10
use function sprintf;
11
use function trigger_error;
12
13
/**
14
 * Class for exception when encountering proxy object that has
15
 * an identifier that does not exist in the database.
16
 *
17
 * @final
18
 */
19
class DocumentNotFoundException extends MongoDBException
20
{
21 8
    public function __construct($message = '', $code = 0, ?Throwable $previous = null)
22
    {
23 8
        if (self::class !== static::class) {
24
            @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...
25
        }
26 8
        parent::__construct($message, $code, $previous);
27 8
    }
28
29 8
    public static function documentNotFound(string $className, $identifier) : self
30
    {
31 8
        return new self(sprintf(
32 8
            'The "%s" document with identifier %s could not be found.',
33 8
            $className,
34 8
            json_encode($identifier)
35
        ));
36
    }
37
}
38