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

Messages::error()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 7
rs 9.4285
cc 1
eloc 4
nc 1
nop 1
1
<?php
2
3
namespace Anetwork\Respond;
4
5
class Messages extends Main
6
{
7
8
    /**
9
     * Request succeeded and contains json result
10
     * @param array $data
11
     * @author Shima Payro <[email protected]>
12
     * @since May 2, 2016 9:50:51 AM
13
     * @uses
14
     * @see
15
     */
16
    public function succeed( $data ) {
17
18
        return $this->setStatusCode( 200 )
19
                    ->setStatusText( 'success' )
20
                    ->respondWithResult( $data );
0 ignored issues
show
Documentation introduced by
$data is of type array, 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...
21
22
    }
23
24
    /**
25
     * Delete action is succeed
26
     * @author Shima Payro <[email protected]>
27
     * @param String $message
28
     * @since May 2, 2016 9:52:05 AM
29
     * @uses
30
     * @see
31
     */
32
    public function deleteSucceeded( $message = 'The requested parameter is deleted successfully!' ) {
33
34
        return $this->setStatusCode( 200 )
35
                    ->setStatusText( 'success' )
36
                    ->respondWithMessage( $message );
0 ignored issues
show
Unused Code introduced by
The call to Messages::respondWithMessage() has too many arguments starting with $message.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
37
38
    }
39
40
    /**
41
     * Update action is succeed
42
     * @author Shima Payro <[email protected]>
43
     * @param String $message
44
     * @since May 2, 2016 9:52:52 AM
45
     * @uses
46
     * @see
47
     */
48
    public function updateSucceeded( $message = 'The requested parameter is updated successfully!' ) {
49
50
        return $this->setStatusCode( 200 )
51
                    ->setStatusText( 'success' )
52
                    ->respondWithMessage( $message );
0 ignored issues
show
Unused Code introduced by
The call to Messages::respondWithMessage() has too many arguments starting with $message.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
53
54
    }
55
56
    /**
57
     * Insert action is succeed
58
     * @author Shima Payro <[email protected]>
59
     * @param String $message
60
     * @since May 2, 2016 9:53:26 AM
61
     * @uses
62
     * @see
63
     */
64
    public function insertSucceeded( $message = 'The requested parameter is Added successfully!' ) {
65
66
        return $this->setStatusCode( 200 )
67
                    ->setStatusText( 'success' )
68
                    ->respondWithMessage( $message );
0 ignored issues
show
Unused Code introduced by
The call to Messages::respondWithMessage() has too many arguments starting with $message.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
69
70
    }
71
72
    /**
73
     * Delete action is faild
74
     * @author Shima Payro <[email protected]>
75
     * @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...
76
     * @since May 2, 2016 9:53:53 AM
77
     * @uses
78
     * @see
79
     */
80
    public function deleteFaild() {
81
82
        return $this->setStatusCode( 447 )
83
                    ->setErrorCode( 5447 )
84
                    ->respondWithMessage();
85
86
    }
87
88
    /**
89
     * Update action is succeed
90
     * @author Shima Payro <[email protected]>
91
     * @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...
92
     * @since May 2, 2016 9:54:09 AM
93
     * @uses
94
     * @see
95
     */
96
    public function updateFaild() {
97
98
        return $this->setStatusCode( 449 )
99
                    ->setErrorCode( 5449 )
100
                    ->respondWithMessage();
101
102
    }
103
104
    /**
105
     * Insert action is faild
106
     * @author Shima Payro <[email protected]>
107
     * @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...
108
     * @since May 2, 2016 9:54:27 AM
109
     * @uses
110
     * @see
111
     */
112
    public function insertFaild() {
113
114
        return $this->setStatusCode( 448 )
115
                    ->setErrorCode( 5448 )
116
                    ->respondWithMessage();
117
118
    }
119
120
    /**
121
     * Database connection is refused
122
     * @author Shima Payro <[email protected]>
123
     * @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...
124
     * @since May 2, 2016 9:54:45 AM
125
     * @uses
126
     * @see
127
     */
128
    public function connectionRefused() {
129
130
        return $this->setStatusCode( 445 )
131
                    ->setErrorCode( 5445 )
132
                    ->respondWithMessage();
133
134
    }
135
136
    /**
137
     * page requested is not found
138
     * @author Shima Payro <[email protected]>
139
     * @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...
140
     * @since May 2, 2016 9:55:20 AM
141
     * @uses
142
     * @see
143
     */
144
    public function notFound() {
145
146
        return $this->setStatusCode( 404 )
147
                    ->setErrorCode( 5404 )
148
                    ->respondWithMessage();
149
150
    }
151
152
    /**
153
     * Wrong parameters are entered
154
     * @author Shima Payro <[email protected]>
155
     * @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...
156
     * @since May 2, 2016 9:55:20 AM
157
     * @uses
158
     * @see
159
     */
160
    public function wrongParameters() {
161
162
        return $this->setStatusCode( 406 )
163
                    ->setErrorCode( 5406 )
164
                    ->respondWithMessage();
165
166
    }
167
168
    /**
169
     * Method is not allowed
170
     * @author Shima Payro <[email protected]>
171
     * @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...
172
     * @since May 2, 2016 9:55:20 AM
173
     * @uses
174
     * @see
175
     */
176
    public function methodNotAllowed() {
177
178
        return $this->setStatusCode( 405 )
179
                    ->setErrorCode( 5405 )
180
                    ->respondWithMessage();
181
182
    }
183
184
    /**
185
     * There ara validation errors
186
     * @author Shima Payro <[email protected]>
187
     * @param Array $data
188
     * @since May 2, 2016 9:55:20 AM
189
     * @uses
190
     * @see
191
     */
192
    public function validationErrors( $data ) {
193
194
        return $this->setStatusCode( 420 )
195
                    ->setErrorCode( 5420 )
196
                    ->respondWithResult( $data );
0 ignored issues
show
Documentation introduced by
$data is of type array, 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...
197
198
    }
199
200
    /**
201
     * The request field is not found
202
     * @author Shima Payro <[email protected]>
203
     * @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...
204
     * @since May 2, 2016 9:55:20 AM
205
     * @uses
206
     * @see
207
     */
208
    public function requestFieldNotFound() {
209
210
        return $this->setStatusCode( 446 )
211
                    ->setErrorCode( 1001 )
212
                    ->respondWithMessage();
213
214
    }
215
216
    /**
217
     * The request field is doublicated
218
     * @author Mehdi Hosseini <[email protected]>
219
     * @since August 24, 2016
220
     * @return json
221
     */
222
    public function requestFieldDoublicated() {
223
224
      return $this->setStatusCode(400)
225
                  ->SetErrorCode(1004)
226
                  ->respondWithMessage();
227
228
    }
229
230
    /**
231
     * Custom error message according to error config file
232
     * @author Mehdi Hosseini <[email protected]>
233
     * @since August 24, 2016
234
     * @param $code integer
235
     * @return json
236
     */
237
    public function error( $code ) {
238
239
      return $this->SetStatusCode( 400 )
240
                  ->setErrorCode( $code )
241
                  ->respondWithMessage();
242
243
    }
244
245
246
}
247