Passed
Push — master ( 0d32dd...265c4a )
by Marcel
02:32
created

ReportController::create()   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 11
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 2021 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 null $dimension1
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $dimension1 is correct as it would always require null to be passed?
Loading history...
61
     * @param null $dimension2
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $dimension2 is correct as it would always require null to be passed?
Loading history...
62
     * @param null $value
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $value is correct as it would always require null to be passed?
Loading history...
63
     * @return DataResponse
64
     */
65
    public function create($name, $subheader, int $parent, int $type, int $dataset, $link, $visualization, $chart, $dimension1, $dimension2, $value)
66
    {
67
        return new DataResponse($this->ReportService->create($name, $subheader, $parent, $type, $dataset, $link, $visualization, $chart, $dimension1, $dimension2, $value));
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
        //**todo**//
95
        //still needed?
96
        return new DataResponse($this->ReportService->createFromDataFile($file));
97
    }
98
99
    /**
100
     * get own report details
101
     *
102
     * @NoAdminRequired
103
     * @param int $reportId
104
     * @return DataResponse
105
     */
106
    public function read(int $reportId)
107
    {
108
        return new DataResponse($this->ReportService->read($reportId));
109
    }
110
111
    /**
112
     * Delete report and all depending objects
113
     *
114
     * @NoAdminRequired
115
     * @param int $reportId
116
     * @return DataResponse
117
     */
118
    public function delete(int $reportId)
119
    {
120
        return new DataResponse($this->ReportService->delete($reportId));
121
    }
122
123
    /**
124
     * get report details
125
     *
126
     * @NoAdminRequired
127
     * @param int $reportId
128
     * @param $name
129
     * @param $subheader
130
     * @param int $parent
131
     * @param $link
132
     * @param $visualization
133
     * @param $chart
134
     * @param $chartoptions
135
     * @param $dataoptions
136
     * @param null $dimension1
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $dimension1 is correct as it would always require null to be passed?
Loading history...
137
     * @param null $dimension2
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $dimension2 is correct as it would always require null to be passed?
Loading history...
138
     * @param null $value
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $value is correct as it would always require null to be passed?
Loading history...
139
     * @return DataResponse
140
     * @throws \OCP\DB\Exception
141
     */
142
    public function update(int $reportId, $name, $subheader, int $parent, $link, $visualization, $chart, $chartoptions, $dataoptions, $dimension1 = null, $dimension2 = null, $value = null)
143
    {
144
        return new DataResponse($this->ReportService->update($reportId, $name, $subheader, $parent, $link, $visualization, $chart, $chartoptions, $dataoptions, $dimension1, $dimension2, $value));
145
    }
146
147
    /**
148
     * update report options
149
     *
150
     * @NoAdminRequired
151
     * @param int $reportId
152
     * @param $chartoptions
153
     * @param $dataoptions
154
     * @param $filteroptions
155
     * @return DataResponse
156
     */
157
    public function updateOptions(int $reportId, $chartoptions, $dataoptions, $filteroptions)
158
    {
159
        return new DataResponse($this->ReportService->updateOptions($reportId, $chartoptions, $dataoptions, $filteroptions));
160
    }
161
162
    /**
163
     * update report refresh details
164
     *
165
     * @NoAdminRequired
166
     * @param int $reportId
167
     * @param $refresh
168
     * @return DataResponse
169
     */
170
    public function updateRefresh(int $reportId, $refresh)
171
    {
172
        return new DataResponse($this->ReportService->updateRefresh($reportId, $refresh));
173
    }
174
175
    /**
176
     * get own reports which are marked as favorites
177
     *
178
     * @NoAdminRequired
179
     * @return DataResponse
180
     */
181
    public function getOwnFavoriteReports()
182
    {
183
        return new DataResponse($this->ReportService->getOwnFavoriteReports());
184
    }
185
186
    /**
187
     * set/remove the favorite flag for a report
188
     *
189
     * @NoAdminRequired
190
     * @param int $reportId
191
     * @param string $favorite
192
     * @return DataResponse
193
     */
194
    public function setFavorite(int $reportId, string $favorite)
195
    {
196
        return new DataResponse($this->ReportService->setFavorite($reportId, $favorite));
197
    }
198
199
    /**
200
     * Export report
201
     *
202
     * @NoCSRFRequired
203
     * @NoAdminRequired
204
     * @param int $reportId
205
     */
206
    public function export(int $reportId)
207
    {
208
        return $this->ReportService->export($reportId);
209
    }
210
211
    /**
212
     * Import report
213
     *
214
     * @NoAdminRequired
215
     * @param string|null $path
216
     * @param string|null $raw
217
     * @return DataResponse
218
     * @throws \OCP\Files\NotFoundException
219
     * @throws \OCP\Files\NotPermittedException
220
     */
221
    public function import(string $path = null, string $raw = null)
222
    {
223
        return new DataResponse($this->ReportService->import($path, $raw));
224
    }
225
226
}