Completed
Push — master ( 7ad915...1f6acb )
by Park Jong-Hun
03:16
created

AuthManager   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 74
Duplicated Lines 24.32 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 9
c 1
b 0
f 1
lcom 1
cbo 0
dl 18
loc 74
rs 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A getInstance() 0 10 2
A setConfig() 0 4 1
A setAccountManagerConfig() 0 4 1
A setLoginManagerConfig() 0 4 1
A isDefaultAllow() 0 4 1
A getDefaultAccountManager() 9 9 1
A getDefaultLoginManager() 9 9 1

How to fix   Duplicated Code   

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:

1
<?php
2
3
namespace App\Auth;
4
5
class AuthManager
6
{
7
8
    private $config = [];
9
10
    private $accountManagerConfig = [];
11
    private $loginManagerConfig = [];
12
13
    private function __construct()
14
    {
15
    }
16
17
    /**
18
     * @return self
19
     */
20
    public static function getInstance()
21
    {
22
        static $instance = null;
23
24
        if ($instance === null) {
25
            $instance = new self();
26
        }
27
28
        return $instance;
29
    }
30
31
32
    public function setConfig(array $config)
33
    {
34
        $this->config = $config;
35
    }
36
37
    public function setAccountManagerConfig(array $config)
38
    {
39
        $this->accountManagerConfig = $config;
40
    }
41
42
    public function setLoginManagerConfig(array $config)
43
    {
44
        $this->loginManagerConfig = $config;
45
    }
46
47
48
    public function isDefaultAllow()
49
    {
50
        return $this->config['defaultAllow'];
51
    }
52
53
    /**
54
     * @return AccountManagerInterface
55
     */
56 View Code Duplication
    public function getDefaultAccountManager()
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...
57
    {
58
        $defaultAccountManagerConfig = $this->accountManagerConfig[$this->config['defaultAccountManager']];
59
60
        $className = $defaultAccountManagerConfig['class'];
61
        $settings = $defaultAccountManagerConfig['settings'];
62
63
        return new $className($settings);
64
    }
65
66
    /**
67
     * @return LoginManagerInterface
68
     */
69 View Code Duplication
    public function getDefaultLoginManager()
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...
70
    {
71
        $defaultLoginManagerConfig = $this->loginManagerConfig[$this->config['defaultLoginManager']];
72
73
        $className = $defaultLoginManagerConfig['class'];
74
        $settings = $defaultLoginManagerConfig['settings'];
75
76
        return new $className($settings);
77
    }
78
}
79