Passed
Push — master ( 370f15...d1697d )
by Marcel
02:54
created

DataloadController::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 22
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 9
nc 1
nop 10
dl 0
loc 22
rs 9.9666
c 0
b 0
f 0

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 Exception;
15
use OCA\Analytics\Activity\ActivityManager;
16
use OCA\Analytics\Db\DataloadMapper;
17
use OCA\Analytics\Service\DataloadService;
18
use OCA\Analytics\Service\DatasetService;
19
use OCA\Analytics\Service\StorageService;
20
use OCP\AppFramework\Controller;
21
use OCP\AppFramework\Http\DataResponse;
22
use OCP\AppFramework\Http\NotFoundResponse;
23
use OCP\Files\NotFoundException;
24
use OCP\IL10N;
25
use OCP\IRequest;
26
use Psr\Log\LoggerInterface;
27
28
class DataloadController extends Controller
29
{
30
    private $logger;
31
    private $StorageService;
32
    private $DatasourceController;
33
    private $ActivityManager;
34
    private $DatasetService;
35
    private $DataloadService;
36
    private $l10n;
37
    private $DataloadMapper;
38
39
    public function __construct(
40
        string $AppName,
41
        IRequest $request,
42
        IL10N $l10n,
43
        LoggerInterface $logger,
44
        ActivityManager $ActivityManager,
45
        DatasourceController $DatasourceController,
46
        DatasetService $DatasetService,
47
        DataloadService $DataloadService,
48
        StorageService $StorageService,
49
        DataloadMapper $DataloadMapper
50
    )
51
    {
52
        parent::__construct($AppName, $request);
53
        $this->l10n = $l10n;
54
        $this->logger = $logger;
55
        $this->StorageService = $StorageService;
56
        $this->ActivityManager = $ActivityManager;
57
        $this->DatasourceController = $DatasourceController;
58
        $this->DatasetService = $DatasetService;
59
        $this->DataloadService = $DataloadService;
60
        $this->DataloadMapper = $DataloadMapper;
61
    }
62
63
    /**
64
     * create a new dataload
65
     *
66
     * @NoAdminRequired
67
     * @param int $datasetId
68
     * @param int $datasourceId
69
     * @return DataResponse
70
     */
71
    public function create(int $datasetId, int $datasourceId)
72
    {
73
        return new DataResponse(['id' => $this->DataloadService->create($datasetId, $datasourceId)]);
74
    }
75
76
    /**
77
     * get all dataloads for a dataset
78
     *
79
     * @NoAdminRequired
80
     * @param int $datasetId
81
     * @return DataResponse
82
     */
83
    public function read(int $datasetId)
84
    {
85
        $result = array();
86
        $result['dataloads'] = $this->DataloadService->read($datasetId);
87
        return new DataResponse($result);
88
    }
89
90
    /**
91
     * update dataload
92
     *
93
     * @NoAdminRequired
94
     * @param int $dataloadId
95
     * @param $name
96
     * @param $option
97
     * @param $schedule
98
     * @return DataResponse
99
     */
100
    public function update(int $dataloadId, $name, $option, $schedule)
101
    {
102
        return new DataResponse(['update' => $this->DataloadService->update($dataloadId, $name, $option, $schedule)]);
103
    }
104
105
    /**
106
     * delete a dataload
107
     *
108
     * @NoAdminRequired
109
     * @param int $dataloadId
110
     * @return bool
111
     */
112
    public function delete(int $dataloadId)
113
    {
114
        return $this->DataloadService->delete($dataloadId);
115
    }
116
117
    /**
118
     * simulate a dataload and output its data
119
     *
120
     * @NoAdminRequired
121
     * @param int $dataloadId
122
     * @return DataResponse
123
     * @throws NotFoundException
124
     */
125
    public function simulate(int $dataloadId)
126
    {
127
        return new DataResponse($this->DataloadService->getDataFromDatasource($dataloadId));
128
    }
129
130
    /**
131
     * execute a dataload from datasource and store into dataset
132
     *
133
     * @NoAdminRequired
134
     * @param int $dataloadId
135
     * @return DataResponse
136
     * @throws Exception
137
     */
138
    public function execute(int $dataloadId)
139
    {
140
        return new DataResponse($this->DataloadService->execute($dataloadId));
141
    }
142
143
144
    // Data Manipulation
145
    // Data Manipulation
146
    // Data Manipulation
147
148
    /**
149
     * update data from input form
150
     *
151
     * @NoAdminRequired
152
     * @param int $reportId
153
     * @param $dimension1
154
     * @param $dimension2
155
     * @param $value
156
     * @return DataResponse|NotFoundResponse
157
     * @throws Exception
158
     */
159
    public function updateData(int $reportId, $dimension1, $dimension2, $value)
160
    {
161
        $result = $this->DataloadService->updateData($reportId, $dimension1, $dimension2, $value);
162
        if ($result) {
163
            return new DataResponse($result);
164
        } else {
165
            return new NotFoundResponse();
166
        }
167
    }
168
169
    /**
170
     * delete data from input form
171
     *
172
     * @NoAdminRequired
173
     * @param int $reportId
174
     * @param $dimension1
175
     * @param $dimension2
176
     * @return DataResponse|NotFoundResponse
177
     */
178
    public function deleteData(int $reportId, $dimension1, $dimension2)
179
    {
180
        $result = $this->DataloadService->deleteData($reportId, $dimension1, $dimension2);
181
        if ($result) {
182
            return new DataResponse($result);
183
        } else {
184
            return new NotFoundResponse();
185
        }
186
    }
187
188
    /**
189
     * Simulate delete data from input form
190
     *
191
     * @NoAdminRequired
192
     * @param int $reportId
193
     * @param $dimension1
194
     * @param $dimension2
195
     * @return DataResponse|NotFoundResponse
196
     */
197
    public function deleteDataSimulate(int $reportId, $dimension1, $dimension2)
198
    {
199
        $result = $this->DataloadService->deleteDataSimulate($reportId, $dimension1, $dimension2);
200
        if ($result) {
201
            return new DataResponse($result);
202
        } else {
203
            return new NotFoundResponse();
204
        }
205
    }
206
207
    /**
208
     * Import clipboard data
209
     *
210
     * @NoAdminRequired
211
     * @param int $reportId
212
     * @param $import
213
     * @return DataResponse|NotFoundResponse
214
     * @throws Exception
215
     */
216
    public function importClipboard($reportId, $import)
217
    {
218
        $result = $this->DataloadService->importClipboard($reportId, $import);
219
        if ($result) {
220
            return new DataResponse($result);
221
        } else {
222
            return new NotFoundResponse();
223
        }
224
    }
225
226
    /**
227
     * Import data into dataset from an internal or external file
228
     *
229
     * @NoAdminRequired
230
     * @param int $reportId
231
     * @param $path
232
     * @return DataResponse|NotFoundResponse
233
     * @throws Exception
234
     */
235
    public function importFile(int $reportId, $path)
236
    {
237
        $result = $this->DataloadService->importFile($reportId, $path);
238
        if ($result) {
239
            return new DataResponse($result);
240
        } else {
241
            return new NotFoundResponse();
242
        }
243
    }
244
}