Completed
Push — fake_json ( 3414f8...1903bd )
by Akihito
10:46 queued 09:03
created

Link::jsonSerialize()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 13
rs 9.8333
c 0
b 0
f 0
cc 2
nc 2
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace BEAR\Resource\Annotation;
6
7
/**
8
 * @Annotation
9
 * @Target("METHOD")
10
 */
11
final class Link implements \JsonSerializable
12
{
13
    /**
14
     * Relation to the target resource of the link
15
     *
16
     * @var string
17
     */
18
    public $rel;
19
20
    /**
21
     * A URI template, as defined by RFC 6570
22
     *
23
     * @var string
24
     */
25
    public $href;
26
27
    /**
28
     * A method for the Link
29
     *
30
     * @var string
31
     * @Enum({"get", "post", "put", "patch", "delete"})
32
     */
33
    public $method = 'get';
34
35
    /**
36
     * A title for the link
37
     *
38
     * @var string
39
     */
40
    public $title = '';
41
42
    /**
43
     * Crawl tag ID for crawl request
44
     *
45
     * @var string
46
     */
47
    public $crawl = '';
48
49
    public function jsonSerialize()
50
    {
51
        $json = [
52
            'rel' => $this->rel,
53
            'href' => $this->href,
54
            'method' => $this->method
55
        ];
56
        if ($this->title) {
57
            $json += ['title' => $this->title];
58
        }
59
60
        return $json;
61
    }
62
}
63