Completed
Pull Request — master (#4)
by Alireza
02:56
created
src/Main.php 2 patches
Indentation   +205 added lines, -205 removed lines patch added patch discarded remove patch
@@ -4,271 +4,271 @@
 block discarded – undo
4 4
 
5 5
 class Main {
6 6
 
7
-	/**
8
-	 * Http status code
9
-	 * @var integer
10
-	 */
11
-	protected $statusCode = 200;
12
-
13
-	/**
14
-	 * Status text
15
-	 * @var string
16
-	 */
17
-	protected $statusText = 'success';
18
-
19
-	/**
20
-	 * Error code, message and text-key
21
-	 * @var array
22
-	 */
23
-	protected $error;
24
-
25
-	/**
26
-	 * Error code
27
-	 * @var integer
28
-	 */
29
-	protected $errorCode;
30
-
31
-	/**
32
-	 * Haeders
33
-	 * @var array
34
-	 */
35
-	protected $headers = [];
36
-
37
-	/**
38
-	 * @var string
39
-	 */
40
-	protected $lang;
41
-
42
-	/**
43
-	 * @var array
44
-	 */
45
-	protected $config;
46
-
47
-	/**
48
-	 * @author Shahrokh Niakan <[email protected]>
49
-	 * @since Sep 24, 2016
50
-	 */
51
-	public function __construct() {
52
-
53
-
54
-		$this->lang = \App::getLocale();
55
-
56
-		if(! file_exists(config_path($this->lang . '.php'))){
7
+ /**
8
+  * Http status code
9
+  * @var integer
10
+  */
11
+ protected $statusCode = 200;
12
+
13
+ /**
14
+  * Status text
15
+  * @var string
16
+  */
17
+ protected $statusText = 'success';
18
+
19
+ /**
20
+  * Error code, message and text-key
21
+  * @var array
22
+  */
23
+ protected $error;
24
+
25
+ /**
26
+  * Error code
27
+  * @var integer
28
+  */
29
+ protected $errorCode;
30
+
31
+ /**
32
+  * Haeders
33
+  * @var array
34
+  */
35
+ protected $headers = [];
36
+
37
+ /**
38
+  * @var string
39
+  */
40
+ protected $lang;
41
+
42
+ /**
43
+  * @var array
44
+  */
45
+ protected $config;
46
+
47
+ /**
48
+  * @author Shahrokh Niakan <[email protected]>
49
+  * @since Sep 24, 2016
50
+  */
51
+ public function __construct() {
52
+
53
+
54
+  $this->lang = \App::getLocale();
55
+
56
+  if(! file_exists(config_path($this->lang . '.php'))){
57 57
             $this->config = include __DIR__ . '/../errors/lang/' . $this->lang . '.php';
58 58
         } else {
59 59
             $this->config = include config_path($this->lang . '.php');
60 60
         }
61 61
 
62
-	}
62
+ }
63 63
 
64
-	/**
65
-	 * Getter for $statusCode
66
-	 * @author Shima Payro <[email protected]>
67
-	 * @since May 2, 2016 9:46:27 AM
68
-	 * @uses
69
-	 * @see
70
-	 */
71
-	public function getStatusCode() {
64
+ /**
65
+  * Getter for $statusCode
66
+  * @author Shima Payro <[email protected]>
67
+  * @since May 2, 2016 9:46:27 AM
68
+  * @uses
69
+  * @see
70
+  */
71
+ public function getStatusCode() {
72 72
 
73
-		return $this->statusCode;
73
+  return $this->statusCode;
74 74
 
75
-	}
75
+ }
76 76
 
77
-	/**
78
-	 * Setter for $statusCode
79
-	 * @param integer $statusCode
80
-	 * @return $this
81
-	 * @author Shima Payro <[email protected]>
82
-	 * @since May 2, 2016 9:47:04 AM
83
-	 * @uses
84
-	 * @see
85
-	 */
86
-	public function setStatusCode( $statusCode ) {
77
+ /**
78
+  * Setter for $statusCode
79
+  * @param integer $statusCode
80
+  * @return $this
81
+  * @author Shima Payro <[email protected]>
82
+  * @since May 2, 2016 9:47:04 AM
83
+  * @uses
84
+  * @see
85
+  */
86
+ public function setStatusCode( $statusCode ) {
87 87
 
88
-		$this->statusCode = $statusCode;
88
+  $this->statusCode = $statusCode;
89 89
 
90
-		return $this;
90
+  return $this;
91 91
 
92
-	}
92
+ }
93 93
 
94
-	/**
95
-	 * Getter for $statusText
96
-	 * @author Shima Payro <[email protected]>
97
-	 * @since May 2, 2016 9:47:36 AM
98
-	 * @uses
99
-	 * @see
100
-	 */
101
-	public function getStatusText() {
94
+ /**
95
+  * Getter for $statusText
96
+  * @author Shima Payro <[email protected]>
97
+  * @since May 2, 2016 9:47:36 AM
98
+  * @uses
99
+  * @see
100
+  */
101
+ public function getStatusText() {
102 102
 
103
-		return $this->statusText;
103
+  return $this->statusText;
104 104
 
105
-	}
105
+ }
106 106
 
107
-	/**
108
-	 * Setter for $statusText
109
-	 * @param String $statusText
110
-	 * @return $this
111
-	 * @author Shima Payro <[email protected]>
112
-	 * @since May 2, 2016 9:48:23 AM
113
-	 * @uses
114
-	 * @see
115
-	 */
116
-	public function setStatusText( $statusText ) {
107
+ /**
108
+  * Setter for $statusText
109
+  * @param String $statusText
110
+  * @return $this
111
+  * @author Shima Payro <[email protected]>
112
+  * @since May 2, 2016 9:48:23 AM
113
+  * @uses
114
+  * @see
115
+  */
116
+ public function setStatusText( $statusText ) {
117 117
 
118
-		$this->statusText = $statusText;
118
+  $this->statusText = $statusText;
119 119
 
120
-		return $this;
120
+  return $this;
121 121
 
122
-	}
122
+ }
123 123
 
124
-	/**
125
-	 * Response
126
-	 * @param $data : json
127
-	 * @return $this|\Illuminate\Http\JsonResponse
128
-	 * @author Shima Payro <[email protected]>
129
-	 * @since May 2, 2016 9:48:45 AM
130
-	 * @uses
131
-	 * @see
132
-	 */
133
-	public function respond( $data ) {
124
+ /**
125
+  * Response
126
+  * @param $data : json
127
+  * @return $this|\Illuminate\Http\JsonResponse
128
+  * @author Shima Payro <[email protected]>
129
+  * @since May 2, 2016 9:48:45 AM
130
+  * @uses
131
+  * @see
132
+  */
133
+ public function respond( $data ) {
134 134
 
135
-		$result = array_filter( $this->getHeaders() );
135
+  $result = array_filter( $this->getHeaders() );
136 136
 
137
-		if ( empty( $result ) )
138
-			return response()->json( $data, $this->getStatusCode() );
137
+  if ( empty( $result ) )
138
+   return response()->json( $data, $this->getStatusCode() );
139 139
 
140
-		return response()->json( $data, $this->getStatusCode() )
141
-						->withHeaders( $this->getHeaders() );
140
+  return response()->json( $data, $this->getStatusCode() )
141
+      ->withHeaders( $this->getHeaders() );
142 142
 
143
-	}
143
+ }
144 144
 
145
-	/**
146
-	 * Response which conteins just a message
147
-	 * @param string $message
148
-	 * @author Shima Payro <[email protected]>
149
-	 * @since May 2, 2016 9:49:21 AM
150
-	 * @return Main|\Illuminate\Http\JsonResponse
151
-	 * @uses
152
-	 * @see
153
-	 */
154
-	public function respondWithMessage( $message = null ) {
145
+ /**
146
+  * Response which conteins just a message
147
+  * @param string $message
148
+  * @author Shima Payro <[email protected]>
149
+  * @since May 2, 2016 9:49:21 AM
150
+  * @return Main|\Illuminate\Http\JsonResponse
151
+  * @uses
152
+  * @see
153
+  */
154
+ public function respondWithMessage( $message = null ) {
155 155
 
156
-		$res[ 'status' ] = $this->getStatusText();
156
+  $res[ 'status' ] = $this->getStatusText();
157 157
 
158
-		//if it's about failure
159
-		if ( $this->getErrorCode() ) {
158
+  //if it's about failure
159
+  if ( $this->getErrorCode() ) {
160 160
 
161
-			$res[ 'error' ] = $this->getErrorCode();
161
+   $res[ 'error' ] = $this->getErrorCode();
162 162
 
163
-			if ( is_null( $message ) )
164
-		     $res[ 'message' ] = $this->getErrorMessage();
165
-		    else
166
-		     $res[ 'message' ] = $message;
163
+   if ( is_null( $message ) )
164
+       $res[ 'message' ] = $this->getErrorMessage();
165
+      else
166
+       $res[ 'message' ] = $message;
167 167
 
168
-		} else {
168
+  } else {
169 169
 
170
-			$res[ 'message' ] = $message;
170
+   $res[ 'message' ] = $message;
171 171
 
172
-		}
172
+  }
173 173
 
174
-		return $this->respond( $res );
174
+  return $this->respond( $res );
175 175
 
176
-	}
176
+ }
177 177
 
178
-	/**
179
-	 * Set error code in our result
180
-	 * @author Mehdi Hosseini <[email protected]>
181
-	 * @since August 24, 2016
182
-	 * @param $errorCode integer
183
-	 * @return $this
184
-	 */
185
-	public function setErrorCode( $errorCode ) {
178
+ /**
179
+  * Set error code in our result
180
+  * @author Mehdi Hosseini <[email protected]>
181
+  * @since August 24, 2016
182
+  * @param $errorCode integer
183
+  * @return $this
184
+  */
185
+ public function setErrorCode( $errorCode ) {
186 186
 
187
-		$this->error = $this->config[ $errorCode ];
187
+  $this->error = $this->config[ $errorCode ];
188 188
 
189
-		$this->errorCode = $errorCode;
189
+  $this->errorCode = $errorCode;
190 190
 
191
-		return $this;
191
+  return $this;
192 192
 
193
-	}
193
+ }
194 194
 
195
-	/**
196
-	 * Return Error code
197
-	 * @author Mehdi Hosseini <[email protected]>
198
-	 * @since August 24, 2016
199
-	 * @return integer
200
-	 */
201
-	public function getErrorCode() {
195
+ /**
196
+  * Return Error code
197
+  * @author Mehdi Hosseini <[email protected]>
198
+  * @since August 24, 2016
199
+  * @return integer
200
+  */
201
+ public function getErrorCode() {
202 202
 
203
-		return $this->errorCode;
203
+  return $this->errorCode;
204 204
 
205
-	}
205
+ }
206 206
 
207
-	/**
208
-	 * Get error message
209
-	 * @author Mehdi Hosseini <[email protected]>
210
-	 * @since August 24, 2016
211
-	 * @return string
212
-	 */
213
-	public function getErrorMessage() {
207
+ /**
208
+  * Get error message
209
+  * @author Mehdi Hosseini <[email protected]>
210
+  * @since August 24, 2016
211
+  * @return string
212
+  */
213
+ public function getErrorMessage() {
214 214
 
215
-		return $this->error['message'];
215
+  return $this->error['message'];
216 216
 
217
-	}
217
+ }
218 218
 
219
-	/**
220
-	 * Get headers
221
-	 * @author Shima Payro <[email protected]>
222
-	 * @since Sep 13, 2016
223
-	 * @return array
224
-	 */
225
-	public function getHeaders() {
219
+ /**
220
+  * Get headers
221
+  * @author Shima Payro <[email protected]>
222
+  * @since Sep 13, 2016
223
+  * @return array
224
+  */
225
+ public function getHeaders() {
226 226
 
227
-		return $this->headers;
227
+  return $this->headers;
228 228
 
229
-	}
229
+ }
230 230
 
231
-	/**
232
-	 * Set headers
233
-	 * @author Shima Payro <[email protected]>
234
-	 * @since Sep 13, 2016
235
-	 * @return array
236
-	 */
237
-	public function setHeaders( $headers = [] ) {
231
+ /**
232
+  * Set headers
233
+  * @author Shima Payro <[email protected]>
234
+  * @since Sep 13, 2016
235
+  * @return array
236
+  */
237
+ public function setHeaders( $headers = [] ) {
238 238
 
239
-		$this->headers = $headers;
239
+  $this->headers = $headers;
240 240
 
241
-		return $this;
241
+  return $this;
242 242
 
243
-	}
243
+ }
244 244
 
245
-	/**
246
-	 * Response which contains status and data
247
-	 * @param null|array $data
248
-	 * @author Shima Payro <[email protected]>
249
-	 * @since May 2, 2016 9:50:19 AM
250
-	 * @return Main|\Illuminate\Http\JsonResponse
251
-	 * @uses
252
-	 * @see
253
-	 */
254
-	 public function respondWithResult( $data = NULL ) {
245
+ /**
246
+  * Response which contains status and data
247
+  * @param null|array $data
248
+  * @author Shima Payro <[email protected]>
249
+  * @since May 2, 2016 9:50:19 AM
250
+  * @return Main|\Illuminate\Http\JsonResponse
251
+  * @uses
252
+  * @see
253
+  */
254
+  public function respondWithResult( $data = NULL ) {
255 255
 
256
-		$res[ 'status' ] = $this->getStatusText();
256
+  $res[ 'status' ] = $this->getStatusText();
257 257
 
258
-		//if it's about laravel validation error
259
-		if ( $this->getErrorCode() && $this->getStatusCode() == 420 ) {
258
+  //if it's about laravel validation error
259
+  if ( $this->getErrorCode() && $this->getStatusCode() == 420 ) {
260 260
 
261
-			$res[ 'error' ] = $this->getErrorCode();
262
-			$res[ 'message' ] = $data;
261
+   $res[ 'error' ] = $this->getErrorCode();
262
+   $res[ 'message' ] = $data;
263 263
 
264
-		} else {
264
+  } else {
265 265
 
266
-			$res[ 'result' ] = $data;
266
+   $res[ 'result' ] = $data;
267 267
 
268
-		}
268
+  }
269 269
 
270
-		return $this->respond( $res );
270
+  return $this->respond( $res );
271 271
 
272
-	}
272
+ }
273 273
 
274 274
 }
Please login to merge, or discard this patch.
Spacing   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -32,7 +32,7 @@  discard block
 block discarded – undo
32 32
 	 * Haeders
33 33
 	 * @var array
34 34
 	 */
35
-	protected $headers = [];
35
+	protected $headers = [ ];
36 36
 
37 37
 	/**
38 38
 	 * @var string
@@ -53,10 +53,10 @@  discard block
 block discarded – undo
53 53
 
54 54
 		$this->lang = \App::getLocale();
55 55
 
56
-		if(! file_exists(config_path($this->lang . '.php'))){
57
-            $this->config = include __DIR__ . '/../errors/lang/' . $this->lang . '.php';
56
+		if (!file_exists(config_path($this->lang.'.php'))) {
57
+            $this->config = include __DIR__.'/../errors/lang/'.$this->lang.'.php';
58 58
         } else {
59
-            $this->config = include config_path($this->lang . '.php');
59
+            $this->config = include config_path($this->lang.'.php');
60 60
         }
61 61
 
62 62
 	}
@@ -83,7 +83,7 @@  discard block
 block discarded – undo
83 83
 	 * @uses
84 84
 	 * @see
85 85
 	 */
86
-	public function setStatusCode( $statusCode ) {
86
+	public function setStatusCode($statusCode) {
87 87
 
88 88
 		$this->statusCode = $statusCode;
89 89
 
@@ -113,7 +113,7 @@  discard block
 block discarded – undo
113 113
 	 * @uses
114 114
 	 * @see
115 115
 	 */
116
-	public function setStatusText( $statusText ) {
116
+	public function setStatusText($statusText) {
117 117
 
118 118
 		$this->statusText = $statusText;
119 119
 
@@ -130,15 +130,15 @@  discard block
 block discarded – undo
130 130
 	 * @uses
131 131
 	 * @see
132 132
 	 */
133
-	public function respond( $data ) {
133
+	public function respond($data) {
134 134
 
135
-		$result = array_filter( $this->getHeaders() );
135
+		$result = array_filter($this->getHeaders());
136 136
 
137
-		if ( empty( $result ) )
138
-			return response()->json( $data, $this->getStatusCode() );
137
+		if (empty($result))
138
+			return response()->json($data, $this->getStatusCode());
139 139
 
140
-		return response()->json( $data, $this->getStatusCode() )
141
-						->withHeaders( $this->getHeaders() );
140
+		return response()->json($data, $this->getStatusCode())
141
+						->withHeaders($this->getHeaders());
142 142
 
143 143
 	}
144 144
 
@@ -151,16 +151,16 @@  discard block
 block discarded – undo
151 151
 	 * @uses
152 152
 	 * @see
153 153
 	 */
154
-	public function respondWithMessage( $message = null ) {
154
+	public function respondWithMessage($message = null) {
155 155
 
156 156
 		$res[ 'status' ] = $this->getStatusText();
157 157
 
158 158
 		//if it's about failure
159
-		if ( $this->getErrorCode() ) {
159
+		if ($this->getErrorCode()) {
160 160
 
161 161
 			$res[ 'error' ] = $this->getErrorCode();
162 162
 
163
-			if ( is_null( $message ) )
163
+			if (is_null($message))
164 164
 		     $res[ 'message' ] = $this->getErrorMessage();
165 165
 		    else
166 166
 		     $res[ 'message' ] = $message;
@@ -171,7 +171,7 @@  discard block
 block discarded – undo
171 171
 
172 172
 		}
173 173
 
174
-		return $this->respond( $res );
174
+		return $this->respond($res);
175 175
 
176 176
 	}
177 177
 
@@ -182,7 +182,7 @@  discard block
 block discarded – undo
182 182
 	 * @param $errorCode integer
183 183
 	 * @return $this
184 184
 	 */
185
-	public function setErrorCode( $errorCode ) {
185
+	public function setErrorCode($errorCode) {
186 186
 
187 187
 		$this->error = $this->config[ $errorCode ];
188 188
 
@@ -212,7 +212,7 @@  discard block
 block discarded – undo
212 212
 	 */
213 213
 	public function getErrorMessage() {
214 214
 
215
-		return $this->error['message'];
215
+		return $this->error[ 'message' ];
216 216
 
217 217
 	}
218 218
 
@@ -234,7 +234,7 @@  discard block
 block discarded – undo
234 234
 	 * @since Sep 13, 2016
235 235
 	 * @return array
236 236
 	 */
237
-	public function setHeaders( $headers = [] ) {
237
+	public function setHeaders($headers = [ ]) {
238 238
 
239 239
 		$this->headers = $headers;
240 240
 
@@ -251,12 +251,12 @@  discard block
 block discarded – undo
251 251
 	 * @uses
252 252
 	 * @see
253 253
 	 */
254
-	 public function respondWithResult( $data = NULL ) {
254
+	 public function respondWithResult($data = NULL) {
255 255
 
256 256
 		$res[ 'status' ] = $this->getStatusText();
257 257
 
258 258
 		//if it's about laravel validation error
259
-		if ( $this->getErrorCode() && $this->getStatusCode() == 420 ) {
259
+		if ($this->getErrorCode() && $this->getStatusCode() == 420) {
260 260
 
261 261
 			$res[ 'error' ] = $this->getErrorCode();
262 262
 			$res[ 'message' ] = $data;
@@ -267,7 +267,7 @@  discard block
 block discarded – undo
267 267
 
268 268
 		}
269 269
 
270
-		return $this->respond( $res );
270
+		return $this->respond($res);
271 271
 
272 272
 	}
273 273
 
Please login to merge, or discard this patch.