Failed Conditions
Push — ng ( a004c2...0b9cb0 )
by Florent
03:36
created

ClientRepository::populateClients()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 52
Code Lines 39

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 52
rs 9.4929
c 0
b 0
f 0
cc 1
eloc 39
nc 1
nop 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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\Bundle\Tests\TestBundle\Entity;
15
16
use OAuth2Framework\Component\Core\Client\Client;
17
use OAuth2Framework\Component\Core\Client\ClientId;
18
use OAuth2Framework\Component\Core\DataBag\DataBag;
19
use OAuth2Framework\Component\Core\UserAccount\UserAccountId;
20
21
class ClientRepository implements \OAuth2Framework\Component\Core\Client\ClientRepository
22
{
23
    /**
24
     * @var Client[]
25
     */
26
    private $clients = [];
27
28
    /**
29
     * ClientRepository constructor.
30
     */
31
    public function __construct()
32
    {
33
        $this->populateClients();
34
    }
35
36
    /**
37
     * {@inheritdoc}
38
     */
39
    public function find(ClientId $clientId): ? Client
40
    {
41
        return array_key_exists($clientId->getValue(), $this->clients) ? $this->clients[$clientId->getValue()] : null;
42
    }
43
44
    /**
45
     * {@inheritdoc}
46
     */
47
    public function save(Client $client)
48
    {
49
        $this->clients[$client->getPublicId()->getValue()] = $client;
50
    }
51
52
    private function populateClients()
53
    {
54
        $client = Client::createEmpty();
55
        $client = $client->create(
56
            ClientId::create('CLIENT_ID_1'),
57
            DataBag::create([
58
                'token_endpoint_auth_method' => 'none',
59
                'grant_types' => [],
60
            ]),
61
            UserAccountId::create('USER_ACCOUNT_1')
62
        );
63
        $client->eraseMessages();
64
        $this->save($client);
65
66
        $client = Client::createEmpty();
67
        $client = $client->create(
68
            ClientId::create('CLIENT_ID_2'),
69
            DataBag::create([
70
                'token_endpoint_auth_method' => 'none',
71
                'grant_types' => ['client_credentials', 'refresh_token', 'authorization_code', 'password', 'implicit'],
72
            ]),
73
            UserAccountId::create('USER_ACCOUNT_1')
74
        );
75
        $client->eraseMessages();
76
        $this->save($client);
77
78
        $client = Client::createEmpty();
79
        $client = $client->create(
80
            ClientId::create('CLIENT_ID_3'),
81
            DataBag::create([
82
                'token_endpoint_auth_method' => 'client_secret_post',
83
                'grant_types' => ['client_credentials', 'refresh_token', 'authorization_code', 'password', 'implicit'],
84
                'client_secret' => 'secret',
85
            ]),
86
            UserAccountId::create('USER_ACCOUNT_1')
87
        );
88
        $client->eraseMessages();
89
        $this->save($client);
90
91
        $client = Client::createEmpty();
92
        $client = $client->create(
93
            ClientId::create('CLIENT_ID_4'),
94
            DataBag::create([
95
                'token_endpoint_auth_method' => 'client_secret_jwt',
96
                'grant_types' => ['urn:ietf:params:oauth:grant-type:jwt-bearer'],
97
                'client_secret' => 'secret',
98
            ]),
99
            UserAccountId::create('USER_ACCOUNT_1')
100
        );
101
        $client->eraseMessages();
102
        $this->save($client);
103
    }
104
}
105