Failed Conditions
Push — master ( b8d841...bc596e )
by Florent
28:20
created

ResourceRepository::find()   A

Complexity

Conditions 4
Paths 6

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 13
rs 9.8333
c 0
b 0
f 0
cc 4
nc 6
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\WebFingerBundle\Tests\TestBundle\Entity;
15
16
use OAuth2Framework\Component\WebFingerEndpoint\IdentifierResolver\Identifier;
17
use OAuth2Framework\Component\WebFingerEndpoint\Link;
18
use OAuth2Framework\Component\WebFingerEndpoint\ResourceDescriptor;
19
use OAuth2Framework\Component\WebFingerEndpoint\ResourceRepository as ResourceRepositoryInterface;
20
21
class ResourceRepository implements ResourceRepositoryInterface
22
{
23
    /**
24
     * @var ResourceDescriptor[]
25
     */
26
    private $resources = [];
27
28
    public function __construct()
29
    {
30
        $this->resources['john'] = new ResourceDescriptor(
31
            'john',
32
            [
33
                'acct:[email protected]:443',
34
                'https://my-service.com:443/+john',
35
            ],
36
            [],
37
            [
38
                new Link('http://openid.net/specs/connect/1.0/issuer', null, 'https://server.example.com', [], []),
39
            ]
40
        );
41
    }
42
43
    public function find(string $resource, Identifier $identifier): ?ResourceDescriptor
44
    {
45
        $resourceDescriptor = \array_key_exists($identifier->getId(), $this->resources) ? $this->resources[$identifier->getId()] : null;
46
        if (null === $resourceDescriptor) {
47
            return null;
48
        }
49
50
        if (!\in_array($resource, $resourceDescriptor->getAliases(), true)) {
51
            return null;
52
        }
53
54
        return $resourceDescriptor;
55
    }
56
}
57