ReportController::create()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 12
dl 0
loc 3
rs 10

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
<?php
2
/**
3
 * Analytics
4
 *
5
 * SPDX-FileCopyrightText: 2019-2022 Marcel Scherello
6
 * SPDX-License-Identifier: AGPL-3.0-or-later
7
 */
8
9
namespace OCA\Analytics\Controller;
10
11
use OCA\Analytics\Service\ReportService;
12
use OCP\AppFramework\Controller;
0 ignored issues
show
Bug introduced by
The type OCP\AppFramework\Controller was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
13
use OCP\AppFramework\Http\DataResponse;
0 ignored issues
show
Bug introduced by
The type OCP\AppFramework\Http\DataResponse was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
14
use OCP\DB\Exception;
0 ignored issues
show
Bug introduced by
The type OCP\DB\Exception was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
15
use OCP\IRequest;
0 ignored issues
show
Bug introduced by
The type OCP\IRequest was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
16
use Psr\Log\LoggerInterface;
0 ignored issues
show
Bug introduced by
The type Psr\Log\LoggerInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
17
18
class ReportController extends Controller
19
{
20
    private $logger;
21
    private $ReportService;
22
23
    public function __construct(
24
        $appName,
25
        IRequest $request,
26
        LoggerInterface $logger,
27
        ReportService $ReportService
28
    )
29
    {
30
        parent::__construct($appName, $request);
31
        $this->logger = $logger;
32
        $this->ReportService = $ReportService;
33
    }
34
35
    /**
36
     * get all reports
37
     *
38
     * @NoAdminRequired
39
     * @return DataResponse
40
     */
41
    public function index()
42
    {
43
        return new DataResponse($this->ReportService->index());
44
    }
45
46
    /**
47
     * create new blank report
48
     *
49
     * @NoAdminRequired
50
     * @param $name
51
     * @param $subheader
52
     * @param int $parent
53
     * @param int $type
54
     * @param int $dataset
55
     * @param $link
56
     * @param $visualization
57
     * @param $chart
58
     * @param $dimension1
59
     * @param $dimension2
60
     * @param $value
61
     * @return DataResponse
62
     */
63
    public function create($name, $subheader, int $parent, int $type, int $dataset, $link, $visualization, $chart, $dimension1, $dimension2, $value, $addReport = null)
64
    {
65
        return new DataResponse($this->ReportService->create($name, $subheader, $parent, $type, $dataset, $link, $visualization, $chart, $dimension1, $dimension2, $value, $addReport));
66
    }
67
68
    /**
69
     * copy an existing report with the current navigation status
70
     *
71
     * @NoAdminRequired
72
     * @param int $reportId
73
     * @param $chartoptions
74
     * @param $dataoptions
75
     * @param $filteroptions
76
     * @param $tableoptions
77
     * @return DataResponse
78
     * @throws Exception
79
     */
80
    public function createCopy(int $reportId, $chartoptions, $dataoptions, $filteroptions, $tableoptions)
81
    {
82
        return new DataResponse($this->ReportService->createCopy($reportId, $chartoptions, $dataoptions, $filteroptions, $tableoptions));
83
    }
84
85
    /**
86
     * create new report from file
87
     *
88
     * @NoAdminRequired
89
     * @param string $file
90
     * @return DataResponse
91
     */
92
    public function createFromDataFile($file = '')
93
    {
94
        return new DataResponse($this->ReportService->createFromDataFile($file));
95
    }
96
97
    /**
98
     * get own report details
99
     *
100
     * @NoAdminRequired
101
     * @param int $reportId
102
     * @return DataResponse
103
     */
104
    public function read(int $reportId)
105
    {
106
        return new DataResponse($this->ReportService->read($reportId, false));
107
    }
108
109
    /**
110
     * Delete report and all depending objects
111
     *
112
     * @NoAdminRequired
113
     * @param int $reportId
114
     * @return DataResponse
115
     */
116
    public function delete(int $reportId)
117
    {
118
        if ($this->ReportService->isOwn($reportId)) {
119
            return new DataResponse($this->ReportService->delete($reportId));
120
        } else {
121
            return new DataResponse(false,400);
122
        }
123
    }
124
125
    /**
126
     * get report details
127
     *
128
     * @NoAdminRequired
129
     * @param int $reportId
130
     * @param $name
131
     * @param $subheader
132
     * @param int $parent
133
     * @param $link
134
     * @param $visualization
135
     * @param $chart
136
     * @param $chartoptions
137
     * @param $dataoptions
138
     * @param $dimension1
139
     * @param $dimension2
140
     * @param $value
141
     * @return DataResponse
142
     * @throws \OCP\DB\Exception
143
     */
144
    public function update(int $reportId, $name, $subheader, int $parent, $link, $visualization, $chart, $chartoptions, $dataoptions, $dimension1 = null, $dimension2 = null, $value = null)
145
    {
146
        return new DataResponse($this->ReportService->update($reportId, $name, $subheader, $parent, $link, $visualization, $chart, $chartoptions, $dataoptions, $dimension1, $dimension2, $value));
147
    }
148
149
    /**
150
     * update report options
151
     *
152
     * @NoAdminRequired
153
     * @param int $reportId
154
     * @param $chartoptions
155
     * @param $dataoptions
156
     * @param $filteroptions
157
     * @param $tableoptions
158
     * @return DataResponse
159
     * @throws Exception
160
     */
161
    public function updateOptions(int $reportId, $chartoptions, $dataoptions, $filteroptions, $tableoptions)
162
    {
163
        return new DataResponse($this->ReportService->updateOptions($reportId, $chartoptions, $dataoptions, $filteroptions, $tableoptions));
164
    }
165
166
    /**
167
     * update report refresh details
168
     *
169
     * @NoAdminRequired
170
     * @param int $reportId
171
     * @param $refresh
172
     * @return DataResponse
173
     */
174
    public function updateRefresh(int $reportId, $refresh)
175
    {
176
        return new DataResponse($this->ReportService->updateRefresh($reportId, $refresh));
177
    }
178
179
    /**
180
     * update report group assignment (from drag & drop)
181
     *
182
     * @NoAdminRequired
183
     * @param int $reportId
184
     * @param $groupId
185
     * @return DataResponse
186
     */
187
    public function updateGroup(int $reportId, $groupId)
188
    {
189
        return new DataResponse($this->ReportService->updateGroup($reportId, $groupId));
190
    }
191
192
    /**
193
     * get own reports which are marked as favorites
194
     *
195
     * @NoAdminRequired
196
     * @return DataResponse
197
     */
198
    public function getOwnFavoriteReports()
199
    {
200
        return new DataResponse($this->ReportService->getOwnFavoriteReports());
201
    }
202
203
    /**
204
     * set/remove the favorite flag for a report
205
     *
206
     * @NoAdminRequired
207
     * @param int $reportId
208
     * @param string $favorite
209
     * @return DataResponse
210
     */
211
    public function setFavorite(int $reportId, string $favorite)
212
    {
213
        return new DataResponse($this->ReportService->setFavorite($reportId, $favorite));
214
    }
215
216
    /**
217
     * Export report
218
     *
219
     * @NoCSRFRequired
220
     * @NoAdminRequired
221
     * @param int $reportId
222
     */
223
    public function export(int $reportId)
224
    {
225
        return $this->ReportService->export($reportId);
226
    }
227
228
    /**
229
     * Import report
230
     *
231
     * @NoAdminRequired
232
     * @param string|null $path
233
     * @param string|null $raw
234
     * @return DataResponse
235
     * @throws \OCP\Files\NotFoundException
236
     * @throws \OCP\Files\NotPermittedException
237
     */
238
    public function import(string $path = null, string $raw = null)
239
    {
240
        return new DataResponse($this->ReportService->import($path, $raw));
241
    }
242
}