Passed
Push — master ( c70a6b...e1aeb2 )
by Marcel
05:29 queued 16s
created

StoryController::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 8
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 2019-2022 Marcel Scherello
10
 */
11
12
namespace OCA\Analytics\Controller;
13
14
use OCA\Analytics\Service\StoryService;
15
use OCP\AppFramework\Controller;
0 ignored issues
show
Bug introduced by
The type OCP\AppFramework\Controller was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
16
use OCP\AppFramework\Http\DataResponse;
0 ignored issues
show
Bug introduced by
The type OCP\AppFramework\Http\DataResponse was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
17
use OCP\DB\Exception;
0 ignored issues
show
Bug introduced by
The type OCP\DB\Exception was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
18
use OCP\IRequest;
0 ignored issues
show
Bug introduced by
The type OCP\IRequest was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
19
use Psr\Log\LoggerInterface;
0 ignored issues
show
Bug introduced by
The type Psr\Log\LoggerInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
20
21
class StoryController extends Controller
22
{
23
    private $logger;
24
    private $StoryService;
25
26
    public function __construct(
27
        $appName,
28
        IRequest $request,
29
        LoggerInterface $logger,
30
        StoryService $StoryService
31
    )
32
    {
33
        parent::__construct($appName, $request);
34
        $this->logger = $logger;
35
        $this->StoryService = $StoryService;
36
    }
37
38
    /**
39
     * get all reports
40
     *
41
     * @NoAdminRequired
42
     * @return DataResponse
43
     */
44
    public function index()
45
    {
46
        return new DataResponse($this->StoryService->index());
47
    }
48
49
    /**
50
     * create new blank report
51
     *
52
     * @NoAdminRequired
53
     * @param $name
54
     * @param $subheader
55
     * @param int $type
56
     * @param int $page
57
     * @param int $parent
58
     * @param $reports
59
     * @param $layout
60
     * @return DataResponse
61
     * @throws Exception
62
     */
63
    public function create($name, $subheader, int $type, int $page, int $parent, $reports, $layout)
64
    {
65
        return new DataResponse($this->StoryService->create($name, $subheader, $type, $page, $parent, $reports, $layout));
66
    }
67
68
69
    /**
70
     * get own report details
71
     *
72
     * @NoAdminRequired
73
     * @param int $storyId
74
     * @return DataResponse
75
     */
76
    public function read(int $storyId)
77
    {
78
        return new DataResponse($this->StoryService->read($storyId));
79
    }
80
81
    /**
82
     * Delete report and all depending objects
83
     *
84
     * @NoAdminRequired
85
     * @param int $storyId
86
     * @return DataResponse
87
     */
88
    public function delete(int $storyId)
89
    {
90
        if ($this->StoryService->isOwn($storyId)) {
91
            return new DataResponse($this->StoryService->delete($storyId));
92
        } else {
93
            return new DataResponse(false,400);
94
        }
95
    }
96
97
    /**
98
     * get report details
99
     *
100
     * @NoAdminRequired
101
     * @param int $id
102
     * @param $name
103
     * @param $subheader
104
     * @param int $type
105
     * @param int $page
106
     * @param int $parent
107
     * @param $reports
108
     * @param $layout
109
     * @return DataResponse
110
     * @throws Exception
111
     */
112
    public function update(int $id, $name, $subheader, int $type, int $page, int $parent, $reports, $layout)
113
    {
114
        return new DataResponse($this->StoryService->update($id, $name, $subheader, $type, $page, $parent, $reports, $layout));
115
    }
116
}