Failed Conditions
Push — master ( 7c3864...930f9b )
by Florent
14:15
created

UserAccountRepository::getUsers()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 37

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 37
rs 9.328
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * The MIT License (MIT)
7
 *
8
 * Copyright (c) 2014-2018 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\Entity;
15
16
use OAuth2Framework\Component\Core\UserAccount\UserAccount as BaseUserAccount;
17
use OAuth2Framework\Component\Core\UserAccount\UserAccountId;
18
use OAuth2Framework\Component\Core\UserAccount\UserAccountRepository as UserAccountRepositoryInterface;
19
20
class UserAccountRepository implements UserAccountRepositoryInterface
21
{
22
    /**
23
     * @var UserAccount[]
24
     */
25
    private $userAccounts = [];
26
27
    public function __construct()
28
    {
29
        foreach ($this->getUsers() as $data) {
30
            $userAccount = new UserAccount(
31
                new UserAccountId($data['id']),
32
                $data['parameters']
33
            );
34
            $this->userAccounts[$data['id']] = $userAccount;
35
        }
36
    }
37
38
    public function find(UserAccountId $publicId): ?BaseUserAccount
39
    {
40
        return \array_key_exists($publicId->getValue(), $this->userAccounts) ? $this->userAccounts[$publicId->getValue()] : null;
41
    }
42
43
    private function getUsers(): array
44
    {
45
        return [
46
            [
47
                'id' => 'john.1',
48
                'parameters' => [
49
                    'address', [
50
                        'street_address' => '5 rue Sainte Anne',
51
                        'region' => 'Île de France',
52
                        'postal_code' => '75001',
53
                        'locality' => 'Paris',
54
                        'country' => 'France',
55
                    ],
56
                    'name' => 'John Doe',
57
                    'given_name' => 'John',
58
                    'family_name' => 'Doe',
59
                    'middle_name' => 'Jack',
60
                    'nickname' => 'Little John',
61
                    'profile' => 'https://profile.doe.fr/john/',
62
                    'preferred_username' => 'j-d',
63
                    'gender' => 'M',
64
                    'phone_number' => '+0123456789',
65
                    'phone_number_verified' => true,
66
                    'zoneinfo' => 'Europe/Paris',
67
                    'locale' => 'en',
68
                    'picture' => 'https://www.google.com',
69
                    'birthdate' => '1950-01-01',
70
                    'email' => '[email protected]',
71
                    'email_verified' => false,
72
                    'website' => 'https://john.doe.com',
73
                    'website#fr_fr' => 'https://john.doe.fr',
74
                    'website#fr' => 'https://john.doe.fr',
75
                    'picture#de' => 'https://john.doe.de/picture',
76
                ],
77
            ],
78
        ];
79
    }
80
}
81