Completed
Push — develop ( dfd31d...f6e11d )
by
unknown
25:04 queued 17:04
created

RepositoryEventsSubscriber::getSubscribedEvents()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
/**
3
 * YAWIK
4
 *
5
 * @filesource
6
 * @copyright (c) 2013 - 2016 Cross Solution (http://cross-solution.de)
7
 * @license   MIT
8
 */
9
10
namespace Core\Repository\DoctrineMongoODM\Event;
11
12
use Doctrine\Common\EventSubscriber;
13
use Zend\ServiceManager\ServiceLocatorInterface;
14
use Core\Repository\RepositoryInterface;
15
16
class RepositoryEventsSubscriber implements EventSubscriber
17
{
18
    const postConstruct = 'postRepositoryConstruct';
0 ignored issues
show
Coding Style introduced by
This class constant is not uppercase (expected POSTCONSTRUCT).
Loading history...
19
    
20
    /**
21
     * @var ServiceLocatorInterface
22
     */
23
    protected $services;
24
    
25
    /**
26
     * @param ServiceLocatorInterface $serviceLocator
27
     */
28
    public function __construct(ServiceLocatorInterface $serviceLocator)
29
    {
30
        $this->services = $serviceLocator;
31
    }
32
    
33
    public function postRepositoryConstruct($eventArgs)
34
    {
35
        $repo = $eventArgs->getRepository();
36
        if ($repo instanceof RepositoryInterface) {
37
            $documentName = $repo->getDocumentName();
38
            $entity = new $documentName();
39
            //if ($entity instanceof ) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
60% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
40
            //    $entity->setRepository($repo);
0 ignored issues
show
Unused Code Comprehensibility introduced by
75% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
41
            //}
42
            $repo->setEntityPrototype($entity);
43
            $repo->init($this->services);
44
        }
45
    }
46
    
47
    /**
48
     * @see \Doctrine\Common\EventSubscriber::getSubscribedEvents()
49
     */
50
    public function getSubscribedEvents()
51
    {
52
        return array(self::postConstruct);
53
    }
54
    
55
    /**
56
     * @param ServiceLocatorInterface $serviceLocator
57
     * @return RepositoryEventsSubscriber
58
     */
59
    public static function factory(ServiceLocatorInterface $serviceLocator)
60
    {
61
        return new static($serviceLocator);
62
    }
63
}
64