BaseJsonResponse   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 9
eloc 15
c 0
b 0
f 0
dl 0
loc 59
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A getRawJson() 0 3 1
A success() 0 3 1
A getReturnCode() 0 3 1
A getMessageKey() 0 7 2
A failed() 0 3 1
A getMessage() 0 7 2
1
<?php
2
3
/*
4
 * BigBlueButton open source conferencing system - https://www.bigbluebutton.org/.
5
 *
6
 * Copyright (c) 2016-2024 BigBlueButton Inc. and by respective authors (see below).
7
 *
8
 * This program is free software; you can redistribute it and/or modify it under the
9
 * terms of the GNU Lesser General Public License as published by the Free Software
10
 * Foundation; either version 3.0 of the License, or (at your option) any later
11
 * version.
12
 *
13
 * BigBlueButton is distributed in the hope that it will be useful, but WITHOUT ANY
14
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
15
 * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU Lesser General Public License along
18
 * with BigBlueButton; if not, see <https://www.gnu.org/licenses/>.
19
 */
20
21
namespace BigBlueButton\Responses;
22
23
/**
24
 * Class BaseJsonResponse.
25
 */
26
abstract class BaseJsonResponse
27
{
28
    public const SUCCESS = 'SUCCESS';
29
    public const FAILED  = 'FAILED';
30
31
    /**
32
     * @var mixed
33
     */
34
    protected $data;
35
36
    public function __construct(string $json)
37
    {
38
        $this->data = json_decode($json);
39
    }
40
41
    /**
42
     * @return false|string
43
     */
44
    public function getRawJson()
45
    {
46
        return json_encode($this->data);
47
    }
48
49
    public function getMessage(): ?string
50
    {
51
        if ($this->failed()) {
52
            return $this->data->response->message;
53
        }
54
55
        return null;
56
    }
57
58
    public function getMessageKey(): ?string
59
    {
60
        if ($this->failed()) {
61
            return $this->data->response->messageKey;
62
        }
63
64
        return null;
65
    }
66
67
    /**
68
     * Return will be either 'SUCCESS' or 'FAILED' (nothing else).
69
     *
70
     * @see: https://docs.bigbluebutton.org/development/api/#api-calls
71
     */
72
    public function getReturnCode(): string
73
    {
74
        return $this->data->response->returncode;
75
    }
76
77
    public function success(): bool
78
    {
79
        return self::SUCCESS === $this->getReturnCode();
80
    }
81
82
    public function failed(): bool
83
    {
84
        return self::FAILED === $this->getReturnCode();
85
    }
86
}
87