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

FileBaseAccountManager::getAccountById()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 9
nc 2
nop 1
dl 0
loc 15
rs 9.4285
c 0
b 0
f 0
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