GetUsers::execute()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 14
rs 9.4285
cc 2
eloc 8
nc 2
nop 0
1
<?php
2
/**
3
 * Copyright (c) 2014, Tobia De Koninck hey--at--ledfan.be
4
 * This file is licensed under the AGPL version 3 or later.
5
 * See the COPYING file.
6
 */
7
8
namespace OCA\Chat\OCH\Data;
9
10
use \OCA\Chat\OCH\ChatAPI;
11
use \OCA\Chat\App\Chat;
12
use \OCA\Chat\OCH\Db\UserMapper;
13
14
15
class GetUsers extends ChatAPI {
16
17
	/**
18
	 * @var $userMapper \OCA\Chat\OCH\Db\UserMapper
19
	 */
20
	private $userMapper;
21
22
	public function __construct(
23
		Chat $app,
24
		UserMapper $userMapper
25
	){
26
		$this->app = $app;
0 ignored issues
show
Bug introduced by
The property app does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
27
		$this->userMapper = $userMapper;
28
	}
29
30
	/*
31
	 * @param $requestData['user'] String user id of the client
32
	 * @param $requestData['convid'] String session_id of the client
33
	 */
34
	public function setRequestData(array $requestData){
35
		$this->requestData = $requestData;
36
	}
37
38
	public function execute(){
39
		$contacts = $this->app->getContacts();
40
		$contacts = $contacts['contactsObj'];
41
		
42
		$users = $this->userMapper->findUsersInConv($this->requestData['conv_id']);
43
		
44
		$return = array();
45
		foreach($users as $user){
46
			$return[] = $contacts[$user];
47
		}
48
49
		// Note: users are full contacts
50
		return array("users" => $return);
51
	}
52
}
53