Passed
Branch master (7b1276)
by Marcel
06:24
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 10
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
 * Data 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 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\AppFramework\Http\JSONResponse;
18
use OCP\ILogger;
19
use OCP\IRequest;
20
21
22
class DatasetController extends Controller
23
{
24
    private $logger;
25
    private $DatasetService;
26
    private $ShareController;
27
28
    public function __construct(
29
        $appName,
30
        IRequest $request,
31
        ILogger $logger,
32
        ShareController $ShareController,
33
        DatasetService $DatasetService
34
    )
35
    {
36
        parent::__construct($appName, $request);
37
        $this->logger = $logger;
38
        $this->DatasetService = $DatasetService;
39
        $this->ShareController = $ShareController;
40
    }
41
42
    /**
43
     * get all datasets
44
     * @NoAdminRequired
45
     */
46
    public function index()
47
    {
48
        $ownDatasets = $this->DatasetService->index();
49
        $sharedDatasets = $this->ShareController->getSharedDatasets();
50
        $ownDatasets = array_merge($ownDatasets, $sharedDatasets);
51
        return new JSONResponse($ownDatasets);
52
    }
53
54
    /**
55
     * get own dataset details
56
     * @NoAdminRequired
57
     * @param int $datasetId
58
     * @return DataResponse
59
     */
60
    public function read(int $datasetId)
61
    {
62
        return new DataResponse($this->DatasetService->getOwnDataset($datasetId));
63
    }
64
65
    /**
66
     * create new datasets
67
     * @NoAdminRequired
68
     */
69
    public function create()
70
    {
71
        return new DataResponse($this->DatasetService->create());
72
    }
73
74
    /**
75
     * get dataset details
76
     * @NoAdminRequired
77
     * @param int $datasetId
78
     * @return DataResponse
79
     */
80
    public function delete(int $datasetId)
81
    {
82
        return new DataResponse($this->DatasetService->delete($datasetId));
83
    }
84
85
    /**
86
     * get dataset details
87
     * @NoAdminRequired
88
     * @param int $datasetId
89
     * @return DataResponse
90
     */
91
    public function update(int $datasetId, $name, $parent, $type, $link, $visualization, $chart, $dimension1, $dimension2, $dimension3)
92
    {
93
        return new DataResponse($this->DatasetService->update($datasetId, $name, $parent, $type, $link, $visualization, $chart, $dimension1, $dimension2, $dimension3));
94
    }
95
96
}