GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

TreeController   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 129
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 14

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 14
dl 0
loc 129
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
A getChildrenAction() 0 21 3
A getRootTreeData() 0 20 1
A getCollections() 0 31 2
1
<?php
2
3
namespace Netgen\Bundle\InformationCollectionBundle\Controller\Admin;
4
5
use eZ\Publish\Core\MVC\Symfony\Security\Authorization\Attribute;
6
use eZ\Bundle\EzPublishCoreBundle\Controller;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, Netgen\Bundle\Informatio...roller\Admin\Controller.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
7
use Netgen\InformationCollection\API\Service\InformationCollection;
8
use Netgen\InformationCollection\API\Value\Content;
9
use Netgen\InformationCollection\API\Value\Filter\ContentId;
10
use Netgen\InformationCollection\API\Value\Filter\Query;
11
use Symfony\Component\HttpFoundation\JsonResponse;
12
use Symfony\Component\Routing\RouterInterface;
13
use Symfony\Contracts\Translation\TranslatorInterface;
14
15
class TreeController extends Controller
16
{
17
    /**
18
     * @var \Symfony\Contracts\Translation\TranslatorInterface
19
     */
20
    protected $translator;
21
22
    /**
23
     * @var \Symfony\Component\Routing\RouterInterface
24
     */
25
    protected $router;
26
27
    /**
28
     * @var \Netgen\InformationCollection\API\Service\InformationCollection
29
     */
30
    protected $service;
31
32
    /**
33
     * TreeController constructor.
34
     *
35
     * @param \Netgen\InformationCollection\API\Service\InformationCollection $service
36
     * @param \Symfony\Contracts\Translation\TranslatorInterface $translator
37
     * @param \Symfony\Component\Routing\RouterInterface $router
38
     */
39
    public function __construct(
40
        InformationCollection $service,
41
        TranslatorInterface $translator,
42
        RouterInterface $router
43
    ) {
44
        $this->translator = $translator;
45
        $this->router = $router;
46
        $this->service = $service;
47
    }
48
49
    /**
50
     * Get contents with collections
51
     *
52
     * @param bool $isRoot
53
     *
54
     * @return \Symfony\Component\HttpFoundation\JsonResponse
55
     */
56
    public function getChildrenAction($isRoot = false)
57
    {
58
        $attribute = new Attribute('infocollector', 'read');
59
        $this->denyAccessUnlessGranted($attribute);
60
61
        $result = array();
62
63
        if ((bool) $isRoot) {
64
            $result[] = $this->getRootTreeData();
65
        } else {
66
67
            $query = Query::withLimit($this->getConfigResolver()->getParameter('admin.tree_limit', 'netgen_information_collection'));
68
69
            $objects = $this->service->getObjectsWithCollections($query);
70
            foreach ($objects->getContents() as $content) {
71
                $result[] = $this->getCollections($content, $isRoot);
72
            }
73
        }
74
75
        return (new JsonResponse())->setData($result);
76
    }
77
78
    /**
79
     * Generates data for root of the tree.
80
     *
81
     * @return array
82
     */
83
    protected function getRootTreeData()
84
    {
85
        $count = $this->service->getObjectsWithCollectionsCount();
86
87
        return array(
88
            'id' => '0',
89
            'parent' => '#',
90
            'text' => $this->translator->trans('netgen_information_collection_admin_collected_information', ['%count%' => $count->getCount()], 'netgen_information_collection_admin'),
91
            'children' => true,
92
            'state' => array(
93
                'opened' => true,
94
            ),
95
            'a_attr' => array(
96
                'href' => $this->router->generate('netgen_information_collection.route.admin.overview'),
97
                'rel' => '0',
98
            ),
99
            'data' => array(
100
            ),
101
        );
102
    }
103
104
    /**
105
     * Creates tree structure for Content
106
     *
107
     * @param \Netgen\InformationCollection\API\Value\Content $content
108
     * @param bool $isRoot
109
     *
110
     * @return array
111
     */
112
    protected function getCollections(Content $content, $isRoot = false)
113
    {
114
        $languages = $this->getConfigResolver()->getParameter('languages');
115
116
        $query = ContentId::countWithContentId($content->getContent()->id);
117
118
        $count = $this->service->getCollectionsCount($query);
119
120
        return array(
121
            'id' => $content->getContent()->id,
122
            'parent' => $isRoot ? '#' : '0',
123
            'text' => $content->getContent()->getName($languages[0]) . ' (' . strval($count->getCount()) . ')',
124
            'children' => false,
125
            'a_attr' => array(
126
                'href' => $this->router->generate('netgen_information_collection.route.admin.collection_list', ['contentId' => $content->getContent()->id]),
127
                'rel' => $content->getContent()->id,
128
            ),
129
            'state' => array(
130
                'opened' => $isRoot,
131
            ),
132
            'data' => array(
133
                'context_menu' => array(
134
                    array(
135
                        'name' => 'export',
136
                        'url' => $this->router->generate('netgen_information_collection.route.admin.export', ['contentId' => $content->getContent()->id]),
137
                        'text' => $this->translator->trans('netgen_information_collection_admin_export_export', [], 'netgen_information_collection_admin'),
138
                    ),
139
                ),
140
            ),
141
        );
142
    }
143
}
144