Passed
Push — master ( 3660fa...998d5d )
by Marcel
03:22
created

DatasetController::update()   A

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 13
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 2020 Marcel Scherello
10
 */
11
12
namespace OCA\Analytics\Controller;
13
14
use OCA\Analytics\Service\DatasetService;
15
use OCP\AppFramework\Controller;
16
use OCP\AppFramework\Http\DataResponse;
17
use OCP\ILogger;
18
use OCP\IRequest;
19
20
class DatasetController extends Controller
21
{
22
    private $logger;
23
    private $DatasetService;
24
25
    public function __construct(
26
        $appName,
27
        IRequest $request,
28
        ILogger $logger,
29
        DatasetService $DatasetService
30
    )
31
    {
32
        parent::__construct($appName, $request);
33
        $this->logger = $logger;
34
        $this->DatasetService = $DatasetService;
35
    }
36
37
    /**
38
     * get all datasets
39
     *
40
     * @NoAdminRequired
41
     * @return DataResponse
42
     */
43
    public function index()
44
    {
45
        return $this->DatasetService->index();
46
    }
47
48
    /**
49
     * create new dataset
50
     *
51
     * @NoAdminRequired
52
     * @param string $file
53
     * @param string $link
54
     * @return int
55
     */
56
    public function create($file = '', $link = '')
57
    {
58
        return $this->DatasetService->create($file, $link);
59
    }
60
61
    /**
62
     * get own dataset details
63
     *
64
     * @NoAdminRequired
65
     * @param int $datasetId
66
     * @return array
67
     */
68
    public function read(int $datasetId)
69
    {
70
        return $this->DatasetService->getOwnDataset($datasetId);
71
    }
72
73
    /**
74
     * Delete Dataset and all depending objects
75
     *
76
     * @NoAdminRequired
77
     * @param int $datasetId
78
     * @return bool
79
     */
80
    public function delete(int $datasetId)
81
    {
82
        return $this->DatasetService->delete($datasetId);
83
    }
84
85
    /**
86
     * get dataset details
87
     *
88
     * @NoAdminRequired
89
     * @param int $datasetId
90
     * @param $name
91
     * @param $subheader
92
     * @param int $parent
93
     * @param int $type
94
     * @param $link
95
     * @param $visualization
96
     * @param $chart
97
     * @param $chartoptions
98
     * @param $dataoptions
99
     * @param $dimension1
100
     * @param $dimension2
101
     * @param $value
102
     * @return bool
103
     */
104
    public function update(int $datasetId, $name, $subheader, int $parent, int $type, $link, $visualization, $chart, $chartoptions, $dataoptions, $dimension1 = null, $dimension2 = null, $value = null)
105
    {
106
        return $this->DatasetService->update($datasetId, $name, $subheader, $parent, $type, $link, $visualization, $chart, $chartoptions, $dataoptions, $dimension1, $dimension2, $value);
107
    }
108
109
    /**
110
     * get dataset details
111
     *
112
     * @NoAdminRequired
113
     * @param int $datasetId
114
     * @param $chartoptions
115
     * @param $dataoptions
116
     * @param $filteroptions
117
     * @return bool
118
     */
119
    public function updateOptions(int $datasetId, $chartoptions, $dataoptions, $filteroptions)
120
    {
121
        return $this->DatasetService->updateOptions($datasetId, $chartoptions, $dataoptions, $filteroptions);
122
    }
123
124
    /**
125
     * get own datasets which are marked as favorites
126
     *
127
     * @NoAdminRequired
128
     * @return array|bool
129
     */
130
    public function getOwnFavoriteDatasets()
131
    {
132
        return $this->DatasetService->getOwnFavoriteDatasets();
133
    }
134
135
    /**
136
     * set/remove the favorite flag for a report
137
     *
138
     * @NoAdminRequired
139
     * @param int $datasetId
140
     * @param string $favorite
141
     * @return bool
142
     */
143
    public function setFavorite(int $datasetId, string $favorite)
144
    {
145
        return $this->DatasetService->setFavorite($datasetId, $favorite);
146
    }
147
148
    /**
149
     * Export Dataset
150
     *
151
     * @NoCSRFRequired
152
     * @NoAdminRequired
153
     * @param int $datasetId
154
     * @return \OCP\AppFramework\Http\DataDownloadResponse
155
     */
156
    public function export(int $datasetId)
157
    {
158
        return $this->DatasetService->export($datasetId);
159
    }
160
161
    /**
162
     * Import Dataset
163
     *
164
     * @NoAdminRequired
165
     * @param string $path
166
     * @return DataResponse
167
     */
168
    public function import(string $path)
169
    {
170
        $this->logger->error('DatasetController: import ' . $path);
0 ignored issues
show
Deprecated Code introduced by
The function OCP\ILogger::error() has been deprecated: 20.0.0 use \Psr\Log\LoggerInterface::error ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

170
        /** @scrutinizer ignore-deprecated */ $this->logger->error('DatasetController: import ' . $path);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
171
        return new DataResponse($this->DatasetService->import($path));
0 ignored issues
show
Bug introduced by
$this->DatasetService->import($path) of type integer is incompatible with the type array|object expected by parameter $data of OCP\AppFramework\Http\DataResponse::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

171
        return new DataResponse(/** @scrutinizer ignore-type */ $this->DatasetService->import($path));
Loading history...
172
    }
173
174
}