Test_PublicController_Bookmarks   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 50
Duplicated Lines 24 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
dl 12
loc 50
rs 10
c 0
b 0
f 0
wmc 5
lcom 1
cbo 2

5 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 7 1
A testPublicQueryNoUser() 6 6 1
A testPublicQueryWrongUser() 6 6 1
A testPublicQuery() 0 11 1
A cleanDB() 0 6 1

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
OC_App::loadApp('bookmarks');
4
5
use \OCA\Bookmarks\Controller\Rest\PublicController;
6
use OCA\Bookmarks\Controller\Lib\Bookmarks;
7
8
class Test_PublicController_Bookmarks extends PHPUnit_Framework_TestCase {
9
10
	private $userid;
11
	private $request;
12
	private $db;
13
	private $userManager;
14
	private $publicController;
15
16
	protected function setUp() {
17
		$this->userid = "testuser";
18
		$this->request = \OC::$server->getRequest();
19
		$this->db = \OC::$server->getDb();
20
		$this->userManager = \OC::$server->getUserManager();
21
		$this->publicController = new PublicController("bookmarks", $this->request, $this->db, $this->userManager);
22
	}
23
24 View Code Duplication
	function testPublicQueryNoUser() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
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...
25
		$output = $this->publicController->returnAsJson(null, "apassword", null);
26
		$data = $output->getData();
27
		$status = $data['status'];
28
		$this->assertEquals($status, 'error');
29
	}
30
31 View Code Duplication
	function testPublicQueryWrongUser() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
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...
32
		$output = $this->publicController->returnAsJson("cqc43dr4rx3x4xatr4", "apassword", null);
33
		$data = $output->getData();
34
		$status = $data['status'];
35
		$this->assertEquals($status, 'error');
36
	}
37
38
	function testPublicQuery() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
39
40
		Bookmarks::addBookmark($this->userid, $this->db, "http://www.golem.de", "Golem", array("four"), "PublicNoTag", true);
41
		Bookmarks::addBookmark($this->userid, $this->db, "http://www.9gag.com", "9gag", array("two", "three"), "PublicTag", true);
42
43
		$output = $this->publicController->returnAsJson($this->userid);
44
		$data = $output->getData();
45
		$this->assertEquals(2, count($data));
46
		
47
		$this->cleanDB();
48
	}
49
50
	function cleanDB() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
51
		$query1 = OC_DB::prepare('DELETE FROM *PREFIX*bookmarks');
52
		$query1->execute();
53
		$query2 = OC_DB::prepare('DELETE FROM *PREFIX*bookmarks_tags');
54
		$query2->execute();
55
	}
56
57
}
58