Completed
Push — master ( 597a5a...27b735 )
by Park Jong-Hun
29s
created

FileBaseAccountManager   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 52
Duplicated Lines 30.77 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 16
loc 52
rs 10
c 0
b 0
f 0
wmc 8
lcom 1
cbo 1

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A isExistAccountId() 0 4 1
A isEqualPassword() 8 8 2
A getAccountById() 0 15 2
A getRole() 8 8 2

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\AccountManager;
4
5
use App\Auth\AccountManagerInterface;
6
use App\Auth\Model\Account;
7
8
class FileBaseAccountManager implements AccountManagerInterface
9
{
10
    private $accounts = [];
11
12
    public function __construct(array $settings = [])
13
    {
14
        $this->accounts = $settings['accounts'];
15
    }
16
17
    public function isExistAccountId($accountId)
18
    {
19
        return isset($this->accounts[$accountId]);
20
    }
21
22 View Code Duplication
    public function isEqualPassword($accountId, $password)
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...
23
    {
24
        if ($this->isExistAccountId($accountId) === false) {
25
            return false;
26
        }
27
28
        return $this->accounts[$accountId]['password'] === $password;
29
    }
30
31
    /**
32
     * @param string $accountId
33
     * @return Account|null
34
     */
35
    public function getAccountById($accountId)
36
    {
37
        if(isset($this->accounts[$accountId]) === false) {
38
            return null;
39
        }
40
41
        $user = $this->accounts[$accountId];
42
43
        $account = new Account();
44
        $account->setAccountId($accountId);
45
        $account->setPassword($user['password']);
46
        $account->setName($user['name']);
47
48
        return $account;
49
    }
50
51 View Code Duplication
    public function getRole($accountId)
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...
52
    {
53
        if ($this->isExistAccountId($accountId) === false) {
54
            return null;
55
        }
56
57
        return $this->accounts[$accountId]['role'];
58
    }
59
}
60