MediaEventSubscriber   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 1
dl 0
loc 29
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getSubscribedEvents() 0 11 1
A recomputeSingleEntityChangeSet() 0 9 1
A getMedia() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Sonata Project package.
7
 *
8
 * (c) Thomas Rabaix <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Sonata\MediaBundle\Listener\ODM;
15
16
use Doctrine\Common\EventArgs;
17
use Doctrine\ODM\MongoDB\Events;
18
use Sonata\MediaBundle\Listener\BaseMediaEventSubscriber;
19
20
/**
21
 * @final since sonata-project/media-bundle 3.21.0
22
 */
23
class MediaEventSubscriber extends BaseMediaEventSubscriber
24
{
25
    public function getSubscribedEvents()
26
    {
27
        return [
28
            Events::prePersist,
29
            Events::preUpdate,
30
            Events::preRemove,
31
            Events::postUpdate,
32
            Events::postRemove,
33
            Events::postPersist,
34
        ];
35
    }
36
37
    protected function recomputeSingleEntityChangeSet(EventArgs $args): void
38
    {
39
        $em = $args->getDocumentManager();
0 ignored issues
show
Bug introduced by
The method getDocumentManager() does not seem to exist on object<Doctrine\Common\EventArgs>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
40
41
        $em->getUnitOfWork()->recomputeSingleDocumentChangeSet(
42
            $em->getClassMetadata(\get_class($args->getDocument())),
0 ignored issues
show
Bug introduced by
The method getDocument() does not seem to exist on object<Doctrine\Common\EventArgs>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
43
            $args->getDocument()
0 ignored issues
show
Bug introduced by
The method getDocument() does not seem to exist on object<Doctrine\Common\EventArgs>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
44
        );
45
    }
46
47
    protected function getMedia(EventArgs $args)
48
    {
49
        return $args->getDocument();
0 ignored issues
show
Bug introduced by
The method getDocument() does not seem to exist on object<Doctrine\Common\EventArgs>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
50
    }
51
}
52