Failed Conditions
Push — master ( 2fcdae...1d0766 )
by Florent
04:40
created

GivenName::getForUserAccount()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
c 0
b 0
f 0
rs 9.4285
cc 1
eloc 3
nc 1
nop 2
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\Component\OpenIdConnect\UserInfo\Claim;
15
16
use OAuth2Framework\Component\Core\UserAccount\UserAccount;
17
18
final class GivenName implements Claim
19
{
20
    private const CLAIM_NAME = 'given_name';
21
22
    /**
23
     * {@inheritdoc}
24
     */
25
    public function name(): string
26
    {
27
        return self::CLAIM_NAME;
28
    }
29
30
    /**
31
     * {@inheritdoc}
32
     */
33
    public function isAvailableForUserAccount(UserAccount $userAccount, ?string $claimLocale):bool
34
    {
35
        return $userAccount->has(
36
            $this->getComputedClaimName($claimLocale)
37
        );
38
    }
39
40
    /**
41
     * {@inheritdoc}
42
     */
43
    public function getForUserAccount(UserAccount $userAccount, ?string $claimLocale)
44
    {
45
        return $userAccount->get(
46
            $this->getComputedClaimName($claimLocale)
47
        );
48
    }
49
50
    private function getComputedClaimName(string $claimLocale): string
51
    {
52
        return $claimLocale ? sprintf('%s#%s', self::CLAIM_NAME, $claimLocale) : self::CLAIM_NAME;
53
    }
54
}
55