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

MongoDB/Event/OnClassMetadataNotFoundEventArgs.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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