Completed
Push — master ( c304d8...c35892 )
by mehdi
06:02
created

Main::getErrorMessage()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 5
rs 9.4285
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace Anetwork\Respond;
4
5
use Illuminate\Http\Response;
6
7
class Main {
8
9
    /**
10
     * Http status code
11
     * @var integer
12
     */
13
    protected $statusCode = 200;
14
15
    /**
16
     * Status text
17
     * @var string
18
     */
19
    protected $statusText = 'success';
20
21
    /**
22
     * Error code, message and text-key
23
     * @var array
24
     */
25
    protected $error;
26
27
    /**
28
     * Error code
29
     * @var integer
30
     */
31
     protected $errorCode;
32
33
34
    /**
35
     * Getter for $statusCode
36
     * @author Shima Payro <[email protected]>
37
     * @since May 2, 2016 9:46:27 AM
38
     * @uses
39
     * @see
40
     */
41
    public function getStatusCode() {
42
43
        return $this->statusCode;
44
45
    }
46
47
    /**
48
     * Setter for $statusCode
49
     * @param integer $statusCode
50
     * @return App\Htpp\Responds\Respond
51
     * @author Shima Payro <[email protected]>
52
     * @since May 2, 2016 9:47:04 AM
53
     * @uses
54
     * @see
55
     */
56
    public function setStatusCode( $statusCode ) {
57
58
        $this->statusCode = $statusCode;
59
60
        return $this;
61
62
    }
63
64
    /**
65
     * Getter for $statusText
66
     * @author Shima Payro <[email protected]>
67
     * @since May 2, 2016 9:47:36 AM
68
     * @uses
69
     * @see
70
     */
71
    public function getStatusText() {
72
73
        return $this->statusText;
74
75
    }
76
77
    /**
78
     * Setter for $statusText
79
     * @param String $statusText
80
     * @return App\HtppApp\Htpp\Responds\Respond
81
     * @author Shima Payro <[email protected]>
82
     * @since May 2, 2016 9:48:23 AM
83
     * @uses
84
     * @see
85
     */
86
    public function setStatusText( $statusText ) {
87
88
        $this->statusText = $statusText;
89
90
        return $this;
91
92
    }
93
94
    /**
95
     * Response
96
     * @param json $data
97
     * @return jsom
98
     * @author Shima Payro <[email protected]>
99
     * @since May 2, 2016 9:48:45 AM
100
     * @uses
101
     * @see
102
     */
103
    public function respond( $data ) {
104
105
        return response()->json( $data, $this->getStatusCode() );
106
107
    }
108
109
    /**
110
     * Response which conteins just a message
111
     * @param string $message
0 ignored issues
show
Bug introduced by
There is no parameter named $message. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
112
     * @author Shima Payro <[email protected]>
113
     * @since May 2, 2016 9:49:21 AM
114
     * @return json
115
     * @uses
116
     * @see
117
     */
118
    public function respondWithMessage() {
119
120
        return $this->respond( [
0 ignored issues
show
Documentation introduced by
array('status' => 'fail'...his->getErrorMessage()) is of type array<string,string|inte...r","message":"string"}>, but the function expects a object<Anetwork\Respond\json>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
121
            'status' => 'fail',
122
            'code' => $this->getErrorCode(),
123
            'message' => $this->getErrorMessage(),
124
125
            ] );
126
127
    }
128
129
    /**
130
     * Set error code in our result
131
     * @author Mehdi Hosseini <[email protected]>
132
     * @since August 24, 2016
133
     * @param $errorCode integer
134
     * @return instance
135
     */
136
    public function setErrorCode( $errorCode ) {
137
138
      $this->error = config( 'errors.' . $errorCode );
139
140
      $this->errorCode = $errorCode;
141
142
      return $this;
143
144
    }
145
146
    /**
147
     * Return Error code
148
     * @author Mehdi Hosseini <[email protected]>
149
     * @since August 24, 2016
150
     * @return integer
151
     */
152
    public function getErrorCode() {
153
154
      return $this->errorCode;
155
156
    }
157
158
    /**
159
     * Get error message
160
     * @author Mehdi Hosseini <[email protected]>
161
     * @since August 24, 2016
162
     * @return string
163
     */
164
    public function getErrorMessage() {
165
166
      return $this->error['message'];
167
168
    }
169
170
171
    /**
172
     * Response which contains status and data
173
     * @param json $data
174
     * @author Shima Payro <[email protected]>
175
     * @since May 2, 2016 9:50:19 AM
176
     * @return json
177
     * @uses
178
     * @see
179
     */
180
    public function respondWithResult( $data ) {
181
182
        return $this->respond( [
0 ignored issues
show
Documentation introduced by
array('status' => $this-...t(), 'result' => $data) is of type array<string,string|obje...work\\Respond\\json>"}>, but the function expects a object<Anetwork\Respond\json>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
183
            'status' => $this->getStatusText(),
184
            'result' => $data
185
186
            ] );
187
188
    }
189
190
}
191