Passed
Push — master ( cb24fc...339795 )
by Marcel
04:00 queued 12s
created

ReportController::update()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
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
 * This file is licensed under the Affero General Public License version 3 or
6
 * later. See the LICENSE.md file.
7
 *
8
 * @author Marcel Scherello <[email protected]>
9
 * @copyright 2019-2022 Marcel Scherello
10
 */
11
12
namespace OCA\Analytics\Controller;
13
14
use OCA\Analytics\Service\ReportService;
15
use OCP\AppFramework\Controller;
16
use OCP\AppFramework\Http\DataResponse;
17
use OCP\IRequest;
18
use Psr\Log\LoggerInterface;
19
20
class ReportController extends Controller
21
{
22
    private $logger;
23
    private $ReportService;
24
25
    public function __construct(
26
        $appName,
27
        IRequest $request,
28
        LoggerInterface $logger,
29
        ReportService $ReportService
30
    )
31
    {
32
        parent::__construct($appName, $request);
33
        $this->logger = $logger;
34
        $this->ReportService = $ReportService;
35
    }
36
37
    /**
38
     * get all reports
39
     *
40
     * @NoAdminRequired
41
     * @return DataResponse
42
     */
43
    public function index()
44
    {
45
        return new DataResponse($this->ReportService->index());
46
    }
47
48
    /**
49
     * create new blank report
50
     *
51
     * @NoAdminRequired
52
     * @param $name
53
     * @param $subheader
54
     * @param int $parent
55
     * @param int $type
56
     * @param int $dataset
57
     * @param $link
58
     * @param $visualization
59
     * @param $chart
60
     * @param $dimension1
61
     * @param $dimension2
62
     * @param $value
63
     * @return DataResponse
64
     */
65
    public function create($name, $subheader, int $parent, int $type, int $dataset, $link, $visualization, $chart, $dimension1, $dimension2, $value, $addReport = null)
66
    {
67
        return new DataResponse($this->ReportService->create($name, $subheader, $parent, $type, $dataset, $link, $visualization, $chart, $dimension1, $dimension2, $value, $addReport));
68
    }
69
70
    /**
71
     * copy an existing report with the current navigation status
72
     *
73
     * @NoAdminRequired
74
     * @param int $reportId
75
     * @param $chartoptions
76
     * @param $dataoptions
77
     * @param $filteroptions
78
     * @return DataResponse
79
     */
80
    public function createCopy(int $reportId, $chartoptions, $dataoptions, $filteroptions)
81
    {
82
        return new DataResponse($this->ReportService->createCopy($reportId, $chartoptions, $dataoptions, $filteroptions));
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
     * @return DataResponse
158
     */
159
    public function updateOptions(int $reportId, $chartoptions, $dataoptions, $filteroptions)
160
    {
161
        return new DataResponse($this->ReportService->updateOptions($reportId, $chartoptions, $dataoptions, $filteroptions));
162
    }
163
164
    /**
165
     * update report refresh details
166
     *
167
     * @NoAdminRequired
168
     * @param int $reportId
169
     * @param $refresh
170
     * @return DataResponse
171
     */
172
    public function updateRefresh(int $reportId, $refresh)
173
    {
174
        return new DataResponse($this->ReportService->updateRefresh($reportId, $refresh));
175
    }
176
177
    /**
178
     * update report group assignment (from drag & drop)
179
     *
180
     * @NoAdminRequired
181
     * @param int $reportId
182
     * @param $groupId
183
     * @return DataResponse
184
     */
185
    public function updateGroup(int $reportId, $groupId)
186
    {
187
        return new DataResponse($this->ReportService->updateGroup($reportId, $groupId));
188
    }
189
190
    /**
191
     * get own reports which are marked as favorites
192
     *
193
     * @NoAdminRequired
194
     * @return DataResponse
195
     */
196
    public function getOwnFavoriteReports()
197
    {
198
        return new DataResponse($this->ReportService->getOwnFavoriteReports());
199
    }
200
201
    /**
202
     * set/remove the favorite flag for a report
203
     *
204
     * @NoAdminRequired
205
     * @param int $reportId
206
     * @param string $favorite
207
     * @return DataResponse
208
     */
209
    public function setFavorite(int $reportId, string $favorite)
210
    {
211
        return new DataResponse($this->ReportService->setFavorite($reportId, $favorite));
212
    }
213
214
    /**
215
     * Export report
216
     *
217
     * @NoCSRFRequired
218
     * @NoAdminRequired
219
     * @param int $reportId
220
     */
221
    public function export(int $reportId)
222
    {
223
        return $this->ReportService->export($reportId);
224
    }
225
226
    /**
227
     * Import report
228
     *
229
     * @NoAdminRequired
230
     * @param string|null $path
231
     * @param string|null $raw
232
     * @return DataResponse
233
     * @throws \OCP\Files\NotFoundException
234
     * @throws \OCP\Files\NotPermittedException
235
     */
236
    public function import(string $path = null, string $raw = null)
237
    {
238
        return new DataResponse($this->ReportService->import($path, $raw));
239
    }
240
241
}