WebViewController::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 5
dl 0
loc 6
ccs 0
cts 6
cp 0
crap 2
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * ownCloud - bookmarks
5
 *
6
 * This file is licensed under the Affero General Public License version 3 or
7
 * later. See the COPYING file.
8
 *
9
 * @author Stefan Klemm <[email protected]>
10
 * @copyright Stefan Klemm 2014
11
 */
12
13
namespace OCA\Bookmarks\Controller;
14
15
use OCP\AppFramework\Http\ContentSecurityPolicy;
16
use \OCP\IRequest;
17
use \OCP\AppFramework\Http\TemplateResponse;
18
use \OCP\AppFramework\Controller;
19
use \OCP\IDb;
20
use \OCA\Bookmarks\Controller\Lib\Bookmarks;
21
use OCP\IURLGenerator;
22
23
class WebViewController extends Controller {
24
25
	/** @var  string */
26
	private $userId;
27
28
	/** @var IURLGenerator  */
29
	private $urlgenerator;
30
31
	/** @var IDb  */
32
	private $db;
33
34
	/**
35
	 * WebViewController constructor.
36
	 *
37
	 * @param string $appName
38
	 * @param IRequest $request
39
	 * @param $userId
40
	 * @param IURLGenerator $urlgenerator
41
	 * @param IDb $db
42
	 */
43
	public function __construct($appName, IRequest $request, $userId, IURLGenerator $urlgenerator, IDb $db) {
44
		parent::__construct($appName, $request);
45
		$this->userId = $userId;
46
		$this->urlgenerator = $urlgenerator;
47
		$this->db = $db;
48
	}
49
50
	/**
51
	 * @NoAdminRequired
52
	 * @NoCSRFRequired
53
	 */
54
	public function index() {
55
		$bookmarkleturl = $this->urlgenerator->getAbsoluteURL('index.php/apps/bookmarks/bookmarklet');
56
		$params = array('user' => $this->userId, 'bookmarkleturl' => $bookmarkleturl);
57
58
		$policy = new ContentSecurityPolicy();
59
		$policy->addAllowedFrameDomain("'self'");
60
61
		$response = new TemplateResponse('bookmarks', 'main', $params);
62
		$response->setContentSecurityPolicy($policy);
63
		return $response;
64
	}
65
66
	/**
67
	 * @param string $url
68
	 * @param string $title
69
	 * @return TemplateResponse
70
	 *
71
	 * @NoAdminRequired
72
	 * @NoCSRFRequired
73
	 */
74
	public function bookmarklet($url = "", $title = "") {
75
		$bookmarkExists = Bookmarks::bookmarkExists($url, $this->userId, $this->db);
76
		$description = "";
77
        $tags = [];
78
		if ($bookmarkExists !== false){
79
			$bookmark = Bookmarks::findUniqueBookmark($bookmarkExists, $this->userId, $this->db);
0 ignored issues
show
Documentation introduced by
$bookmarkExists is of type boolean, but the function expects a integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
80
			$description = $bookmark['description'];
81
            $tags = $bookmark['tags'];
82
		}
83
		$params = array(
84
            'url'           => $url,
85
            'title'         => $title,
86
            'description'   => $description,
87
            'bookmarkExists'=> $bookmarkExists,
88
            'tags'          => $tags
89
        );
90
		return new TemplateResponse('bookmarks', 'addBookmarklet', $params);  // templates/main.php
91
	}
92
93
}
94