ResourceDescriptor   A
last analyzed

Complexity

Total Complexity 13

Size/Duplication

Total Lines 95
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 25
c 1
b 0
f 0
dl 0
loc 95
rs 10
wmc 13

9 Methods

Rating   Name   Duplication   Size   Complexity  
A addAlias() 0 3 1
A addLink() 0 3 1
A getProperties() 0 3 1
A jsonSerialize() 0 16 5
A getLinks() 0 3 1
A getSubject() 0 3 1
A addProperty() 0 3 1
A __construct() 0 6 1
A getAliases() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * The MIT License (MIT)
7
 *
8
 * Copyright (c) 2014-2019 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
    /**
19
     * @var null|string
20
     */
21
    private $subject;
22
23
    /**
24
     * @var array|string[]
25
     */
26
    private $aliases;
27
28
    /**
29
     * @var array|mixed[]
30
     */
31
    private $properties;
32
33
    /**
34
     * @var array|Link[]
35
     */
36
    private $links;
37
38
    /**
39
     * @param string[] $aliases
40
     * @param mixed[]  $properties
41
     * @param Link[]   $links
42
     */
43
    public function __construct(?string $subject, array $aliases, array $properties, array $links)
44
    {
45
        $this->subject = $subject;
46
        $this->aliases = $aliases;
47
        $this->properties = $properties;
48
        $this->links = $links;
49
    }
50
51
    public function getSubject(): ?string
52
    {
53
        return $this->subject;
54
    }
55
56
    /**
57
     * @return string[]
58
     */
59
    public function getAliases(): array
60
    {
61
        return $this->aliases;
62
    }
63
64
    public function addAlias(string $key, string $alias): void
65
    {
66
        $this->properties[$key] = $alias;
67
    }
68
69
    /**
70
     * @return mixed[]
71
     */
72
    public function getProperties(): array
73
    {
74
        return $this->properties;
75
    }
76
77
    public function addProperty(string $key, string $property): void
78
    {
79
        $this->properties[$key] = $property;
80
    }
81
82
    /**
83
     * @return Link[]
84
     */
85
    public function getLinks(): array
86
    {
87
        return $this->links;
88
    }
89
90
    public function addLink(string $key, Link $link): void
91
    {
92
        $this->links[$key] = $link;
93
    }
94
95
    public function jsonSerialize(): array
96
    {
97
        $result = [
98
            'subject' => $this->subject,
99
            'aliases' => $this->aliases,
100
            'properties' => $this->properties,
101
            'links' => $this->links,
102
        ];
103
104
        foreach ($result as $k => $v) {
105
            if (null === $v || (\is_array($v) && 0 === \count($v))) {
106
                unset($result[$k]);
107
            }
108
        }
109
110
        return $result;
111
    }
112
}
113