ResponseInfo::getActionData()   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 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php // Copyright ⓒ 2018 Magneds IP B.V. - All Rights Reserved
2
namespace Magneds\Lokalise;
3
4
use function array_key_exists;
5
6
class ResponseInfo
7
{
8
    /**
9
     * @var string
10
     */
11
    protected $status;
12
13
    /**
14
     * @var int
15
     */
16
    protected $code;
17
18
    /**
19
     * @var string
20
     */
21
    protected $message;
22
23
    /**
24
     * @var mixed
25
     */
26
    protected $actionData;
27
28
    /**
29
     * ResponseInfo constructor.
30
     * @param string $status
31
     * @param int $code
32
     * @param string $message
33
     */
34
    public function __construct(string $status, int $code, string $message)
35
    {
36
        $this->status  = $status;
37
        $this->code    = $code;
38
        $this->message = $message;
39
    }
40
41
    /**
42
     * @return string
43
     */
44
    public function getStatus(): string
45
    {
46
        return $this->status;
47
    }
48
49
    /**
50
     * @return int
51
     */
52
    public function getCode(): int
53
    {
54
        return $this->code;
55
    }
56
57
    /**
58
     * @return string
59
     */
60
    public function getMessage(): string
61
    {
62
        return $this->message;
63
    }
64
65
    public function setActionData($actionData)
66
    {
67
        $this->actionData = $actionData;
68
        return $this;
69
    }
70
71
    public function getActionData()
72
    {
73
        return $this->actionData;
74
    }
75
76
    /**
77
     * Build this object with data array typically from the responses json.
78
     *
79
     * @param array $array
80
     * @return self
81
     */
82
    public static function buildFromArray($array)
83
    {
84
        $status  = array_key_exists('status', $array) ? $array['status'] : '';
85
        $code    = array_key_exists('code', $array) ? (int)$array['code'] : 0;
86
        $message = array_key_exists('message', $array) ? $array['message'] : '';
87
88
        return new self($status, $code, $message);
89
    }
90
}
91