Completed
Push — master ( e3f775...b25e7b )
by Patrick
03:18
created

AuthProvider   C

Complexity

Total Complexity 63

Size/Duplication

Total Lines 520
Duplicated Lines 20.19 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 13
Bugs 5 Features 4
Metric Value
c 13
b 5
f 4
dl 105
loc 520
rs 5.8893
wmc 63
lcom 1
cbo 3

24 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getUserByLogin() 0 14 3
A login() 0 16 3
A isLoggedIn() 0 5 1
A getUser() 0 5 1
A mergeResult() 0 13 3
A callOnEach() 18 18 4
A addFromEach() 18 18 4
A getGroupByName() 9 9 2
A getUsersByFilter() 9 9 2
A getPendingUsersByFilter() 9 9 2
A getGroupsByFilter() 9 9 2
A getActiveUserCount() 0 9 2
A getPendingUserCount() 0 9 2
A getGroupCount() 0 9 2
A getSupplementaryLinks() 6 15 3
A impersonateUser() 0 8 2
A getTempUserByHash() 9 9 2
B createPendingUser() 0 23 5
B activatePendingUser() 0 24 5
A getUserByResetHash() 0 13 3
A getSuplementalProviderByHost() 9 17 4
A deletePendingUsersByFilter() 0 14 3
A getUserByAccessCode() 9 9 2

How to fix   Duplicated Code    Complexity   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

Complex Class

 Tip:   Before tackling complexity, make sure that you eliminate any duplication first. This often can reduce the size of classes significantly.

Complex classes like AuthProvider often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use AuthProvider, and based on these observations, apply Extract Interface, too.

1
<?php
2
/**
3
 * AuthProvider class
4
 *
5
 * This file describes the AuthProvider Singleton
6
 *
7
 * PHP version 5 and 7
8
 *
9
 * @author Patrick Boyd / [email protected]
10
 * @copyright Copyright (c) 2015, Austin Artistic Reconstruction
11
 * @license http://www.apache.org/licenses/ Apache 2.0 License
12
 */
13
14
/**
15
 * Allow other classes to be loaded as needed
16
 */
17
require_once('Autoload.php');
18
19
/**
20
 * A Singleton class to abstract access to the authentication providers.
21
 *
22
 * This class is the primary method to access user data, login, and other authenication information.
23
 */
24
class AuthProvider extends Provider
25
{
26
    /**
27
     * Load the authentrication providers specified in the Settings $authProviders array
28
     *
29
     * @SuppressWarnings("StaticAccess")
30
     */
31
    protected function __construct()
32
    {
33
        $settings = \Settings::getInstance();
34
        $this->methods = $settings->getClassesByPropName('authProviders');
35
    }
36
37
    /**
38
     * Get the Auth\User class instance for the specified login
39
     *
40
     * Unlike the AuthProvider::login() function. This function will not impact the SESSION
41
     *
42
     * @param string $username The username of the User
43
     * @param string $password The password of the User
44
     *
45
     * @return Auth\User|false The User with the specified credentials or false if the credentials are not valid
46
     */
47
    public function getUserByLogin($username, $password)
48
    {
49
        $res = false;
50
        $count = count($this->methods);
51
        for($i = 0; $i < $count; $i++)
52
        {
53
            $res = $this->methods[$i]->login($username, $password);
54
            if($res !== false)
55
            {
56
                return $this->methods[$i]->getUser($res);
57
            }
58
        }
59
        return $res;
60
    }
61
62
    /**
63
     * Use the provided credetials to log the user on
64
     *
65
     * @param string $username The username of the User
66
     * @param string $password The password of the User
67
     *
68
     * @return true|false true if the login was successful, false otherwise
69
     */
70
    public function login($username, $password)
71
    {
72
        $res = false;
73
        $count = count($this->methods);
74
        for($i = 0; $i < $count; $i++)
75
        {
76
            $res = $this->methods[$i]->login($username, $password);
77
            if($res !== false)
78
            {
79
                FlipSession::setVar('AuthMethod', get_class($this->methods[$i]));
80
                FlipSession::setVar('AuthData', $res);
81
                break;
82
            }
83
        }
84
        return $res;
85
    }
86
87
    /**
88
     * Determine if the user is still logged on from the session data
89
     *
90
     * @param stdClass $data The AuthData from the session
91
     * @param string $methodName The AuthMethod from the session
92
     *
93
     * @return true|false true if user is logged on, false otherwise
94
     */
95
    public function isLoggedIn($data, $methodName)
96
    {
97
        $auth = $this->getMethodByName($methodName);
98
        return $auth->isLoggedIn($data);
99
    }
100
101
    /**
102
     * Obtain the currently logged in user from the session data
103
     *
104
     * @param stdClass $data The AuthData from the session
105
     * @param string $methodName The AuthMethod from the session
106
     *
107
     * @return Auth\User|false The User instance if user is logged on, false otherwise
108
     */
109
    public function getUser($data, $methodName)
110
    {
111
        $auth = $this->getMethodByName($methodName);
112
        return $auth->getUser($data);
113
    }
114
115
    /**
116
     * Merge or set the returnValue as appropriate
117
     *
118
     * @param false|Auth\Group|Auth\User $returnValue The value to merge to
119
     * @param Auth\Group|Auth\User $res The value to merge from
120
     *
121
     * @return Auth\Group|false The merged returnValue
122
     */
123
    private function mergeResult(&$returnValue, $res)
124
    {
125
        if($res === false)
126
        {
127
            return;
128
        }
129
        if($returnValue === false)
130
        {
131
            $returnValue = $res;
132
            return;
133
        }
134
        $returnValue->merge($res);
135
    }
136
137
    /**
138
     * Calls the indicated function on each Authenticator and merges the result
139
     *
140
     * @param string $functionName The function to call
141
     * @param array $args The arguments for the function
142
     * @param string $checkField A field to check if it is set a certain way before calling the function
143
     * @param mixed $checkValue The value that field should be set to to not call the function
144
     *
145
     * @return Auth\Group|Auth\User|false The merged returnValue
146
     */
147 View Code Duplication
    private function callOnEach($functionName, $args, $checkField = false, $checkValue = false)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
148
    {
149
        $ret = false;
150
        $count = count($this->methods);
151
        for($i = 0; $i < $count; $i++)
152
        {
153
            if($checkField !== false)
154
            {
155
                if($this->methods[$i]->{$checkField} === $checkValue)
156
                {
157
                    continue;
158
                }
159
            }
160
            $res = call_user_func_array(array($this->methods[$i], $functionName), $args);
161
            $this->mergeResult($ret, $res);
162
        }
163
        return $ret;
164
    }
165
166
    /**
167
     * Calls the indicated function on each Authenticator and add the result
168
     *
169
     * @param string $functionName The function to call
170
     * @param string $checkField A field to check if it is set a certain way before calling the function
171
     * @param mixed $checkValue The value that field should be set to to not call the function
172
     *
173
     * @return integer The added returnValue
174
     */
175 View Code Duplication
    private function addFromEach($functionName, $checkField = false, $checkValue = false)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
176
    {
177
        $retCount = 0;
178
        $count = count($this->methods);
179
        for($i = 0; $i < $count; $i++)
180
        {
181
            if($checkField !== false)
182
            {
183
                if($this->methods[$i]->{$checkField} === $checkValue)
184
                {
185
                    continue;
186
                }
187
            }
188
            $res = call_user_func(array($this->methods[$i], $functionName));
189
            $retCount += $res;
190
        }
191
        return $retCount;
192
    }
193
194
    /**
195
     * Get an Auth\Group by its name
196
     *
197
     * @param string $name The name of the group
198
     * @param string $methodName The AuthMethod if information is desired only from a particular Auth\Authenticator
199
     *
200
     * @return Auth\Group|false The Group instance if a group with that name exists, false otherwise
201
     */
202 View Code Duplication
    public function getGroupByName($name, $methodName = false)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
203
    {
204
        if($methodName === false)
205
        {
206
            return $this->callOnEach('getGroupByName', array($name));
207
        }
208
        $auth = $this->getMethodByName($methodName);
209
        return $auth->getGroupByName($name);
210
    }
211
212
    /**
213
     * Get an array of Auth\User from a filtered set
214
     *
215
     * @param Data\Filter|boolean $filter The filter conditions or false to retreive all
216
     * @param array|boolean $select The user fields to obtain or false to obtain all
217
     * @param integer|boolean $top The number of users to obtain or false to obtain all
218
     * @param integer|boolean $skip The number of users to skip or false to skip none
219
     * @param array|boolean $orderby The field to sort by and the method to sort or false to not sort
220
     * @param string|boolean $methodName The AuthMethod if information is desired only from a particular Auth\Authenticator
221
     *
222
     * @return array|boolean An array of Auth\User objects or false if no users were found
223
     */
224 View Code Duplication
    public function getUsersByFilter($filter, $select = false, $top = false, $skip = false, $orderby = false, $methodName = false)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
225
    {
226
        if($methodName === false)
227
        {
228
            return $this->callOnEach('getUsersByFilter', array($filter, $select, $top, $skip, $orderby), 'current');
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this->callOnEach... $orderby), 'current'); (false|Auth\Group|Auth\User) is incompatible with the return type documented by AuthProvider::getUsersByFilter of type array|boolean.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
229
        }
230
        $auth = $this->getMethodByName($methodName);
0 ignored issues
show
Bug introduced by
It seems like $methodName defined by parameter $methodName on line 224 can also be of type boolean; however, Provider::getMethodByName() does only seem to accept string, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
231
        return $auth->getUsersByFilter($filter, $select, $top, $skip, $orderby);
232
    }
233
234
    /**
235
     * Get an array of Auth\PendingUser from a filtered set
236
     *
237
     * @param Data\Filter|boolean $filter The filter conditions or false to retreive all
238
     * @param array|boolean $select The user fields to obtain or false to obtain all
239
     * @param integer|boolean $top The number of users to obtain or false to obtain all
240
     * @param integer|boolean $skip The number of users to skip or false to skip none
241
     * @param array|boolean $orderby The field to sort by and the method to sort or false to not sort
242
     * @param string|boolean $methodName The AuthMethod if information is desired only from a particular Auth\Authenticator
243
     *
244
     * @return array|boolean An array of Auth\PendingUser objects or false if no pending users were found
245
     */
246 View Code Duplication
    public function getPendingUsersByFilter($filter, $select = false, $top = false, $skip = false, $orderby = false, $methodName = false)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
247
    {
248
        if($methodName === false)
249
        {
250
            return $this->callOnEach('getPendingUsersByFilter', array($filter, $select, $top, $skip, $orderby), 'pending');
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this->callOnEach... $orderby), 'pending'); (false|Auth\Group|Auth\User) is incompatible with the return type documented by AuthProvider::getPendingUsersByFilter of type array|boolean.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
251
        }
252
        $auth = $this->getMethodByName($methodName);
0 ignored issues
show
Bug introduced by
It seems like $methodName defined by parameter $methodName on line 246 can also be of type boolean; however, Provider::getMethodByName() does only seem to accept string, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
253
        return $auth->getPendingUsersByFilter($filter, $select, $top, $skip, $orderby);
254
    }
255
256
    /**
257
     * Get an array of Auth\Group from a filtered set
258
     *
259
     * @param Data\Filter|false $filter The filter conditions or false to retreive all
260
     * @param array|false $select The group fields to obtain or false to obtain all
261
     * @param integer|false $top The number of groups to obtain or false to obtain all
262
     * @param integer|false $skip The number of groups to skip or false to skip none
263
     * @param array|false $orderby The field to sort by and the method to sort or false to not sort
264
     * @param string|false $methodName The AuthMethod if information is desired only from a particular Auth\Authenticator
265
     *
266
     * @return array|false An array of Auth\Group objects or false if no pending users were found
267
     */
268 View Code Duplication
    public function getGroupsByFilter($filter, $select = false, $top = false, $skip = false, $orderby = false, $methodName = false)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
269
    {
270
        if($methodName === false)
271
        {
272
            return $this->callOnEach('getGroupsByFilter', array($filter, $select, $top, $skip, $orderby), 'current');
273
        }
274
        $auth = $this->getMethodByName($methodName);
275
        return $auth->getGroupsByFilter($filter, $select, $top, $skip, $orderby);
276
    }
277
278
    /**
279
     * Get the number of currently active users on the system
280
     *
281
     * @param string|false $methodName The AuthMethod if information is desired only from a particular Auth\Authenticator
282
     *
283
     * @return integer The number of currently active users on the system
284
     */
285
    public function getActiveUserCount($methodName = false)
286
    {
287
        if($methodName === false)
288
        {
289
            return $this->addFromEach('getActiveUserCount', 'current');
290
        }
291
        $auth = $this->getMethodByName($methodName);
292
        return $auth->getActiveUserCount();
293
    }
294
295
    /**
296
     * Get the number of currently pending users on the system
297
     *
298
     * @param string|false $methodName The AuthMethod if information is desired only from a particular Auth\Authenticator
299
     *
300
     * @return integer The number of currently pending users on the system
301
     */
302
    public function getPendingUserCount($methodName = false)
303
    {
304
        if($methodName === false)
305
        {
306
            return $this->addFromEach('getPendingUserCount', 'pending');
307
        }
308
        $auth = $this->getMethodByName($methodName);
309
        return $auth->getPendingUserCount();
310
    }
311
312
    /**
313
     * Get the number of current groups on the system
314
     *
315
     * @param string|false $methodName The AuthMethod if information is desired only from a particular Auth\Authenticator
316
     *
317
     * @return integer The number of current groups on the system
318
     */
319
    public function getGroupCount($methodName = false)
320
    {
321
        if($methodName === false)
322
        {
323
            return $this->addFromEach('getGroupCount', 'current');
324
        }
325
        $auth = $this->getMethodByName($methodName);
326
        return $auth->getGroupCount();
327
    }
328
329
    /**
330
     * Get the login links for all supplementary Authenitcation mechanisms
331
     *
332
     * This will return an array of links to any supplementary authentication mechanims. For example, Goodle is 
333
     * a supplementary authentication mechanism.
334
     *
335
     * @return array An array of suppmentary authentication mechanism links
336
     */
337
    public function getSupplementaryLinks()
338
    {
339
        $ret = array();
340
        $count = count($this->methods);
341 View Code Duplication
        for($i = 0; $i < $count; $i++)
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
342
        {
343
            if($this->methods[$i]->supplement === false)
344
            {
345
                continue;
346
            }
347
348
            array_push($ret, $this->methods[$i]->getSupplementLink());
349
        }
350
        return $ret;
351
    }
352
353
    /**
354
     * Impersonate the user specified
355
     *
356
     * This will replace the user in the session with the specified user. In order
357
     * to undo this operation a user must logout.
358
     *
359
     * @param array|Auth\User $userArray Data representing the user
360
     */
361
    public function impersonateUser($userArray)
362
    {
363
        if(!is_object($userArray))
364
        {
365
            $userArray = new $userArray['class']($userArray);
366
        }
367
        \FlipSession::setUser($userArray);
368
    }
369
370
    /**
371
     * Get the pending user reresented by the supplied hash
372
     *
373
     * @param string $hash The hash value representing the Penging User
374
     * @param string|false $methodName The AuthMethod if information is desired only from a particular Auth\Authenticator
375
     *
376
     * @return Auth\PendingUser|false The Auth\PendingUser instance or false if no user is matched by the provided hash
377
     */
378 View Code Duplication
    public function getTempUserByHash($hash, $methodName = false)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
379
    {
380
        if($methodName === false)
381
        {
382
            return $this->callOnEach('getTempUserByHash', array($hash), 'pending');
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->callOnEach('getTe...ray($hash), 'pending'); of type false|Auth\Group|Auth\User adds the type Auth\Group to the return on line 382 which is incompatible with the return type documented by AuthProvider::getTempUserByHash of type Auth\PendingUser|false.
Loading history...
383
        }
384
        $auth = $this->getMethodByName($methodName);
385
        return $auth->getTempUserByHash($hash);
386
    }
387
388
    /**
389
     * Create a pending user
390
     *
391
     * @param array $user An array of information about the user to create
392
     * @param string|false $methodName The AuthMethod if information is desired only from a particular Auth\Authenticator
393
     *
394
     * @return boolean true if the user was successfully created. Otherwise false.
395
     */
396
    public function createPendingUser($user, $methodName = false)
397
    {
398
        if($methodName === false)
399
        {
400
            $count = count($this->methods);
401
            for($i = 0; $i < $count; $i++)
402
            {
403
                if($this->methods[$i]->pending === false)
404
                {
405
                    continue;
406
                }
407
408
                $ret = $this->methods[$i]->createPendingUser($user);
409
                if($ret !== false)
410
                {
411
                    return true;
412
                }
413
            }
414
            return false;
415
        }
416
        $auth = $this->getMethodByName($methodName);
417
        return $auth->createPendingUser($user);
418
    }
419
420
    /**
421
     * Convert a Auth\PendingUser into an Auth\User
422
     *
423
     * This will allow a previously pending user the ability to log on in the future as an active user. It will also
424
     * have the side effect of logging the user on now.
425
     *
426
     * @param Auth\PendingUser $user The user to turn into a current user
427
     * @param string|false $methodName The AuthMethod if information is desired only from a particular Auth\Authenticator
428
     *
429
     * @return boolean true if the user was successfully created. Otherwise false.
430
     */
431
    public function activatePendingUser($user, $methodName = false)
432
    {
433
        if($methodName === false)
434
        {
435
            $count = count($this->methods);
436
            for($i = 0; $i < $count; $i++)
437
            {
438
                if($this->methods[$i]->current === false)
439
                {
440
                    continue;
441
                }
442
443
                $ret = $this->methods[$i]->activatePendingUser($user);
444
                if($ret !== false)
445
                {
446
                    $this->impersonateUser($ret);
447
                    return true;
448
                }
449
            }
450
            return false;
451
        }
452
        $auth = $this->getMethodByName($methodName);
453
        return $auth->activatePendingUser($user);
454
    }
455
456
    /**
457
     * Get a current user by a password reset hash
458
     *
459
     * @param string $hash The current password reset hash for the user
460
     * @param string|false $methodName The AuthMethod if information is desired only from a particular Auth\Authenticator
461
     *
462
     * @return Auth\User|false The user if the password reset hash is valid. Otherwise false.
463
     */
464
    public function getUserByResetHash($hash, $methodName = false)
465
    {
466
        if($methodName === false)
467
        {
468
            return $this->callOnEach('getUserByResetHash', array($hash), 'current');
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->callOnEach('getUs...ray($hash), 'current'); of type false|Auth\Group|Auth\User adds the type Auth\Group to the return on line 468 which is incompatible with the return type documented by AuthProvider::getUserByResetHash of type Auth\User|false.
Loading history...
469
        }
470
        $auth = $this->getMethodByName($methodName);
471
        if($auth === false)
472
        {
473
            return $this->getUserByResetHash($hash, false);
474
        }
475
        return $auth->getUserByResetHash($hash);
476
    }
477
478
    /**
479
     * Get the Auth\Authenticator by host name
480
     *
481
     * @param string $host The host name used by the supplemental authentication mechanism
482
     *
483
     * @return Auth\Authenticator|false The Authenticator if the host is supported by a loaded Authenticator. Otherwise false.
484
     */
485
    public function getSuplementalProviderByHost($host)
486
    {
487
        $count = count($this->methods);
488 View Code Duplication
        for($i = 0; $i < $count; $i++)
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
489
        {
490
            if($this->methods[$i]->supplement === false)
491
            {
492
                continue;
493
            }
494
495
            if($this->methods[$i]->getHostName() === $host)
496
            {
497
                return $this->methods[$i];
498
            }
499
        }
500
        return false;
501
    }
502
503
    /**
504
     * Delete any pending users that match the filter
505
     *
506
     * @param \Data\Filter|boolean $filter The filter to delete with or false to delete all
507
     * @param string|boolean $methodName The AuthMethod if information is desired only from a particular Auth\Authenticator
508
     *
509
     * @return boolean True if the users were deleted, false otherwise
510
     */
511
    public function deletePendingUsersByFilter($filter, $methodName = false)
512
    {
513
        $users = $this->getPendingUsersByFilter($filter, false, false, false, false, $methodName);
514
        if($users === false)
515
        {
516
            return false;
517
        }
518
        $count = count($users);
519
        for($i = 0; $i < $count; $i++)
520
        {
521
            $users[$i]->delete();
522
        }
523
        return true;
524
    }
525
526
    /**
527
     * Get the user by the one time access code
528
     *
529
     * @param string $key The user's access code
530
     * @param string|boolean $methodName The AuthMethod if information is desired only from a particular Auth\Authenticator
531
     *
532
     * @return boolean|\Auth\User The User specified by the access code or false otherwise
533
     */
534 View Code Duplication
    public function getUserByAccessCode($key, $methodName = false)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
535
    {
536
        if($methodName === false)
537
        {
538
            return $this->callOnEach('getUserByAccessCode', array($key), 'current');
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->callOnEach('getUs...rray($key), 'current'); of type false|Auth\Group|Auth\User adds the type Auth\Group to the return on line 538 which is incompatible with the return type documented by AuthProvider::getUserByAccessCode of type boolean|Auth\User.
Loading history...
539
        }
540
        $auth = $this->getMethodByName($methodName);
0 ignored issues
show
Bug introduced by
It seems like $methodName defined by parameter $methodName on line 534 can also be of type boolean; however, Provider::getMethodByName() does only seem to accept string, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
541
        return $auth->getUserByAccessCode($key);
542
    }
543
}
544
/* vim: set tabstop=4 shiftwidth=4 expandtab: */
545