Completed
Pull Request — master (#3233)
by Jan-Christoph
12:25
created

ContactsMenuController::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 3
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * @copyright 2017 Christoph Wurst <[email protected]>
5
 *
6
 * @author 2017 Christoph Wurst <[email protected]>
7
 *
8
 * @license GNU AGPL version 3 or any later version
9
 *
10
 * This program is free software: you can redistribute it and/or modify
11
 * it under the terms of the GNU Affero General Public License as
12
 * published by the Free Software Foundation, either version 3 of the
13
 * License, or (at your option) any later version.
14
 *
15
 * This program is distributed in the hope that it will be useful,
16
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 * GNU Affero General Public License for more details.
19
 *
20
 * You should have received a copy of the GNU Affero General Public License
21
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
22
 *
23
 */
24
25
namespace OC\Core\Controller;
26
27
use OC\Contacts\ContactsMenu\Manager;
28
use OCP\AppFramework\Controller;
29
use OCP\AppFramework\Http\JSONResponse;
30
use OCP\IRequest;
31
use OCP\IUserSession;
32
33
class ContactsMenuController extends Controller {
34
35
	/** @var Manager */
36
	private $manager;
37
38
	/** @var IUserSession */
39
	private $userSession;
40
41
	/**
42
	 * @param IRequest $request
43
	 * @param IUserSession $userSession
44
	 * @param Manager $manager
45
	 */
46
	public function __construct(IRequest $request, IUserSession $userSession, Manager $manager) {
47
		parent::__construct('core', $request);
48
		$this->userSession = $userSession;
49
		$this->manager = $manager;
50
	}
51
52
	/**
53
	 * @NoAdminRequired
54
	 *
55
	 * @param string|null filter
56
	 * @return JSONResponse
57
	 */
58
	public function index($filter = null) {
59
		return $this->manager->getEntries($this->userSession->getUser(), $filter);
0 ignored issues
show
Bug introduced by
It seems like $this->userSession->getUser() can be null; however, getEntries() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
60
	}
61
62
}
63