1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SkautisBundle\Security\Authentication; |
4
|
|
|
|
5
|
|
|
|
6
|
|
|
use SkautisBundle\Security\Authentication\Connector\SkautisUserConnectorInterface; |
7
|
|
|
use SkautisBundle\Security\Authentication\Registrator\UserRegistratorInterface; |
8
|
|
|
|
9
|
|
|
class UserLoader |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* @var bool |
13
|
|
|
*/ |
14
|
|
|
private $enableConnector ; |
15
|
|
|
/** |
16
|
|
|
* @var SkautisUserConnectorInterface |
17
|
|
|
*/ |
18
|
|
|
private $userConnector; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @var bool |
22
|
|
|
*/ |
23
|
|
|
private $enableAutoRegister; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @var UserRegistratorInterface |
27
|
|
|
*/ |
28
|
|
|
private $userRegistrator; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* UserLoader constructor. |
32
|
|
|
* @param bool $enableConnector |
33
|
|
|
* @param SkautisUserConnectorInterface $userConnector |
34
|
|
|
* @param bool $enableAutoRegister |
35
|
|
|
* @param UserRegistratorInterface $userRegistrator |
36
|
|
|
*/ |
37
|
|
|
public function __construct($enableConnector = false, SkautisUserConnectorInterface $userConnector = null, $enableAutoRegister = false, UserRegistratorInterface $userRegistrator = null) |
38
|
|
|
{ |
39
|
|
|
$this->enableConnector = $enableConnector; |
40
|
|
|
$this->userConnector = $userConnector; |
41
|
|
|
$this->enableAutoRegister = $enableAutoRegister; |
42
|
|
|
$this->userRegistrator = $userRegistrator; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
|
46
|
|
|
public function loadUser($personId, $userProvider) |
47
|
|
|
{ |
48
|
|
|
if (!$this->enableConnector) { |
49
|
|
|
return null; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
if (!$this->userConnector) { |
53
|
|
|
throw new \Exception("No userConnector set while autoregistration enabled"); //@TODO custom exception |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
$user = null; |
|
|
|
|
57
|
|
|
$username = $this->userConnector->getUsername($personId); |
58
|
|
|
if (!empty($username)) { |
59
|
|
|
return $userProvider->loadUserByUsername($username); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
|
63
|
|
|
if (!$this->enableAutoRegister) { |
64
|
|
|
return null; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
if (!$this->userRegistrator) { |
68
|
|
|
throw new \Exception("No registrator set while autoregistration enabled"); //@TODO custom exception |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
$username = $this->userRegistrator->registerUser(); //@TODO log registration |
72
|
|
|
$this->userConnector->connect($personId, $username); |
73
|
|
|
|
74
|
|
|
return $userProvider->loadUserByUsername($username); |
75
|
|
|
} |
76
|
|
|
} |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.