Labels   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 8
eloc 18
dl 0
loc 40
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
B member() 0 19 7
A role() 0 3 1
1
<?php
2
/**
3
 * Labels file.
4
 *
5
 * @package App
6
 *
7
 * @copyright YetiForce S.A.
8
 * @license   YetiForce Public License 6.5 (licenses/LicenseEN.txt or yetiforce.com)
9
 * @author    Radosław Skrzypczak <[email protected]>
10
 */
11
12
namespace App;
13
14
/**
15
 * Labels class.
16
 */
17
class Labels
18
{
19
	/**
20
	 * Get member name.
21
	 *
22
	 * @param string $member
23
	 *
24
	 * @return string
25
	 */
26
	public static function member(string $member): string
27
	{
28
		$name = '';
29
		[$type, $id] = explode(':', $member);
30
		switch ($type) {
31
			case \App\PrivilegeUtil::MEMBER_TYPE_USERS:
32
				$name = \App\Fields\Owner::getUserLabel((int) $id) ?: '';
33
				break;
34
			case \App\PrivilegeUtil::MEMBER_TYPE_GROUPS:
35
				$name = \App\Fields\Owner::getGroupName((int) $id) ?: '';
36
				break;
37
			case \App\PrivilegeUtil::MEMBER_TYPE_ROLES:
38
			case \App\PrivilegeUtil::MEMBER_TYPE_ROLE_AND_SUBORDINATES:
39
				$name = self::role($id);
40
				break;
41
			default:
42
				break;
43
		}
44
		return $name;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $name could return the type true which is incompatible with the type-hinted return string. Consider adding an additional type-check to rule them out.
Loading history...
45
	}
46
47
	/**
48
	 * Get role name.
49
	 *
50
	 * @param string $roleId
51
	 *
52
	 * @return string
53
	 */
54
	public static function role(string $roleId): string
55
	{
56
		return \App\PrivilegeUtil::getRoleDetail($roleId)['rolename'] ?? '';
57
	}
58
}
59