Link::createFromString()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 1
c 1
b 0
f 1
nc 1
nop 1
dl 0
loc 3
rs 10
1
<?php
2
namespace Javis\JsonApi\Schema;
3
4
class Link
5
{
6
    /**
7
     * @var string
8
     */
9
    protected $href;
10
11
    /**
12
     * @var array
13
     */
14
    protected $meta;
15
16
    /**
17
     * @param string $link
18
     * @return $this
19
     */
20
    public static function createFromString($link)
21
    {
22
        return new self($link);
23
    }
24
25
    /**
26
     * @param array $link
27
     * @return $this
28
     */
29
    public static function createFromArray(array $link)
30
    {
31
        $href = empty($link["href"]) ? "" : $link["href"];
32
        $meta = empty($link["meta"]) ? [] : $link["meta"];
33
34
        return new self($href, $meta);
35
    }
36
37
    /**
38
     * @param string $href
39
     * @param array $meta
40
     */
41
    public function __construct($href, array $meta = [])
42
    {
43
        $this->href = $href;
44
        $this->meta = $meta;
45
    }
46
47
    /**
48
     * @return array
49
     */
50
    public function toArray()
51
    {
52
        $link = ["href" => $this->href];
53
54
        if (empty($this->meta) === false) {
55
            $link["meta"] = $this->meta;
56
        }
57
58
        return $link;
59
    }
60
61
    /**
62
     * @return string
63
     */
64
    public function href()
65
    {
66
        return $this->href;
67
    }
68
69
    /**
70
     * @return bool
71
     */
72
    public function hasMeta()
73
    {
74
        return empty($this->meta) === false;
75
    }
76
77
    /**
78
     * @return array
79
     */
80
    public function meta()
81
    {
82
        return $this->meta;
83
    }
84
}
85