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

ResourceDescriptor   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 77
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 11
lcom 1
cbo 0
dl 0
loc 77
rs 10
c 0
b 0
f 0

9 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A getSubject() 0 4 1
A getAliases() 0 4 1
A addAlias() 0 4 1
A getProperties() 0 4 1
A addProperty() 0 4 1
A getLinks() 0 4 1
A addLink() 0 4 1
A jsonSerialize() 0 12 3
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\WebFingerEndpoint;
15
16
class ResourceDescriptor implements \JsonSerializable
17
{
18
    private $subject;
19
    private $aliases;
20
    private $properties;
21
    private $links;
22
23
    /**
24
     * @param string[] $aliases
25
     * @param mixed[]  $properties
26
     * @param Link[]   $links
27
     */
28
    public function __construct(?string $subject, array $aliases, array $properties, array $links)
29
    {
30
        $this->subject = $subject;
31
        $this->aliases = $aliases;
32
        $this->properties = $properties;
33
        $this->links = $links;
34
    }
35
36
    public function getSubject(): ?string
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
37
    {
38
        return $this->subject;
39
    }
40
41
    /**
42
     * @return string[]
43
     */
44
    public function getAliases(): array
45
    {
46
        return $this->aliases;
47
    }
48
49
    public function addAlias(string $key, string $alias): void
50
    {
51
        $this->properties[$key] = $alias;
52
    }
53
54
    /**
55
     * @return mixed[]
56
     */
57
    public function getProperties(): array
58
    {
59
        return $this->properties;
60
    }
61
62
    public function addProperty(string $key, string $property): void
63
    {
64
        $this->properties[$key] = $property;
65
    }
66
67
    /**
68
     * @return Link[]
69
     */
70
    public function getLinks(): array
71
    {
72
        return $this->links;
73
    }
74
75
    public function addLink(string $key, Link $link): void
76
    {
77
        $this->links[$key] = $link;
78
    }
79
80
    public function jsonSerialize()
81
    {
82
        $result = [];
83
84
        foreach (['subject', 'aliases', 'properties', 'links'] as $property) {
85
            if (!empty($this->$property)) {
86
                $result[$property] = $this->$property;
87
            }
88
        }
89
90
        return $result;
91
    }
92
}
93