Completed
Push — master ( a28248...4f4a60 )
by Roni
07:13
created

ServiceContainerGetterMethods   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 74
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 8
Bugs 0 Features 3
Metric Value
wmc 9
c 8
b 0
f 3
lcom 1
cbo 2
dl 0
loc 74
rs 10

9 Methods

Rating   Name   Duplication   Size   Complexity  
getContainer() 0 1 ?
A getCommonResolver() 0 4 1
A getService() 0 4 1
A getRequest() 0 8 2
A getEntityEventResolver() 0 4 1
A getParameter() 0 4 1
A getKernel() 0 4 1
A isDebug() 0 4 1
A getDoctrineEventsList() 0 5 1
1
<?php
2
3
/*
4
 * This file is part of the XiideaEasyAuditBundle package.
5
 *
6
 * (c) Xiidea <http://www.xiidea.net>
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace Xiidea\EasyAuditBundle\Traits;
13
14
trait ServiceContainerGetterMethods
15
{
16
17
    /**
18
     * @throws \Exception
19
     * @return \Symfony\Component\DependencyInjection\ContainerInterface
20
     */
21
    protected abstract function getContainer();
22
23
    /**
24
     * @return \Xiidea\EasyAuditBundle\Resolver\EventResolverInterface
25
     */
26
    public function getCommonResolver()
27
    {
28
        return $this->getService($this->getParameter('resolver'));
29
    }
30
31
32
    public function getService($serviceName)
33
    {
34
        return $this->getContainer()->get($serviceName);
35
    }
36
37
    /**
38
     * @return boolean|\Symfony\Component\HttpFoundation\Request
39
     */
40
    public function getRequest()
41
    {
42
        try {
43
            return $this->getService('request_stack')->getCurrentRequest();
44
        } catch (\Exception $e) {
45
            return false;
46
        }
47
    }
48
49
    /**
50
     * @return \Xiidea\EasyAuditBundle\Resolver\EventResolverInterface
51
     */
52
    public function getEntityEventResolver()
53
    {
54
        return $this->getService($this->getParameter('entity_event_resolver'));
55
    }
56
57
    /**
58
     * @param string $parameter
59
     * @return mixed
60
     */
61
    public function getParameter($parameter)
62
    {
63
        return $this->getContainer()->getParameter('xiidea.easy_audit.'.$parameter);
64
    }
65
66
    /**
67
     * @return \Symfony\Component\HttpKernel\KernelInterface
68
     */
69
    public function getKernel()
70
    {
71
        return $this->getService('kernel');
72
    }
73
74
    /**
75
     * @return boolean
76
     */
77
    public function isDebug()
78
    {
79
        return $this->getKernel()->isDebug();
80
    }
81
82
    public function getDoctrineEventsList()
83
    {
84
        $reflectionClass = new \ReflectionClass('Xiidea\EasyAuditBundle\Events\DoctrineEvents');
85
        return  $reflectionClass->getConstants();
86
    }
87
}
88