Failed Conditions
Push — ng ( 06d981...bf1375 )
by Florent
11:23
created

ResourceRepository::find()   B

Complexity

Conditions 5
Paths 5

Size

Total Lines 14
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 8.8571
c 0
b 0
f 0
cc 5
eloc 10
nc 5
nop 1
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\IssuerDiscoveryEndpoint\Resource;
17
use OAuth2Framework\Component\IssuerDiscoveryEndpoint\ResourceId;
18
use OAuth2Framework\Component\IssuerDiscoveryEndpoint\ResourceRepository as ResourceRepositoryInterface;
19
20
final class ResourceRepository implements ResourceRepositoryInterface
21
{
22
    /**
23
     * @var Resource[]
24
     */
25
    private $resources = [];
26
27
    public function __construct()
28
    {
29
        $this->resources['john'] = new ResourceObject('https://server.example.com');
30
    }
31
32
    /**
33
     * {@inheritdoc}
34
     */
35
    public function find(ResourceId $resourceId): ?Resource
36
    {
37
        $server = 'my-service.com:9000';
38
        $length = mb_strlen($server, 'utf-8');
39
        if ('https://'.$server.'/+' === mb_substr($resourceId->getValue(), 0, $length + 10, 'utf-8')) {
40
            $resourceName = mb_substr($resourceId->getValue(), $length + 10, null, 'utf-8');
41
        } elseif ('acct:' === mb_substr($resourceId->getValue(), 0, 5, 'utf-8') && '@'.$server === mb_substr($resourceId->getValue(), -($length + 1), null, 'utf-8')) {
42
            $resourceName = mb_substr($resourceId->getValue(), 5, -($length + 1), 'utf-8');
43
        } else {
44
            return null;
45
        }
46
47
        return array_key_exists($resourceName, $this->resources) ? $this->resources[$resourceName] : null;
0 ignored issues
show
Bug Compatibility introduced by
The expression array_key_exists($resour...[$resourceName] : null; of type OAuth2Framework\Componen...yEndpoint\Resource|null adds the type OAuth2Framework\Componen...coveryEndpoint\Resource to the return on line 47 which is incompatible with the return type declared by the interface OAuth2Framework\Componen...esourceRepository::find of type resource|null.
Loading history...
48
    }
49
}
50