Passed
Push — master ( 912bd1...0b1a33 )
by Marcel
06:53
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 14
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 $this->ReportService->index();
46
    }
47
48
    /**
49
     * create new report
50
     *
51
     * @NoAdminRequired
52
     * @param string $file
53
     * @return int
54
     */
55
    public function create($file = '')
56
    {
57
        return $this->ReportService->create($file);
58
    }
59
60
    /**
61
     * get own report details
62
     *
63
     * @NoAdminRequired
64
     * @param int $reportId
65
     * @return array
66
     */
67
    public function read(int $reportId)
68
    {
69
        return $this->ReportService->read($reportId);
70
    }
71
72
    /**
73
     * Delete report and all depending objects
74
     *
75
     * @NoAdminRequired
76
     * @param int $reportId
77
     * @return bool
78
     */
79
    public function delete(int $reportId)
80
    {
81
        return $this->ReportService->delete($reportId);
82
    }
83
84
    /**
85
     * get report details
86
     *
87
     * @NoAdminRequired
88
     * @param int $reportId
89
     * @param $name
90
     * @param $subheader
91
     * @param int $parent
92
     * @param int $type
93
     * @param int $dataset
94
     * @param $link
95
     * @param $visualization
96
     * @param $chart
97
     * @param $chartoptions
98
     * @param $dataoptions
99
     * @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...
100
     * @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...
101
     * @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...
102
     * @return bool
103
     */
104
    public function update(int $reportId, $name, $subheader, int $parent, int $type, int $dataset, $link, $visualization, $chart, $chartoptions, $dataoptions, $dimension1 = null, $dimension2 = null, $value = null)
105
    {
106
        return $this->ReportService->update($reportId, $name, $subheader, $parent, $type, $dataset, $link, $visualization, $chart, $chartoptions, $dataoptions, $dimension1, $dimension2, $value);
107
    }
108
109
    /**
110
     * update report options
111
     *
112
     * @NoAdminRequired
113
     * @param int $reportId
114
     * @param $chartoptions
115
     * @param $dataoptions
116
     * @param $filteroptions
117
     * @return bool
118
     */
119
    public function updateOptions(int $reportId, $chartoptions, $dataoptions, $filteroptions)
120
    {
121
        return $this->ReportService->updateOptions($reportId, $chartoptions, $dataoptions, $filteroptions);
122
    }
123
124
    /**
125
     * update report refresh details
126
     *
127
     * @NoAdminRequired
128
     * @param int $reportId
129
     * @param $refresh
130
     * @return bool
131
     */
132
    public function updateRefresh(int $reportId, $refresh)
133
    {
134
        return $this->ReportService->updateRefresh($reportId, $refresh);
135
    }
136
137
    /**
138
     * get own reports which are marked as favorites
139
     *
140
     * @NoAdminRequired
141
     * @return array|bool
142
     */
143
    public function getOwnFavoriteReports()
144
    {
145
        return $this->ReportService->getOwnFavoriteReports();
146
    }
147
148
    /**
149
     * set/remove the favorite flag for a report
150
     *
151
     * @NoAdminRequired
152
     * @param int $reportId
153
     * @param string $favorite
154
     * @return bool
155
     */
156
    public function setFavorite(int $reportId, string $favorite)
157
    {
158
        return $this->ReportService->setFavorite($reportId, $favorite);
159
    }
160
161
    /**
162
     * Export report
163
     *
164
     * @NoCSRFRequired
165
     * @NoAdminRequired
166
     * @param int $reportId
167
     * @return \OCP\AppFramework\Http\DataDownloadResponse
168
     */
169
    public function export(int $reportId)
170
    {
171
        return $this->ReportService->export($reportId);
172
    }
173
174
    /**
175
     * Import report
176
     *
177
     * @NoAdminRequired
178
     * @param string|null $path
179
     * @param string|null $raw
180
     * @return DataResponse
181
     * @throws \OCP\Files\NotFoundException
182
     * @throws \OCP\Files\NotPermittedException
183
     */
184
    public function import(string $path = null, string $raw = null)
185
    {
186
        return new DataResponse($this->ReportService->import($path, $raw));
187
    }
188
189
}