1 | <?php |
||
36 | class ObjectRepository extends AbstractAdapter |
||
37 | { |
||
38 | /** |
||
39 | * @var AuthenticationOptions |
||
40 | */ |
||
41 | protected $options; |
||
42 | |||
43 | /** |
||
44 | * Contains the authentication results. |
||
45 | * |
||
46 | * @var array |
||
47 | */ |
||
48 | protected $authenticationResultInfo = null; |
||
49 | |||
50 | /** |
||
51 | * Constructor |
||
52 | * |
||
53 | * @param array|AuthenticationOptions $options |
||
54 | */ |
||
55 | 13 | public function __construct($options = []) |
|
56 | { |
||
57 | 13 | $this->setOptions($options); |
|
58 | 11 | } |
|
59 | |||
60 | /** |
||
61 | * @param array|AuthenticationOptions $options |
||
62 | */ |
||
63 | 13 | public function setOptions($options) |
|
64 | { |
||
65 | 13 | if (! $options instanceof AuthenticationOptions) { |
|
66 | 11 | $options = new AuthenticationOptions($options); |
|
67 | 9 | } |
|
68 | |||
69 | 11 | $this->options = $options; |
|
70 | 11 | return $this; |
|
71 | } |
||
72 | |||
73 | /** |
||
74 | * @return AuthenticationOptions |
||
75 | */ |
||
76 | public function getOptions() |
||
77 | { |
||
78 | return $this->options; |
||
79 | } |
||
80 | |||
81 | /* |
||
82 | * {@inheritDoc} |
||
83 | */ |
||
84 | 8 | public function authenticate() |
|
103 | |||
104 | /** |
||
105 | * This method attempts to validate that the record in the resultset is indeed a |
||
106 | * record that matched the identity provided to this adapter. |
||
107 | * |
||
108 | * @param object $identity |
||
109 | * @throws Exception\UnexpectedValueException |
||
110 | * @return AuthenticationResult |
||
111 | */ |
||
112 | 6 | protected function validateIdentity($identity) |
|
113 | { |
||
114 | 6 | $credentialProperty = $this->options->getCredentialProperty(); |
|
115 | 6 | $getter = 'get' . ucfirst($credentialProperty); |
|
116 | 6 | $documentCredential = null; |
|
|
|||
117 | |||
118 | 6 | if (method_exists($identity, $getter)) { |
|
119 | 3 | $documentCredential = $identity->$getter(); |
|
120 | 6 | } elseif (property_exists($identity, $credentialProperty)) { |
|
121 | 1 | $documentCredential = $identity->{$credentialProperty}; |
|
122 | 1 | } else { |
|
123 | 2 | throw new Exception\UnexpectedValueException( |
|
124 | 2 | sprintf( |
|
125 | 2 | 'Property (%s) in (%s) is not accessible. You should implement %s::%s()', |
|
126 | 2 | $credentialProperty, |
|
127 | 2 | get_class($identity), |
|
128 | 2 | get_class($identity), |
|
129 | $getter |
||
130 | 2 | ) |
|
131 | 2 | ); |
|
132 | } |
||
133 | |||
134 | 4 | $credentialValue = $this->credential; |
|
135 | 4 | $callable = $this->options->getCredentialCallable(); |
|
136 | |||
137 | 4 | if ($callable) { |
|
138 | 1 | $credentialValue = call_user_func($callable, $identity, $credentialValue); |
|
139 | 1 | } |
|
140 | |||
141 | 4 | if ($credentialValue !== true && $credentialValue !== $documentCredential) { |
|
142 | 2 | $this->authenticationResultInfo['code'] = AuthenticationResult::FAILURE_CREDENTIAL_INVALID; |
|
143 | 2 | $this->authenticationResultInfo['messages'][] = 'Supplied credential is invalid.'; |
|
144 | |||
145 | 2 | return $this->createAuthenticationResult(); |
|
146 | } |
||
147 | |||
148 | 3 | $this->authenticationResultInfo['code'] = AuthenticationResult::SUCCESS; |
|
149 | 3 | $this->authenticationResultInfo['identity'] = $identity; |
|
150 | 3 | $this->authenticationResultInfo['messages'][] = 'Authentication successful.'; |
|
151 | |||
152 | 3 | return $this->createAuthenticationResult(); |
|
153 | } |
||
154 | |||
155 | /** |
||
156 | * This method abstracts the steps involved with making sure that this adapter was |
||
157 | * indeed setup properly with all required pieces of information. |
||
158 | * |
||
159 | * @throws Exception\RuntimeException - in the event that setup was not done properly |
||
160 | */ |
||
161 | 8 | protected function setup() |
|
162 | { |
||
163 | 8 | if (null === $this->identity) { |
|
164 | 1 | throw new Exception\RuntimeException( |
|
165 | 'A value for the identity was not provided prior to authentication with ObjectRepository ' |
||
166 | . 'authentication adapter' |
||
167 | 1 | ); |
|
168 | } |
||
169 | |||
170 | 7 | if (null === $this->credential) { |
|
171 | 1 | throw new Exception\RuntimeException( |
|
172 | 'A credential value was not provided prior to authentication with ObjectRepository' |
||
173 | . ' authentication adapter' |
||
174 | 1 | ); |
|
175 | } |
||
176 | |||
177 | 6 | $this->authenticationResultInfo = [ |
|
178 | 6 | 'code' => AuthenticationResult::FAILURE, |
|
179 | 6 | 'identity' => $this->identity, |
|
180 | 6 | 'messages' => [], |
|
181 | ]; |
||
182 | 6 | } |
|
183 | |||
184 | /** |
||
185 | * Creates a Zend\Authentication\Result object from the information that has been collected |
||
186 | * during the authenticate() attempt. |
||
187 | * |
||
188 | * @return \Zend\Authentication\Result |
||
189 | */ |
||
190 | 4 | protected function createAuthenticationResult() |
|
198 | } |
||
199 |
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.