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

OnClearEventArgs   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 0
dl 0
loc 30
ccs 0
cts 21
cp 0
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 2
A getDocumentManager() 0 6 1
A getDocumentClass() 0 4 1
A clearsAllDocuments() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\ODM\MongoDB\Event;
6
7
use Doctrine\Common\Persistence\Event\OnClearEventArgs as BaseOnClearEventArgs;
8
use Doctrine\ODM\MongoDB\DocumentManager;
9
use const E_USER_DEPRECATED;
10
use function assert;
11
use function sprintf;
12
use function trigger_error;
13
14
/**
15
 * Provides event arguments for the onClear event.
16
 *
17
 * @final
18
 */
19
class OnClearEventArgs extends BaseOnClearEventArgs
20
{
21
    public function __construct($objectManager, $entityClass = null)
22
    {
23
        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
        parent::__construct($objectManager, $entityClass);
27
    }
28
29
    public function getDocumentManager() : DocumentManager
30
    {
31
        $dm = $this->getObjectManager();
32
        assert($dm instanceof DocumentManager);
33
        return $dm;
34
    }
35
36
    public function getDocumentClass() : ?string
37
    {
38
        return $this->getEntityClass();
39
    }
40
41
    /**
42
     * Returns whether this event clears all documents.
43
     */
44
    public function clearsAllDocuments() : bool
45
    {
46
        return $this->clearsAllEntities();
47
    }
48
}
49