Passed
Pull Request — master (#966)
by René
04:09
created

CommentController::getByToken()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 2
ccs 0
cts 2
cp 0
crap 2
rs 10
1
<?php
2
/**
3
 * @copyright Copyright (c) 2017 Vinzenz Rosenkranz <[email protected]>
4
 *
5
 * @author René Gieling <[email protected]>
6
 *
7
 * @license GNU AGPL version 3 or any later version
8
 *
9
 *  This program is free software: you can redistribute it and/or modify
10
 *  it under the terms of the GNU Affero General Public License as
11
 *  published by the Free Software Foundation, either version 3 of the
12
 *  License, or (at your option) any later version.
13
 *
14
 *  This program is distributed in the hope that it will be useful,
15
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 *  GNU Affero General Public License for more details.
18
 *
19
 *  You should have received a copy of the GNU Affero General Public License
20
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
21
 *
22
 */
23
24
namespace OCA\Polls\Controller;
25
26
use Exception;
27
28
use OCP\IRequest;
29
use OCP\ILogger;
30
use OCP\AppFramework\Controller;
31
use OCP\AppFramework\Http;
32
use OCP\AppFramework\Http\DataResponse;
33
34
use OCA\Polls\Service\CommentService;
35
36
37
38
class CommentController extends Controller {
39
40
	private $commentService;
41
42
	/**
43
	 * CommentController constructor.
44
	 * @param string $appName
45
	 * @param IRequest $request
46
	 * @param CommentService $commentService
47
	 */
48
49
	public function __construct(
50
		string $appName,
51
		IRequest $request,
52
		CommentService $commentService
53
	) {
54
		parent::__construct($appName, $request);
55
		$this->commentService = $commentService;
56
	}
57
58
	/**
59
	 * get
60
	 * Read all comments of a poll based on the poll id and return list as array
61
	 * @NoAdminRequired
62
	 * @NoCSRFRequired
63
	 * @param integer $pollId
64
	 * @return DataResponse
65
	 */
66
	public function list($pollId) {
67
		return new DataResponse($this->commentService->list($pollId), Http::STATUS_OK);
68
	}
69
70
	/**
71
	 * Read all comments of a poll based on a share token and return list as array
72
	 * @NoAdminRequired
73
	 * @NoCSRFRequired
74
	 * @PublicPage
75
	 * @param string $token
76
	 * @return DataResponse
77
	 */
78
	public function getByToken($token) {
79
		return new DataResponse($this->commentService->get(0, $token), Http::STATUS_OK);
0 ignored issues
show
Bug introduced by
The method get() does not exist on OCA\Polls\Service\CommentService. ( Ignorable by Annotation )

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

79
		return new DataResponse($this->commentService->/** @scrutinizer ignore-call */ get(0, $token), Http::STATUS_OK);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
80
	}
81
82
	/**
83
	 * Write a new comment to the db and returns the new comment as array
84
	 * @NoAdminRequired
85
	 * @PublicPage
86
	 * @param int $pollId
87
	 * @param string $message
88
	 * @param string $token
89
	 * @return DataResponse
90
	 */
91
	public function add($pollId, $message, $token) {
92
		try {
93
			return new DataResponse($this->commentService->add($pollId, $message, $token), Http::STATUS_OK);
94
		} catch (Exception $e) {
95
			return new DataResponse($e, Http::STATUS_UNAUTHORIZED);
96
		}
97
	}
98
99
	/**
100
	 * Delete Comment
101
	 * @NoAdminRequired
102
	 * @PublicPage
103
	 * @param int $commentId
104
	 * @param string $token
105
	 * @return DataResponse
106
	 */
107
	public function delete($commentId, $token) {
108
		try {
109
			return new DataResponse($this->commentService->delete($commentId, $token), Http::STATUS_OK);
110
		} catch (NotAuthorizedException $e) {
0 ignored issues
show
Bug introduced by
The type OCA\Polls\Controller\NotAuthorizedException 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...
111
			return new DataResponse($e, Http::STATUS_FORBIDDEN);
112
		} catch (DoesNotExistException $e) {
0 ignored issues
show
Bug introduced by
The type OCA\Polls\Controller\DoesNotExistException 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...
113
			return new DataResponse($e, Http::STATUS_OK);
114
		}
115
116
	}
117
118
}
119