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

OnClassMetadataNotFoundEventArgs::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2.0185

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 5
cts 6
cp 0.8333
rs 9.9666
c 0
b 0
f 0
cc 2
nc 2
nop 2
crap 2.0185
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\ODM\MongoDB\Event;
6
7
use Doctrine\ODM\MongoDB\DocumentManager;
8
use Doctrine\ODM\MongoDB\Mapping\ClassMetadata;
9
use const E_USER_DEPRECATED;
10
use function sprintf;
11
use function trigger_error;
12
13
/**
14
 * Class that holds event arguments for a `onClassMetadataNotFound` event.
15
 *
16
 * This object is mutable by design, allowing callbacks having access to it to set the
17
 * found metadata in it, and therefore "cancelling" a `onClassMetadataNotFound` event
18
 *
19
 * @final
20
 */
21
class OnClassMetadataNotFoundEventArgs extends ManagerEventArgs
22
{
23
    /** @var string */
24
    private $className;
25
26
    /** @var ClassMetadata|null */
27
    private $foundMetadata;
28
29 4
    public function __construct(string $className, DocumentManager $dm)
30
    {
31 4
        if (self::class !== static::class) {
32
            @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...
33
        }
34 4
        $this->className = $className;
35
36 4
        parent::__construct($dm);
37 4
    }
38
39 4
    public function setFoundMetadata(?ClassMetadata $classMetadata = null)
40
    {
41 4
        $this->foundMetadata = $classMetadata;
42 4
    }
43
44
    /**
45
     * @return ClassMetadata|null
46
     */
47 4
    public function getFoundMetadata()
48
    {
49 4
        return $this->foundMetadata;
50
    }
51
52
    /**
53
     * Retrieve class name for which a failed metadata fetch attempt was executed
54
     *
55
     * @return string
56
     */
57 4
    public function getClassName()
58
    {
59 4
        return $this->className;
60
    }
61
}
62