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

Link::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 5
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 Link implements \JsonSerializable
17
{
18
    private $rel;
19
    private $type;
20
    private $href;
21
    private $titles;
22
    private $properties;
23
24
    /**
25
     * @param string[] $titles
26
     * @param mixed[]  $properties
27
     */
28
    public function __construct(string $rel, ?string $type, ?string $href, array $titles, array $properties)
29
    {
30
        $this->rel = $rel;
31
        $this->type = $type;
32
        $this->href = $href;
33
        $this->titles = $titles;
34
        $this->properties = $properties;
35
    }
36
37
    public function getRel(): string
38
    {
39
        return $this->rel;
40
    }
41
42
    public function getType(): ?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...
43
    {
44
        return $this->type;
45
    }
46
47
    public function getHref(): string
48
    {
49
        return $this->href;
50
    }
51
52
    /**
53
     * @return string[]
54
     */
55
    public function getTitles(): array
56
    {
57
        return $this->titles;
58
    }
59
60
    public function addTitle(string $tag, string $title): void
61
    {
62
        $this->titles[$tag] = $title;
63
    }
64
65
    /**
66
     * @return string[]
67
     */
68
    public function getProperties(): array
69
    {
70
        return $this->properties;
71
    }
72
73
    public function addProperty(string $key, string $property): void
74
    {
75
        $this->properties[$key] = $property;
76
    }
77
78
    public function jsonSerialize()
79
    {
80
        $result = [
81
            'rel' => $this->rel,
82
        ];
83
84
        foreach (['type', 'href', 'titles', 'properties'] as $property) {
85
            if (!empty($this->$property)) {
86
                $result[$property] = $this->$property;
87
            }
88
        }
89
90
        return $result;
91
    }
92
}
93