ErrorSource::toArray()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 13
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

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