BrowseEventSubscriber   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 1
dl 0
loc 53
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getSubscribedEvents() 0 6 1
A loadClassMetadata() 0 20 3
1
<?php
2
3
namespace Victoire\Bundle\AnalyticsBundle\EventSubscriber;
4
5
use Doctrine\Common\EventSubscriber;
6
use Doctrine\ORM\Event\LoadClassMetadataEventArgs;
7
8
/**
9
 * This class listen Browse Event Entity changes.
10
 */
11
class BrowseEventSubscriber implements EventSubscriber
12
{
13
    protected $router;
14
    protected $userClass;
15
16
    /**
17
     * Constructor.
18
     *
19
     * @param string $userClass %victoire_core.user_class%
20
     */
21
    public function __construct($userClass)
22
    {
23
        $this->userClass = $userClass;
24
    }
25
26
    /**
27
     * bind to LoadClassMetadata method.
28
     *
29
     * @return string[] The subscribed events
30
     */
31
    public function getSubscribedEvents()
32
    {
33
        return [
34
            'loadClassMetadata',
35
        ];
36
    }
37
38
    /**
39
     * Insert enabled widgets in base widget DiscriminatorMap.
40
     *
41
     * @param LoadClassMetadataEventArgs $eventArgs
42
     */
43
    public function loadClassMetadata(LoadClassMetadataEventArgs $eventArgs)
44
    {
45
        $metadatas = $eventArgs->getClassMetadata();
46
47
        //Add author relation on BrowseEvent
48
        if ($this->userClass && $metadatas->name === 'Victoire\Bundle\AnalyticsBundle\Entity\BrowseEvent') {
0 ignored issues
show
Bug introduced by
The property name does not seem to exist in Doctrine\ORM\EntityManager.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
49
            $metadatas->mapManyToOne([
0 ignored issues
show
Bug introduced by
The method mapManyToOne() does not seem to exist on object<Doctrine\ORM\EntityManager>.

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
                'fieldName'    => 'author',
51
                'targetEntity' => $this->userClass,
52
                'cascade'      => ['persist'],
53
                'joinColumns'  => [
54
                    [
55
                        'name'                 => 'author_id',
56
                        'referencedColumnName' => 'id',
57
                        'onDelete'             => 'SET NULL',
58
                    ],
59
                ],
60
            ]);
61
        }
62
    }
63
}
64