GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

RelationProvider::getRelations()   B
last analyzed

Complexity

Conditions 6
Paths 6

Size

Total Lines 30
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 30
c 0
b 0
f 0
rs 8.439
cc 6
eloc 16
nc 6
nop 1
1
<?php
2
3
namespace Hateoas\Configuration\Provider;
4
5
use Hateoas\Configuration\Metadata\ClassMetadataInterface;
6
use Hateoas\Configuration\Provider\Resolver\RelationProviderResolverInterface;
7
use Metadata\MetadataFactoryInterface;
8
9
/**
10
 * @author Adrien Brault <[email protected]>
11
 */
12
class RelationProvider implements RelationProviderInterface
13
{
14
    /**
15
     * @var MetadataFactoryInterface
16
     */
17
    private $metadataFactory;
18
19
    /**
20
     * @var RelationProviderResolverInterface
21
     */
22
    private $resolver;
23
24
    public function __construct(MetadataFactoryInterface $metadataFactory, RelationProviderResolverInterface $resolver)
25
    {
26
        $this->metadataFactory = $metadataFactory;
27
        $this->resolver        = $resolver;
28
    }
29
30
    public function getRelations($object)
31
    {
32
        $classMetadata = $this->metadataFactory->getMetadataForClass(get_class($object));
33
34
        if (!$classMetadata instanceof ClassMetadataInterface) {
35
            return array();
36
        }
37
38
        $relations = array();
39
        foreach ($classMetadata->getRelationProviders() as $configuration) {
40
            if (null === $relationProviderCallable = $this->resolver->getRelationProvider($configuration, $object)) {
41
                continue;
42
            }
43
44
            if (!is_callable($relationProviderCallable)) {
45
                throw new \RuntimeException('The returned relation provider is not callable, it should be.');
46
            }
47
48
            $newRelations = call_user_func_array(
49
                $relationProviderCallable,
50
                array($object, $classMetadata)
51
            );
52
53
            if (is_array($newRelations)) {
54
                $relations = array_merge($relations, $newRelations);
55
            }
56
        }
57
58
        return $relations;
59
    }
60
}
61