Failed Conditions
Push — master ( ed3bfb...d044dc )
by Florent
06:10
created

ResourceOwnerPasswordCredentialRepository   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 24
rs 10
c 0
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A findResourceOwnerIdWithUsernameAndPassword() 0 10 3
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * The MIT License (MIT)
7
 *
8
 * Copyright (c) 2014-2019 Spomky-Labs
9
 *
10
 * This software may be modified and distributed under the terms
11
 * of the MIT license.  See the LICENSE file for details.
12
 */
13
14
namespace OAuth2Framework\ServerBundle\Tests\TestBundle\Repository;
15
16
use OAuth2Framework\Component\Core\ResourceOwner\ResourceOwnerId;
17
use OAuth2Framework\Component\Core\UserAccount\UserAccountId;
18
use OAuth2Framework\Component\ResourceOwnerPasswordCredentialsGrant\ResourceOwnerPasswordCredentialManager as ResourceOwnerPasswordCredentialManagerInterface;
19
20
final class ResourceOwnerPasswordCredentialRepository implements ResourceOwnerPasswordCredentialManagerInterface
21
{
22
    /**
23
     * @var ResourceOwnerId[]
24
     */
25
    private $usernameAndPasswords;
26
27
    public function __construct()
28
    {
29
        $this->usernameAndPasswords = [
30
            'password.1' => new UserAccountId('john.1'),
31
        ];
32
    }
33
34
    public function findResourceOwnerIdWithUsernameAndPassword(string $username, string $password): ?ResourceOwnerId
35
    {
36
        if (!\array_key_exists($password, $this->usernameAndPasswords)) {
37
            return null;
38
        }
39
        if ($this->usernameAndPasswords[$password]->getValue() !== $username) {
40
            return null;
41
        }
42
43
        return $this->usernameAndPasswords[$password];
44
    }
45
}
46