config.php ➔ roles_get_roles_config()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 70
Code Lines 40

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 40
nc 2
nop 4
dl 0
loc 70
rs 9.1724
c 0
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
/**
4
 * 
5
 * Provides the default roles configuration array. Triggered by the 'roles:config' hook.
6
 * 
7
 * When implementing specific roles, authors should register for the same hook their handler.
8
 * The handler should merge new role values into the existing configuration array
9
 * Examples of this can be seen in the roles_moderators and roles_group_amins plugins
10
 * 
11
 * @param string $hook_name    Equals "roles:config"
12
 * @param string $entity_type  Equals "role"
13
 * @param mixed  $return_value The array of already initialized role configuration values
14
 * @param mixed  $params       Hook params (not in use)
15
 * @return array The role configuration
16
 */
17
function roles_get_roles_config($hook_name, $entity_type, $return_value, $params) {
0 ignored issues
show
Unused Code introduced by
The parameter $hook_name is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $entity_type is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $params is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
18
19
	$roles = array(
20
21
		VISITOR_ROLE => array(
22
			'title' => 'roles:role:VISITOR_ROLE',
23
			'extends' => array(),
24
			'permissions' => array(
25
				'actions' => array(
26
				),
27
				'menus' => array(
28
				),
29
				'views' => array(
30
				),
31
				'hooks' => array(
32
				),
33
			),
34
		),
35
36
		DEFAULT_ROLE => array(
37
			'title' => 'roles:role:DEFAULT_ROLE',
38
			'extends' => array(),
39
			'permissions' => array(
40
				'actions' => array(
41
				),
42
				'menus' => array(
43
				),
44
				'views' => array(
45
				),
46
				'hooks' => array(
47
				),
48
			),
49
		),
50
51
		ADMIN_ROLE => array(
52
			'title' => 'roles:role:ADMIN_ROLE',
53
			'extends' => array(),
54
			'permissions' => array(
55
				'actions' => array(
56
				),
57
				'menus' => array(
58
				),
59
				'views' => array(
60
					'forms/account/settings' => array(
61
						'rule' => 'extend',
62
						'view_extension' => array(
63
							'view' => 'roles/settings/account/role',
64
							'priority' => 150
65
						)
66
					),
67
				),
68
				'hooks' => array(
69
					'usersettings:save::user' => array(
70
						'rule' => 'extend',
71
						'hook' => array(
72
							'handler' => 'roles_user_settings_save',
73
							'priority' => 500,
74
						)
75
					),
76
				),
77
			),
78
		),
79
	);
80
81
	if (!is_array($return_value)) {
82
		return $roles;
83
	} else {
84
		return array_merge($return_value, $roles);
85
	}
86
}
87