SMSAResponse   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 75
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 1
dl 0
loc 75
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 2
A jsonSerialize() 0 12 1
1
<?php
2
3
/*
4
 * This file is part of Smsa WebService package.
5
 * (c) Hamoud Alhoqbani <[email protected]>
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
namespace Alhoqbani\SmsaWebService\Response;
11
12
use WsdlToPhp\PackageBase\AbstractStructBase;
13
14
class SMSAResponse implements \JsonSerializable
15
{
16
    /**
17
     * @var bool
18
     */
19
    public $success;
20
    /**
21
     * @var array|string
22
     */
23
    public $data;
24
    /**
25
     * @var null|string
26
     */
27
    public $error;
28
    /**
29
     * @var string
30
     */
31
    public $type;
32
    /**
33
     * @var AbstractStructBase
34
     */
35
    public $payload;
36
    /**
37
     * @var \DOMDocument
38
     */
39
    public $request;
40
    /**
41
     * @var \DOMDocument
42
     */
43
    public $response;
44
45
    /**
46
     * SMSAResponse constructor.
47
     *
48
     * @param bool $success
49
     * @param null $data
50
     * @param null $error
51
     * @param      $type
52
     * @param      $payload
53
     * @param      $request
54
     * @param      $response
55
     */
56
    public function __construct(bool $success, $data = null, $error = null, string $type, $payload, $request, $response)
57
    {
58
        $this->success = $success;
59
        $this->data = $data;
60
        $this->type = $type;
61
        $this->payload = $payload;
62
        $this->request = $request;
63
        $this->response = $response;
64
        $this->error = ($error instanceof \SoapFault) ? $error->faultstring : $error;
65
    }
66
67
    /**
68
     * Specify data which should be serialized to JSON
69
     **
70
     *
71
     * @return mixed data which can be serialized by <b>json_encode</b>,
72
     *               which is a value of any type other than a resource.
73
     *
74
     * @since 5.4.0
75
     */
76
    public function jsonSerialize()
77
    {
78
        return [
79
          'success'    => $this->success,
80
          'data'       => $this->data,
81
          'error'      => $this->error,
82
          'type'       => $this->type,
83
          'payload'    => $this->payload->jsonSerialize(),
84
          'request'    => $this->request->saveXML(),
85
          'response'   => $this->response->saveXML(),
86
        ];
87
    }
88
}
89