Completed
Push — master ( 1de9b7...830752 )
by Kristof
38:46 queued 24:09
created

VotingBundle/Services/RepositoryResolver.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
namespace Kunstmaan\VotingBundle\Services;
4
5
use Doctrine\ORM\EntityManager;
6
use Kunstmaan\VotingBundle\Event\Facebook\FacebookLikeEvent;
7
use Kunstmaan\VotingBundle\Event\Facebook\FacebookSendEvent;
8
use Kunstmaan\VotingBundle\Event\LinkedIn\LinkedInShareEvent;
9
use Kunstmaan\VotingBundle\Event\UpDown\DownVoteEvent;
10
use Kunstmaan\VotingBundle\Event\UpDown\UpVoteEvent;
11
12
/**
13
 * Helper class get repository for an event
14
 */
15
class RepositoryResolver
16
{
17
    /**
18
     * Entity manager
19
     */
20
    protected $em;
21
22
    /**
23
     * Constructor
24
     *
25
     * @param object $em entity manager
0 ignored issues
show
Consider making the type for parameter $em a bit more specific; maybe use EntityManager.
Loading history...
26
     */
27
    public function __construct(EntityManager $em)
28
    {
29
        $this->em = $em;
30
    }
31
32
    /**
33
     * Return repository for event
34
     *
35
     * @param Event $event event
36
     *
37
     * @return Repository
38
     */
39
    public function getRepositoryForEvent($event)
40
    {
41
        $repository = null;
42
43
        if ($event instanceof DownVoteEvent) {
44
            $repository = $this->getRepository('Kunstmaan\VotingBundle\Entity\UpDown\DownVote');
45
        }
46
47
        if ($event instanceof UpVoteEvent) {
48
            $repository = $this->getRepository('Kunstmaan\VotingBundle\Entity\UpDown\UpVote');
49
        }
50
51
        if ($event instanceof LinkedInShareEvent) {
52
            $repository = $this->getRepository('Kunstmaan\VotingBundle\Entity\LinkedIn\LinkedInShare');
53
        }
54
55
        if ($event instanceof FacebookLikeEvent) {
56
            $repository = $this->getRepository('Kunstmaan\VotingBundle\Entity\Facebook\FacebookLike');
57
        }
58
59
        if ($event instanceof FacebookSendEvent) {
60
            $repository = $this->getRepository('Kunstmaan\VotingBundle\Entity\Facebook\FacebookSend');
61
        }
62
63
        return $repository;
64
    }
65
66
    /**
67
     * Return a repository By name
68
     *
69
     * @param string $name name
70
     *
71
     * @return Repository
72
     */
73
    protected function getRepository($name)
74
    {
75
        return $this->em->getRepository($name);
76
    }
77
}
78