CommentAdmin::getJsBundleName()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 3
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
3
/*
4
 * This file is part of Sulu.
5
 *
6
 * (c) MASSIVE ART WebServices GmbH
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 Sulu\Bundle\CommentBundle\Admin;
13
14
use Sulu\Bundle\AdminBundle\Admin\Admin;
15
use Sulu\Bundle\AdminBundle\Navigation\Navigation;
16
use Sulu\Bundle\AdminBundle\Navigation\NavigationItem;
17
use Sulu\Component\Security\Authorization\PermissionTypes;
18
use Sulu\Component\Security\Authorization\SecurityCheckerInterface;
19
20
/**
21
 * Integrates sulu_comment into sulu-admin.
22
 */
23
class CommentAdmin extends Admin
24
{
25
    const COMMENT_SECURITY_CONTEXT = 'sulu.comment.comments';
26
27
    const THREAD_SECURITY_CONTEXT = 'sulu.comment.threads';
28
29
    /**
30
     * @var SecurityCheckerInterface
31
     */
32
    private $securityChecker;
33
34
    /**
35
     * @param SecurityCheckerInterface $securityChecker
36
     * @param string $title
37
     */
38
    public function __construct(SecurityCheckerInterface $securityChecker, $title)
39
    {
40
        $this->securityChecker = $securityChecker;
41
42
        $rootNavigationItem = new NavigationItem($title);
43
        $section = new NavigationItem('navigation.modules');
44
        $section->setPosition(20);
45
46
        $commentModule = new NavigationItem('sulu_comment.comments');
47
        $commentModule->setPosition(9);
48
        $commentModule->setIcon('commenting');
49
50 View Code Duplication
        if ($this->securityChecker->hasPermission(self::COMMENT_SECURITY_CONTEXT, PermissionTypes::VIEW)) {
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...
51
            $comments = new NavigationItem('sulu_comment.comments');
52
            $comments->setPosition(10);
53
            $comments->setAction('comments');
54
55
            $commentModule->addChild($comments);
0 ignored issues
show
Documentation introduced by
$comments is of type object<Sulu\Bundle\Admin...igation\NavigationItem>, but the function expects a object<self>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
56
        }
57
58 View Code Duplication
        if ($this->securityChecker->hasPermission(self::THREAD_SECURITY_CONTEXT, PermissionTypes::VIEW)) {
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...
59
            $threads = new NavigationItem('sulu_comment.threads');
60
            $threads->setPosition(20);
61
            $threads->setAction('threads');
62
63
            $commentModule->addChild($threads);
0 ignored issues
show
Documentation introduced by
$threads is of type object<Sulu\Bundle\Admin...igation\NavigationItem>, but the function expects a object<self>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
64
        }
65
66
        if ($commentModule->hasChildren()) {
67
            $section->addChild($commentModule);
0 ignored issues
show
Documentation introduced by
$commentModule is of type object<Sulu\Bundle\Admin...igation\NavigationItem>, but the function expects a object<self>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
68
            $rootNavigationItem->addChild($section);
0 ignored issues
show
Documentation introduced by
$section is of type object<Sulu\Bundle\Admin...igation\NavigationItem>, but the function expects a object<self>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
69
        }
70
71
        $this->setNavigation(new Navigation($rootNavigationItem));
72
    }
73
74
    /**
75
     * {@inheritdoc}
76
     */
77
    public function getSecurityContexts()
78
    {
79
        return [
80
            'Sulu' => [
81
                'Comment' => [
82
                    self::COMMENT_SECURITY_CONTEXT => [
83
                        PermissionTypes::VIEW,
84
                        PermissionTypes::DELETE,
85
                        PermissionTypes::LIVE,
86
                    ],
87
                    self::THREAD_SECURITY_CONTEXT => [
88
                        PermissionTypes::VIEW,
89
                        PermissionTypes::DELETE,
90
                        PermissionTypes::EDIT,
91
                    ],
92
                ],
93
            ],
94
        ];
95
    }
96
97
    /**
98
     * {@inheritdoc}
99
     */
100
    public function getJsBundleName()
101
    {
102
        return 'sulucomment';
103
    }
104
}
105