Completed
Push — master ( a7cf71...06c6ea )
by Craig
06:43
created

AbstractLinkContainer::setTranslator()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Routes.
4
 *
5
 * @copyright Zikula contributors (Zikula)
6
 * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License
7
 * @author Zikula contributors <[email protected]>.
8
 * @link http://www.zikula.org
9
 * @link http://zikula.org
10
 * @version Generated by ModuleStudio 0.7.0 (http://modulestudio.de).
11
 */
12
13
namespace Zikula\RoutesModule\Container\Base;
14
15
use Symfony\Component\Routing\RouterInterface;
16
use Zikula\Common\Translator\TranslatorInterface;
17
use Zikula\Common\Translator\TranslatorTrait;
18
use Zikula\Core\Doctrine\EntityAccess;
19
use Zikula\Core\LinkContainer\LinkContainerInterface;
20
use Zikula\PermissionsModule\Api\PermissionApi;
21
use Zikula\UsersModule\Api\CurrentUserApi;
22
use Zikula\RoutesModule\Helper\ControllerHelper;
23
24
/**
25
 * This is the link container service implementation class.
26
 */
27
abstract class AbstractLinkContainer implements LinkContainerInterface
28
{
29
    use TranslatorTrait;
30
31
    /**
32
     * @var RouterInterface
33
     */
34
    protected $router;
35
36
    /**
37
     * @var PermissionApi
38
     */
39
    protected $permissionApi;
40
41
    /**
42
     * @var ControllerHelper
43
     */
44
    protected $controllerHelper;
45
46
    /**
47
     * @var CurrentUserApi
48
     */
49
    private $currentUserApi;
50
51
    /**
52
     * Constructor.
53
     * Initialises member vars.
54
     *
55
     * @param TranslatorInterface $translator       Translator service instance
56
     * @param Routerinterface     $router           Router service instance
57
     * @param PermissionApi       $permissionApi    PermissionApi service instance
58
     * @param ControllerHelper    $controllerHelper ControllerHelper service instance
59
     * @param CurrentUserApi      $currentUserApi   CurrentUserApi service instance
60
     */
61 View Code Duplication
    public function __construct(TranslatorInterface $translator, RouterInterface $router, PermissionApi $permissionApi, ControllerHelper $controllerHelper, CurrentUserApi $currentUserApi)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
62
    {
63
        $this->setTranslator($translator);
64
        $this->router = $router;
65
        $this->permissionApi = $permissionApi;
66
        $this->controllerHelper = $controllerHelper;
67
        $this->currentUserApi = $currentUserApi;
68
    }
69
70
    /**
71
     * Sets the translator.
72
     *
73
     * @param TranslatorInterface $translator Translator service instance
74
     */
75
    public function setTranslator(/*TranslatorInterface */$translator)
76
    {
77
        $this->translator = $translator;
0 ignored issues
show
Documentation Bug introduced by
$translator is of type object<Zikula\Common\Tra...or\TranslatorInterface>, but the property $translator was declared to be of type object<Zikula\Common\Translator\Translator>. Are you sure that you always receive this specific sub-class here, or does it make sense to add an instanceof check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.

Either this assignment is in error or an instanceof check should be added for that assignment.

class Alien {}

class Dalek extends Alien {}

class Plot
{
    /** @var  Dalek */
    public $villain;
}

$alien = new Alien();
$plot = new Plot();
if ($alien instanceof Dalek) {
    $plot->villain = $alien;
}
Loading history...
78
    }
79
80
    /**
81
     * Returns available header links.
82
     *
83
     * @param string $type The type to collect links for
84
     *
85
     * @return array Array of header links
86
     */
87
    public function getLinks($type = LinkContainerInterface::TYPE_ADMIN)
88
    {
89
        $utilArgs = ['api' => 'linkContainer', 'action' => 'getLinks'];
90
        $allowedObjectTypes = $this->controllerHelper->getObjectTypes('api', $utilArgs);
91
92
        $permLevel = LinkContainerInterface::TYPE_ADMIN == $type ? ACCESS_ADMIN : ACCESS_READ;
93
94
        // Create an array of links to return
95
        $links = [];
96
97
        
98 View Code Duplication
        if (LinkContainerInterface::TYPE_ADMIN == $type) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
99
            if ($this->permissionApi->hasPermission($this->getBundleName() . '::', '::', ACCESS_READ)) {
100
                $links[] = [
101
                    'url' => $this->router->generate('zikularoutesmodule_user_index'),
102
                    'text' => $this->__('Frontend'),
103
                    'title' => $this->__('Switch to user area.'),
104
                    'icon' => 'home'
105
                ];
106
            }
107
            
108
            if (in_array('route', $allowedObjectTypes)
109
                && $this->permissionApi->hasPermission($this->getBundleName() . ':Route:', '::', $permLevel)) {
110
                $links[] = [
111
                    'url' => $this->router->generate('zikularoutesmodule_route_adminview'),
112
                     'text' => $this->__('Routes'),
113
                     'title' => $this->__('Route list')
114
                 ];
115
            }
116
        }
117 View Code Duplication
        if (LinkContainerInterface::TYPE_USER == $type) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
118
            if ($this->permissionApi->hasPermission($this->getBundleName() . '::', '::', ACCESS_ADMIN)) {
119
                $links[] = [
120
                    'url' => $this->router->generate('zikularoutesmodule_admin_index'),
121
                    'text' => $this->__('Backend'),
122
                    'title' => $this->__('Switch to administration area.'),
123
                    'icon' => 'wrench'
124
                ];
125
            }
126
            
127
            if (in_array('route', $allowedObjectTypes)
128
                && $this->permissionApi->hasPermission($this->getBundleName() . ':Route:', '::', $permLevel)) {
129
                $links[] = [
130
                    'url' => $this->router->generate('zikularoutesmodule_route_view'),
131
                     'text' => $this->__('Routes'),
132
                     'title' => $this->__('Route list')
133
                 ];
134
            }
135
        }
136
137
        return $links;
138
    }
139
140
    /**
141
     * Returns the name of the providing bundle.
142
     *
143
     * @return string The bundle name
144
     */
145
    public function getBundleName()
146
    {
147
        return 'ZikulaRoutesModule';
148
    }
149
}
150