Completed
Pull Request — master (#5)
by Alireza
02:51
created

Messages   A

Complexity

Total Complexity 22

Size/Duplication

Total Lines 285
Duplicated Lines 22.11 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 7
Bugs 1 Features 0
Metric Value
c 7
b 1
f 0
dl 63
loc 285
rs 10
wmc 22
lcom 1
cbo 1

16 Methods

Rating   Name   Duplication   Size   Complexity  
A succeed() 0 7 1
A deleteSucceeded() 10 10 2
A updateSucceeded() 10 10 2
A insertSucceeded() 10 10 2
A deleteFaild() 11 11 2
A updateFaild() 11 11 2
A insertFaild() 11 11 2
A connectionRefused() 0 8 1
A redisConnectionRefused() 0 7 1
A notFound() 0 8 1
A wrongParameters() 0 8 1
A methodNotAllowed() 0 8 1
A validationErrors() 0 8 1
A requestFieldNotFound() 0 8 1
A requestFieldDuplicated() 0 8 1
A error() 0 8 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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 );
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 View Code Duplication
	public function deleteSucceeded( $message = null ) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
33
34
		if ( is_null( $message ) )
35
			$message = $this->config[ 'success' ][ 'delete' ];
36
37
		return $this->setStatusCode( 200 )
38
					->setStatusText( 'success' )
39
					->respondWithMessage( $message );
40
41
	}
42
43
	/**
44
	 * Update action is succeed
45
	 * @author Shima Payro <[email protected]>
46
	 * @param String $message
47
	 * @since May 2, 2016 9:52:52 AM
48
	 * @uses
49
	 * @see
50
	 */
51 View Code Duplication
	public function updateSucceeded( $message = null ) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
52
53
		if ( is_null( $message ) )
54
			$message = $this->config[ 'success' ][ 'update' ];
55
56
		return $this->setStatusCode( 200 )
57
					->setStatusText( 'success' )
58
					->respondWithMessage( $message );
59
60
	}
61
62
	/**
63
	 * Insert action is succeed
64
	 * @author Shima Payro <[email protected]>
65
	 * @param String $message
66
	 * @since May 2, 2016 9:53:26 AM
67
	 * @uses
68
	 * @see
69
	 */
70 View Code Duplication
	public function insertSucceeded( $message = null ) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
71
72
		if ( is_null( $message ) )
73
			$message = $this->config[ 'success' ][ 'insert' ];
74
75
		return $this->setStatusCode( 200 )
76
					->setStatusText( 'success' )
77
					->respondWithMessage( $message );
78
79
	}
80
81
	/**
82
	 * Delete action is faild
83
	 * @author Shima Payro <[email protected]>
84
	 * @param String $message
85
	 * @since May 2, 2016 9:53:53 AM
86
	 * @uses
87
	 * @see
88
	 */
89 View Code Duplication
	public function deleteFaild( $message = null ) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
90
91
		if ( is_null( $message ) )
92
			$message = $this->config[ 'fail' ][ 'delete' ];
93
94
		return $this->setStatusCode( 447 )
95
					->setStatusText( 'fail' )
96
					->setErrorCode( 5447 )
97
					->respondWithMessage( $message );
98
99
	}
100
101
	/**
102
	 * Update action is succeed
103
	 * @author Shima Payro <[email protected]>
104
	 * @param String $message
105
	 * @since May 2, 2016 9:54:09 AM
106
	 * @uses
107
	 * @see
108
	 */
109 View Code Duplication
	public function updateFaild( $message = null ) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
110
111
		if ( is_null( $message ) )
112
			$message = $this->config[ 'fail' ][ 'update' ];
113
114
		return $this->setStatusCode( 449 )
115
					->setStatusText( 'fail' )
116
					->setErrorCode( 5449 )
117
					->respondWithMessage( $message );
118
119
	}
120
121
	/**
122
	 * Insert action is faild
123
	 * @author Shima Payro <[email protected]>
124
	 * @param String $message
125
	 * @since May 2, 2016 9:54:27 AM
126
	 * @uses
127
	 * @see
128
	 */
129 View Code Duplication
	public function insertFaild( $message = null ) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
130
131
		if ( is_null( $message ) )
132
			$message = $this->config[ 'fail' ][ 'insert' ];
133
134
		return $this->setStatusCode( 448 )
135
					->setStatusText( 'fail' )
136
					->setErrorCode( 5448 )
137
					->respondWithMessage( $message );
138
139
	}
140
141
	/**
142
	 * Database connection is refused
143
	 * @author Shima Payro <[email protected]>
144
	 * @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...
145
	 * @since May 2, 2016 9:54:45 AM
146
	 * @uses
147
	 * @see
148
	 */
149
	public function connectionRefused() {
150
151
		return $this->setStatusCode( 445 )
152
					->setStatusText( 'fail' )
153
					->setErrorCode( 5445 )
154
					->respondWithMessage();
155
156
	}
157
158
    /**
159
     * Redis connection is refused
160
     *
161
     * @author Alireza Josheghani <[email protected]>
162
     * @since 21 Jan 2017
163
     */
164
    public function redisConnectionRefused()
165
    {
166
        return $this->setStatusCode( 445 )
167
            ->setStatusText( 'fail' )
168
            ->setErrorCode( 5445 )
169
            ->respondWithMessage();
170
	}
171
172
	/**
173
	 * page requested is not found
174
	 * @author Shima Payro <[email protected]>
175
	 * @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...
176
	 * @since May 2, 2016 9:55:20 AM
177
	 * @uses
178
	 * @see
179
	 */
180
	public function notFound() {
181
182
		return $this->setStatusCode( 404 )
183
					->setStatusText( 'fail' )
184
					->setErrorCode( 5404 )
185
					->respondWithMessage();
186
187
	}
188
189
	/**
190
	 * Wrong parameters are entered
191
	 * @author Shima Payro <[email protected]>
192
	 * @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...
193
	 * @since May 2, 2016 9:55:20 AM
194
	 * @uses
195
	 * @see
196
	 */
197
	public function wrongParameters() {
198
199
		return $this->setStatusCode( 406 )
200
					->setStatusText( 'fail' )
201
					->setErrorCode( 5406 )
202
					->respondWithMessage();
203
204
	}
205
206
	/**
207
	 * Method is not allowed
208
	 * @author Shima Payro <[email protected]>
209
	 * @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...
210
	 * @since May 2, 2016 9:55:20 AM
211
	 * @uses
212
	 * @see
213
	 */
214
	public function methodNotAllowed() {
215
216
		return $this->setStatusCode( 405 )
217
					->setStatusText( 'fail' )
218
					->setErrorCode( 5405 )
219
					->respondWithMessage();
220
221
	}
222
223
	/**
224
	 * There ara validation errors
225
	 * @author Shima Payro <[email protected]>
226
	 * @param $data array
227
	 * @since May 2, 2016 9:55:20 AM
228
	 * @uses
229
	 * @see
230
	 */
231
	public function validationErrors( $message = null ) {
232
233
		return $this->setStatusCode( 420 )
234
					->setStatusText( 'fail' )
235
					->setErrorCode( 5420 )
236
					->respondWithResult( $message );
237
238
	}
239
240
	/**
241
	 * The request field is not found
242
	 * @author Shima Payro <[email protected]>
243
	 * @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...
244
	 * @since May 2, 2016 9:55:20 AM
245
	 * @uses
246
	 * @see
247
	 */
248
	public function requestFieldNotFound() {
249
250
		return $this->setStatusCode( 446 )
251
					->setStatusText( 'fail' )
252
					->setErrorCode( 1001 )
253
					->respondWithMessage();
254
255
	}
256
257
	/**
258
	 * The request field is doublicated
259
	 * @author Mehdi Hosseini <[email protected]>
260
	 * @since August 24, 2016
261
	 * @return mixed
262
	 */
263
	public function requestFieldDuplicated() {
264
265
	  return $this->setStatusCode( 400 )
266
					->setStatusText( 'fail' )
267
					->SetErrorCode(1004)
268
					->respondWithMessage();
269
270
	}
271
272
	/**
273
	 * Custom error message according to error config file
274
	 * @author Mehdi Hosseini <[email protected]>
275
	 * @since August 24, 2016
276
	 * @param $code integer
277
	 * @return mixed
278
	 */
279
	public function error( $code ) {
280
281
	  return $this->setStatusCode( 400 )
282
					->setStatusText( 'fail' )
283
					->setErrorCode( $code )
284
					->respondWithMessage();
285
286
	}
287
288
289
}
290