GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

UserService   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 0

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 9
c 2
b 0
f 0
lcom 2
cbo 0
dl 0
loc 63
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getCurrentUser() 0 3 1
A isUserDeleteable() 0 10 2
A isUserAllowedToManageUsers() 0 17 3
A setEventManager() 0 7 1
A getEventManager() 0 3 1
1
<?php
2
3
/**
4
 * @author Steven Bühner
5
 * @license MIT
6
 */
7
namespace HtpasswdManager\Service;
8
9
use Zend\Http\Request;
10
use Zend\EventManager\EventManagerAwareInterface;
11
use Zend\EventManager\EventManagerInterface;
12
13
class UserService implements EventManagerAwareInterface {
14
	protected $request;
15
	protected $not_deletable_users;
16
	protected $user_with_management_permission;
17
	protected $eventManager;
18
19
	public function __construct(Request $request, $not_deletable_users, $user_with_management_permission) {
0 ignored issues
show
Coding Style Naming introduced by
The parameter $not_deletable_users is not named in camelCase.

This check marks parameter names that have not been written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection string becomes databaseConnectionString.

Loading history...
Coding Style Naming introduced by
The parameter $user_with_management_permission is not named in camelCase.

This check marks parameter names that have not been written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection string becomes databaseConnectionString.

Loading history...
20
		$this->request = $request;
21
		$this->not_deletable_users = $not_deletable_users;
22
		$this->user_with_management_permission = $user_with_management_permission;
23
	}
24
25
	/**
26
	 * Return the current used user
27
	 *
28
	 * @return string
29
	 */
30
	public function getCurrentUser() {
31
		return $this->request->getServer ()->get ( 'REMOTE_USER', null );
32
	}
33
34
	public function isUserDeleteable($username) {
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
35
		$eResult = $this->getEventManager ()->trigger ( 'pre_' . __FUNCTION__, $this, array( 
36
				$username 
37
		) );
38
		
39
		if ($eResult->stopped ())
40
			return $eResult->last ();
41
		
42
		return ! in_array ( $username, $this->not_deletable_users );
43
	}
44
45
	public function isUserAllowedToManageUsers($username) {
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
46
		$eResult = $this->getEventManager ()->trigger ( 'pre_' . __FUNCTION__, $this, array( 
47
				'user' => $username 
48
		) );
49
		
50
		if ($eResult->stopped ())
51
			return $eResult->last ();
52
			
53
			/* If parameter is an array => allow only users in list. IF parameter is boolean, return boolean value */
54
		if (is_array ( $this->user_with_management_permission )) {
55
			$accessAllowed = in_array ( $username, $this->user_with_management_permission );
56
		} else {
57
			$accessAllowed = ($this->user_with_management_permission === true);
58
		}
59
		
60
		return $accessAllowed;
61
	}
62
63
	public function setEventManager(EventManagerInterface $eventManager) {
64
		$eventManager->setIdentifiers ( array( 
65
				__CLASS__,
66
				get_class ( $this ) 
67
		) );
68
		$this->eventManager = $eventManager;
69
	}
70
71
	public function getEventManager() {
72
		return $this->eventManager;
73
	}
74
75
}
76