FreeBusyModule::addUserData()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 20
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 11
nc 2
nop 1
dl 0
loc 20
rs 9.9
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * FreeBusyModule Module.
5
 */
6
class FreeBusyModule extends Module {
7
	public function __construct($id, $data) {
8
		parent::__construct($id, $data);
9
	}
10
11
	#[Override]
12
	public function execute() {
13
		foreach ($this->data as $actionType => $selUser) {
14
			if (isset($actionType)) {
15
				try {
16
					match ($actionType) {
17
						'list' => $this->addUserData($selUser),
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->addUserData($selUser) targeting FreeBusyModule::addUserData() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
18
						default => $this->handleUnknownActionType($actionType),
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->handleUnknownActionType($actionType) targeting Module::handleUnknownActionType() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
19
					};
20
				}
21
				catch (MAPIException $e) {
0 ignored issues
show
Bug introduced by
The type MAPIException was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
22
					$this->processException($e, $actionType);
23
				}
24
			}
25
		}
26
	}
27
28
	/**
29
	 * This function will get user info from address book and add freebusy data of the user to
30
	 * response.
31
	 *
32
	 * @param array $selUser User that should be resolved
33
	 */
34
	public function addUserData($selUser) {
35
		$data = [
36
			'users' => [],
37
		];
38
39
		foreach ($selUser['users'] as $fbUser) {
40
			// Copy the identifier of the user.
41
			$user = [
42
				'userid' => $fbUser['userid'],
43
				'entryid' => $fbUser['entryid'],
44
			];
45
46
			// Obtain the Freebusy data for this user
47
			$busyArray = $this->getFreeBusyInfo($fbUser['entryid'], $selUser['start'], $selUser['end']);
48
			$user['items'] = $busyArray;
49
			$data['users'][] = $user;
50
		}
51
52
		$this->addActionData('list', $data);
53
		$GLOBALS['bus']->addData($this->getResponseData());
54
	}
55
56
	/**
57
	 * This function will get freebusy data for user based on the timeframe passed in arguments.
58
	 *
59
	 * @param string $entryID Entryid of the user for which we need to get freebusy data
60
	 * @param int    $start   start offset for freebusy publish range
61
	 * @param int    $end     end offset for freebusy publish range
62
	 *
63
	 * @return array freebusy blocks for passed publish range
64
	 */
65
	public function getFreeBusyInfo($entryID, $start, $end) {
66
		$result = [];
67
		try {
68
			$fbdata = mapi_getuserfreebusy($GLOBALS['mapisession']->getSession(), hex2bin($entryID), $start, $end);
69
	
70
			foreach ($fbdata['fbevents'] as $event) {
71
				$result[] = [
72
					'start' => $event['start'],
73
					'end' => $event['end'],
74
					'status' => $event['busystatus'],
75
				];
76
			}
77
		}
78
		catch (Exception $e) {
79
			error_log(sprintf("getFreeBusyInfo exception: %s (0x%08X)", $e->getMessage(), $e->getCode()));
80
			$result[] = [
81
				'start' => $start,
82
				'end' => $end,
83
				'status' => fbNoData,
84
			];
85
		}
86
87
		return $result;
88
	}
89
}
90