Completed
Push — master ( 593857...cd1c2d )
by Michael
29s queued 20s
created

Factory::getAuthConnection()   B

Complexity

Conditions 10
Paths 21

Size

Total Lines 37
Code Lines 27

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 23
CRAP Score 10.1536

Importance

Changes 0
Metric Value
cc 10
eloc 27
nc 21
nop 2
dl 0
loc 37
rs 7.6666
c 0
b 0
f 0
ccs 23
cts 26
cp 0.8846
crap 10.1536

How to fix   Complexity   

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
 You may not change or alter any portion of this comment or credits
4
 of supporting developers from this source code or any supporting source code
5
 which is considered copyrighted (c) material of the original comment or credit authors.
6
7
 This program is distributed in the hope that it will be useful,
8
 but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10
*/
11
12
namespace Xoops\Auth;
13
14
/**
15
 * Authentication class factory
16
 *
17
 * @category  Xoops\Auth
18
 * @package   Factory
19
 * @author    Pierre-Eric MENUET <[email protected]>
20
 * @copyright 2000-2014 XOOPS Project (http://xoops.org)
21
 * @license   GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html)
22
 * @link      http://xoops.org
23
 * @since     2.0
24
 */
25
class Factory
26
{
27
    /**
28
     * Get a reference to the only instance of authentication class
29
     *
30
     * if the class has not been instantiated yet, this will also take
31
     * care of that
32
     *
33
     * @param string $uname user name
34
     * @param bool $_force internal use for tests
35
     *
36
     * @return AuthAbstract|bool Reference to the only instance of authentication class
37
     */
38 5
    public static function getAuthConnection($uname, $_force=false)
39
    {
40 5
        $xoops = \Xoops::getInstance();
41 5
        static $auth_instance;
42 5
        if (!isset($auth_instance) || (bool)$_force) {
43
            /* @var $config_handler XoopsConfigHandler */
44 5
            $authConfig = $xoops->getConfigs();
45 5
            if (empty($authConfig['auth_method'])) { // If there is a config error, we use xoops
46
                $xoops_auth_method = 'xoops';
47
            } else {
48 5
                $xoops_auth_method = $authConfig['auth_method'];
49
            }
50
            // Verify if uname allow to bypass LDAP auth
51 5
            if (isset($authConfig['ldap_users_bypass']) && in_array($uname, $authConfig['ldap_users_bypass'])) {
52 2
                $xoops_auth_method = 'xoops';
53
            }
54
55 5
            $class = '\Xoops\Auth\\' . ucfirst($xoops_auth_method);
56 5
            if (!class_exists($class)) {
57
                trigger_error(\XoopsLocale::EF_CLASS_NOT_FOUND, E_USER_ERROR);
58
                return false;
59
            }
60 5
            $dao = null;
61
            switch ($xoops_auth_method) {
62 5
                case 'xoops':
63 3
                    $dao = null;
64 3
                    break;
65 2
                case 'ldap':
66 1
                    $dao = null;
67 1
                    break;
68 1
                case 'ads':
69 1
                    $dao = null;
70 1
                    break;
71
            }
72 5
            $auth_instance = new $class($dao);
73
        }
74 5
        return $auth_instance;
75
    }
76
}
77