PageController   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 55
Duplicated Lines 12.73 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 1
dl 7
loc 55
ccs 21
cts 21
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 7 7 1
A index() 0 24 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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\Controller;
15
use OCP\AppFramework\Http\TemplateResponse;
16
use OCP\AppFramework\Http\ContentSecurityPolicy;
17
use OCP\IRequest;
18
use OCP\IConfig;
19
20
use OCA\Notes\Service\NotesService;
21
use OCA\Notes\Service\NoteDoesNotExistException;
22
23
/**
24
 * Class PageController
25
 *
26
 * @package OCA\Notes\Controller
27
 */
28
class PageController extends Controller {
29
30
	/** @var NotesService */
31
	private $notesService;
32
	/** @var IConfig */
33
	private $settings;
34
	/** @var string */
35
	private $userId;
36
37
	/**
38
	 * @param string $AppName
39
	 * @param IRequest $request
40
	 * @param NotesService $notesService
41
	 * @param IConfig $settings
42
	 * @param string $UserId
43
	 */
44 4 View Code Duplication
	public function __construct($AppName, IRequest $request, $UserId,
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
45
								NotesService $notesService, IConfig $settings) {
46 4
		parent::__construct($AppName, $request);
47 4
		$this->notesService = $notesService;
48 4
		$this->userId = $UserId;
49 4
		$this->settings = $settings;
50 4
	}
51
52
	/**
53
	 * @NoAdminRequired
54
	 * @NoCSRFRequired
55
	 *
56
	 * @return TemplateResponse
57
	 */
58
	public function index() {
59 4
		$lastViewedNote = (int) $this->settings->getUserValue($this->userId,
60 4
			$this->appName, 'notesLastViewedNote');
61 4
		// check if note exists
62
		try {
63
			$this->notesService->get($lastViewedNote, $this->userId);
64 4
		} catch (NoteDoesNotExistException $ex) {
65 4
			$lastViewedNote = 0;
66 1
		}
67
68
		$response = new TemplateResponse(
69 4
			$this->appName,
70 4
			'main',
71 4
			[
72
				'lastViewedNote' => $lastViewedNote
73
			]
74 4
		);
75 4
76
		$csp = new ContentSecurityPolicy();
77 4
		$csp->addAllowedImageDomain('*');
78 4
		$response->setContentSecurityPolicy($csp);
79 4
80
		return $response;
81 4
	}
82
}
83