Errors::respond()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 2
1
<?php
2
/**
3
 * ownCloud - Notes
4
 *
5
 * This file is licensed under the Affero General Public License version 3 or
6
 * later. See the COPYING file.
7
 *
8
 * @author Bernhard Posselt <[email protected]>
9
 * @copyright Bernhard Posselt 2012, 2014
10
 */
11
12
namespace OCA\Notes\Controller;
13
14
use OCP\AppFramework\Http;
15
use OCP\AppFramework\Http\DataResponse;
16
17
use OCA\Notes\Service\NoteDoesNotExistException;
18
19
/**
20
 * Class Errors
21
 *
22
 * @package OCA\Notes\Controller
23
 */
24
trait Errors {
25
	/**
26
	 * @param $callback
27
	 * @return DataResponse
28
	 */
29 14
	protected function respond($callback) {
30
		try {
31 14
			return new DataResponse($callback());
32 6
		} catch (NoteDoesNotExistException $ex) {
33 6
			return new DataResponse([], Http::STATUS_NOT_FOUND);
34
		}
35
	}
36
}
37