@@ -24,9 +24,9 @@ discard block |
||
24 | 24 | * @param mixed $message |
25 | 25 | * @return JsonResponse |
26 | 26 | */ |
27 | - public function errorResponse(string $errorCode = null, int $statusCode = null, $message = null):JsonResponse |
|
27 | + public function errorResponse( string $errorCode = null, int $statusCode = null, $message = null ):JsonResponse |
|
28 | 28 | { |
29 | - return app(Responder::class)->error($errorCode, $statusCode, $message); |
|
29 | + return app( Responder::class )->error( $errorCode, $statusCode, $message ); |
|
30 | 30 | } |
31 | 31 | |
32 | 32 | /** |
@@ -37,9 +37,9 @@ discard block |
||
37 | 37 | * @param array $meta |
38 | 38 | * @return \Illuminate\Http\JsonResponse |
39 | 39 | */ |
40 | - public function successResponse($data = null, $statusCode = null, array $meta = []):JsonResponse |
|
40 | + public function successResponse( $data = null, $statusCode = null, array $meta = [ ] ):JsonResponse |
|
41 | 41 | { |
42 | - return app(Responder::class)->success($data, $statusCode, $meta); |
|
42 | + return app( Responder::class )->success( $data, $statusCode, $meta ); |
|
43 | 43 | } |
44 | 44 | |
45 | 45 | /** |
@@ -49,8 +49,8 @@ discard block |
||
49 | 49 | * @param callable|string|null $transformer |
50 | 50 | * @return \Flugg\Responder\Http\SuccessResponse |
51 | 51 | */ |
52 | - public function transform($data = null, $transformer = null):SuccessResponseBuilder |
|
52 | + public function transform( $data = null, $transformer = null ):SuccessResponseBuilder |
|
53 | 53 | { |
54 | - return app(Responder::class)->transform($data, $transformer); |
|
54 | + return app( Responder::class )->transform( $data, $transformer ); |
|
55 | 55 | } |
56 | 56 | } |
57 | 57 | \ No newline at end of file |
@@ -70,7 +70,7 @@ |
||
70 | 70 | /** |
71 | 71 | * SuccessResponseBuilder constructor. |
72 | 72 | * |
73 | - * @param \Illuminate\Contracts\Routing\ResponseFactory|\Laravel\Lumen\Http\ResponseFactory $responseFactory |
|
73 | + * @param \Illuminate\Contracts\Routing\ResponseFactory $responseFactory |
|
74 | 74 | * @param \Flugg\Responder\ResourceFactory $resourceFactory |
75 | 75 | * @param \League\Fractal\Manager $manager |
76 | 76 | */ |
@@ -37,14 +37,14 @@ discard block |
||
37 | 37 | * |
38 | 38 | * @var array |
39 | 39 | */ |
40 | - protected $meta = []; |
|
40 | + protected $meta = [ ]; |
|
41 | 41 | |
42 | 42 | /** |
43 | 43 | * The included relations. |
44 | 44 | * |
45 | 45 | * @var array |
46 | 46 | */ |
47 | - protected $relations = []; |
|
47 | + protected $relations = [ ]; |
|
48 | 48 | |
49 | 49 | /** |
50 | 50 | * The Fractal resource instance containing the data and transformer. |
@@ -74,13 +74,13 @@ discard block |
||
74 | 74 | * @param \Flugg\Responder\ResourceFactory $resourceFactory |
75 | 75 | * @param \League\Fractal\Manager $manager |
76 | 76 | */ |
77 | - public function __construct($responseFactory, ResourceFactory $resourceFactory, Manager $manager) |
|
77 | + public function __construct( $responseFactory, ResourceFactory $resourceFactory, Manager $manager ) |
|
78 | 78 | { |
79 | 79 | $this->resourceFactory = $resourceFactory; |
80 | 80 | $this->manager = $manager; |
81 | 81 | $this->resource = $this->resourceFactory->make(); |
82 | 82 | |
83 | - parent::__construct($responseFactory); |
|
83 | + parent::__construct( $responseFactory ); |
|
84 | 84 | } |
85 | 85 | |
86 | 86 | /** |
@@ -89,9 +89,9 @@ discard block |
||
89 | 89 | * @param array $data |
90 | 90 | * @return self |
91 | 91 | */ |
92 | - public function addMeta(array $data):SuccessResponseBuilder |
|
92 | + public function addMeta( array $data ):SuccessResponseBuilder |
|
93 | 93 | { |
94 | - $this->meta = array_merge($this->meta, $data); |
|
94 | + $this->meta = array_merge( $this->meta, $data ); |
|
95 | 95 | |
96 | 96 | return $this; |
97 | 97 | } |
@@ -104,11 +104,11 @@ discard block |
||
104 | 104 | */ |
105 | 105 | public function include($relations):SuccessResponseBuilder |
106 | 106 | { |
107 | - if (is_string($relations)) { |
|
108 | - $relations = explode(',', $relations); |
|
107 | + if ( is_string( $relations ) ) { |
|
108 | + $relations = explode( ',', $relations ); |
|
109 | 109 | } |
110 | 110 | |
111 | - $this->relations = array_merge($this->relations, (array) $relations); |
|
111 | + $this->relations = array_merge( $this->relations, (array) $relations ); |
|
112 | 112 | |
113 | 113 | return $this; |
114 | 114 | } |
@@ -119,9 +119,9 @@ discard block |
||
119 | 119 | * @param \League\Fractal\Serializer\SerializerAbstract|string $serializer |
120 | 120 | * @return self |
121 | 121 | */ |
122 | - public function serializer($serializer):SuccessResponseBuilder |
|
122 | + public function serializer( $serializer ):SuccessResponseBuilder |
|
123 | 123 | { |
124 | - $this->manager->setSerializer($this->resolveSerializer($serializer)); |
|
124 | + $this->manager->setSerializer( $this->resolveSerializer( $serializer ) ); |
|
125 | 125 | |
126 | 126 | return $this; |
127 | 127 | } |
@@ -133,13 +133,13 @@ discard block |
||
133 | 133 | * @return self |
134 | 134 | * @throws \InvalidArgumentException |
135 | 135 | */ |
136 | - public function setStatus(int $statusCode):ResponseBuilder |
|
136 | + public function setStatus( int $statusCode ):ResponseBuilder |
|
137 | 137 | { |
138 | - if ($statusCode < 100 || $statusCode >= 400) { |
|
139 | - throw new InvalidArgumentException("{$statusCode} is not a valid success HTTP status code."); |
|
138 | + if ( $statusCode < 100 || $statusCode >= 400 ) { |
|
139 | + throw new InvalidArgumentException( "{$statusCode} is not a valid success HTTP status code." ); |
|
140 | 140 | } |
141 | 141 | |
142 | - return parent::setStatus($statusCode); |
|
142 | + return parent::setStatus( $statusCode ); |
|
143 | 143 | } |
144 | 144 | |
145 | 145 | /** |
@@ -151,25 +151,25 @@ discard block |
||
151 | 151 | * @param string|null $resourceKey |
152 | 152 | * @return self |
153 | 153 | */ |
154 | - public function transform($data = null, $transformer = null, string $resourceKey = null):SuccessResponseBuilder |
|
154 | + public function transform( $data = null, $transformer = null, string $resourceKey = null ):SuccessResponseBuilder |
|
155 | 155 | { |
156 | - $resource = $this->resourceFactory->make($data); |
|
156 | + $resource = $this->resourceFactory->make( $data ); |
|
157 | 157 | |
158 | - if (! is_null($resource->getData())) { |
|
159 | - $model = $this->resolveModel($resource->getData()); |
|
160 | - $transformer = $this->resolveTransformer($model, $transformer); |
|
161 | - $resourceKey = $this->resolveResourceKey($model, $resourceKey); |
|
158 | + if ( ! is_null( $resource->getData() ) ) { |
|
159 | + $model = $this->resolveModel( $resource->getData() ); |
|
160 | + $transformer = $this->resolveTransformer( $model, $transformer ); |
|
161 | + $resourceKey = $this->resolveResourceKey( $model, $resourceKey ); |
|
162 | 162 | } |
163 | 163 | |
164 | - if ($transformer instanceof Transformer) { |
|
165 | - $this->include($relations = $this->resolveNestedRelations($resource->getData())); |
|
164 | + if ( $transformer instanceof Transformer ) { |
|
165 | + $this->include( $relations = $this->resolveNestedRelations( $resource->getData() ) ); |
|
166 | 166 | |
167 | - if ($transformer->allRelationsAllowed()) { |
|
168 | - $transformer->setRelations($relations); |
|
167 | + if ( $transformer->allRelationsAllowed() ) { |
|
168 | + $transformer->setRelations( $relations ); |
|
169 | 169 | } |
170 | 170 | } |
171 | 171 | |
172 | - $this->resource = $resource->setTransformer($transformer)->setResourceKey($resourceKey); |
|
172 | + $this->resource = $resource->setTransformer( $transformer )->setResourceKey( $resourceKey ); |
|
173 | 173 | |
174 | 174 | return $this; |
175 | 175 | } |
@@ -181,7 +181,7 @@ discard block |
||
181 | 181 | */ |
182 | 182 | public function toArray():array |
183 | 183 | { |
184 | - return $this->serialize($this->getResource()); |
|
184 | + return $this->serialize( $this->getResource() ); |
|
185 | 185 | } |
186 | 186 | |
187 | 187 | /** |
@@ -191,14 +191,14 @@ discard block |
||
191 | 191 | */ |
192 | 192 | public function getResource():ResourceInterface |
193 | 193 | { |
194 | - $this->manager->parseIncludes($this->relations); |
|
194 | + $this->manager->parseIncludes( $this->relations ); |
|
195 | 195 | $transformer = $this->resource->getTransformer(); |
196 | 196 | |
197 | - if ($transformer instanceof Transformer && $transformer->allRelationsAllowed()) { |
|
198 | - $this->resource->setTransformer($transformer->setRelations($this->manager->getRequestedIncludes())); |
|
197 | + if ( $transformer instanceof Transformer && $transformer->allRelationsAllowed() ) { |
|
198 | + $this->resource->setTransformer( $transformer->setRelations( $this->manager->getRequestedIncludes() ) ); |
|
199 | 199 | } |
200 | 200 | |
201 | - return $this->resource->setMeta($this->meta); |
|
201 | + return $this->resource->setMeta( $this->meta ); |
|
202 | 202 | } |
203 | 203 | |
204 | 204 | /** |
@@ -218,13 +218,13 @@ discard block |
||
218 | 218 | * @return \League\Fractal\Serializer\SerializerAbstract |
219 | 219 | * @throws \Flugg\Responder\Exceptions\InvalidSerializerException |
220 | 220 | */ |
221 | - protected function resolveSerializer($serializer):SerializerAbstract |
|
221 | + protected function resolveSerializer( $serializer ):SerializerAbstract |
|
222 | 222 | { |
223 | - if (is_string($serializer)) { |
|
223 | + if ( is_string( $serializer ) ) { |
|
224 | 224 | $serializer = new $serializer; |
225 | 225 | } |
226 | 226 | |
227 | - if (! $serializer instanceof SerializerAbstract) { |
|
227 | + if ( ! $serializer instanceof SerializerAbstract ) { |
|
228 | 228 | throw new InvalidSerializerException(); |
229 | 229 | } |
230 | 230 | |
@@ -238,15 +238,15 @@ discard block |
||
238 | 238 | * @return \Illuminate\Database\Eloquent\Model |
239 | 239 | * @throws \InvalidArgumentException |
240 | 240 | */ |
241 | - protected function resolveModel($data):Model |
|
241 | + protected function resolveModel( $data ):Model |
|
242 | 242 | { |
243 | - if ($data instanceof Model) { |
|
243 | + if ( $data instanceof Model ) { |
|
244 | 244 | return $data; |
245 | 245 | } |
246 | 246 | |
247 | - $model = array_values($data)[0]; |
|
248 | - if (! $model instanceof Model) { |
|
249 | - throw new InvalidArgumentException('You can only transform data containing Eloquent models.'); |
|
247 | + $model = array_values( $data )[ 0 ]; |
|
248 | + if ( ! $model instanceof Model ) { |
|
249 | + throw new InvalidArgumentException( 'You can only transform data containing Eloquent models.' ); |
|
250 | 250 | } |
251 | 251 | |
252 | 252 | return $model; |
@@ -259,15 +259,15 @@ discard block |
||
259 | 259 | * @param \Flugg\Responder\Transformer|callable|null $transformer |
260 | 260 | * @return \Flugg\Responder\Transformer|callable |
261 | 261 | */ |
262 | - protected function resolveTransformer(Model $model, $transformer = null) |
|
262 | + protected function resolveTransformer( Model $model, $transformer = null ) |
|
263 | 263 | { |
264 | - $transformer = $transformer ?: $this->resolveTransformerFromModel($model); |
|
264 | + $transformer = $transformer ?: $this->resolveTransformerFromModel( $model ); |
|
265 | 265 | |
266 | - if (is_string($transformer)) { |
|
266 | + if ( is_string( $transformer ) ) { |
|
267 | 267 | $transformer = new $transformer; |
268 | 268 | } |
269 | 269 | |
270 | - return $this->parseTransformer($transformer, $model); |
|
270 | + return $this->parseTransformer( $transformer, $model ); |
|
271 | 271 | } |
272 | 272 | |
273 | 273 | /** |
@@ -277,10 +277,10 @@ discard block |
||
277 | 277 | * @param \Illuminate\Database\ELoquent\Model $model |
278 | 278 | * @return \Flugg\Responder\Transformer|callable |
279 | 279 | */ |
280 | - protected function resolveTransformerFromModel(Model $model) |
|
280 | + protected function resolveTransformerFromModel( Model $model ) |
|
281 | 281 | { |
282 | - if (! $model instanceof Transformable) { |
|
283 | - return function ($model) { |
|
282 | + if ( ! $model instanceof Transformable ) { |
|
283 | + return function ( $model ) { |
|
284 | 284 | return $model->toArray(); |
285 | 285 | }; |
286 | 286 | } |
@@ -296,14 +296,14 @@ discard block |
||
296 | 296 | * @return \Flugg\Responder\Transformer|callable |
297 | 297 | * @throws \InvalidTransformerException |
298 | 298 | */ |
299 | - protected function parseTransformer($transformer, Model $model) |
|
299 | + protected function parseTransformer( $transformer, Model $model ) |
|
300 | 300 | { |
301 | - if ($transformer instanceof Transformer) { |
|
302 | - $relations = $transformer->allRelationsAllowed() ? $this->resolveRelations($model) : $transformer->getRelations(); |
|
303 | - $transformer = $transformer->setRelations($relations); |
|
301 | + if ( $transformer instanceof Transformer ) { |
|
302 | + $relations = $transformer->allRelationsAllowed() ? $this->resolveRelations( $model ) : $transformer->getRelations(); |
|
303 | + $transformer = $transformer->setRelations( $relations ); |
|
304 | 304 | |
305 | - } elseif (! is_callable($transformer)) { |
|
306 | - throw new InvalidTransformerException($model); |
|
305 | + } elseif ( ! is_callable( $transformer ) ) { |
|
306 | + throw new InvalidTransformerException( $model ); |
|
307 | 307 | } |
308 | 308 | |
309 | 309 | return $transformer; |
@@ -315,9 +315,9 @@ discard block |
||
315 | 315 | * @param \Illuminate\Database\Eloquent\Model $model |
316 | 316 | * @return array |
317 | 317 | */ |
318 | - protected function resolveRelations(Model $model):array |
|
318 | + protected function resolveRelations( Model $model ):array |
|
319 | 319 | { |
320 | - return array_keys($model->getRelations()); |
|
320 | + return array_keys( $model->getRelations() ); |
|
321 | 321 | } |
322 | 322 | |
323 | 323 | /** |
@@ -326,22 +326,22 @@ discard block |
||
326 | 326 | * @param \Illuminate\Support\Collection|\Illuminate\Database\Eloquent\Model $data |
327 | 327 | * @return array |
328 | 328 | */ |
329 | - protected function resolveNestedRelations($data):array |
|
329 | + protected function resolveNestedRelations( $data ):array |
|
330 | 330 | { |
331 | - if (is_null($data)) { |
|
332 | - return []; |
|
331 | + if ( is_null( $data ) ) { |
|
332 | + return [ ]; |
|
333 | 333 | } |
334 | 334 | |
335 | - $data = $data instanceof Model ? [$data] : $data; |
|
335 | + $data = $data instanceof Model ? [ $data ] : $data; |
|
336 | 336 | |
337 | - return collect($data)->flatMap(function ($model) { |
|
338 | - $relations = collect($model->getRelations()); |
|
337 | + return collect( $data )->flatMap( function ( $model ) { |
|
338 | + $relations = collect( $model->getRelations() ); |
|
339 | 339 | |
340 | - return $relations->keys()->merge($relations->flatMap(function ($relation, $key) { |
|
341 | - return collect($this->resolveNestedRelations($relation))->map(function ($nestedRelation) use ($key) { |
|
340 | + return $relations->keys()->merge( $relations->flatMap( function ( $relation, $key ) { |
|
341 | + return collect( $this->resolveNestedRelations( $relation ) )->map( function ( $nestedRelation ) use ($key) { |
|
342 | 342 | return $key . '.' . $nestedRelation; |
343 | 343 | }); |
344 | - })); |
|
344 | + }) ); |
|
345 | 345 | })->unique()->toArray(); |
346 | 346 | } |
347 | 347 | |
@@ -352,13 +352,13 @@ discard block |
||
352 | 352 | * @param string|null $resourceKey |
353 | 353 | * @return string |
354 | 354 | */ |
355 | - protected function resolveResourceKey(Model $model, string $resourceKey = null):string |
|
355 | + protected function resolveResourceKey( Model $model, string $resourceKey = null ):string |
|
356 | 356 | { |
357 | - if (! is_null($resourceKey)) { |
|
357 | + if ( ! is_null( $resourceKey ) ) { |
|
358 | 358 | return $resourceKey; |
359 | 359 | } |
360 | 360 | |
361 | - if (method_exists($model, 'getResourceKey')) { |
|
361 | + if ( method_exists( $model, 'getResourceKey' ) ) { |
|
362 | 362 | return $model->getResourceKey(); |
363 | 363 | } |
364 | 364 | |
@@ -371,8 +371,8 @@ discard block |
||
371 | 371 | * @param ResourceInterface $resource |
372 | 372 | * @return array |
373 | 373 | */ |
374 | - protected function serialize(ResourceInterface $resource):array |
|
374 | + protected function serialize( ResourceInterface $resource ):array |
|
375 | 375 | { |
376 | - return $this->manager->createData($resource)->toArray(); |
|
376 | + return $this->manager->createData( $resource )->toArray(); |
|
377 | 377 | } |
378 | 378 | } |
@@ -6,8 +6,6 @@ |
||
6 | 6 | use Flugg\Responder\Exceptions\InvalidSerializerException; |
7 | 7 | use Flugg\Responder\Exceptions\InvalidTransformerException; |
8 | 8 | use Flugg\Responder\ResourceFactory; |
9 | -use Flugg\Responder\ResourceResolver; |
|
10 | -use Flugg\Responder\Transformation; |
|
11 | 9 | use Flugg\Responder\Transformer; |
12 | 10 | use Illuminate\Database\Eloquent\Model; |
13 | 11 | use InvalidArgumentException; |
@@ -22,7 +22,7 @@ discard block |
||
22 | 22 | * |
23 | 23 | * @var array |
24 | 24 | */ |
25 | - protected $relations = ['*']; |
|
25 | + protected $relations = [ '*' ]; |
|
26 | 26 | |
27 | 27 | /** |
28 | 28 | * Get relations set on the transformer. |
@@ -31,9 +31,9 @@ discard block |
||
31 | 31 | */ |
32 | 32 | public function getRelations():array |
33 | 33 | { |
34 | - $relations = array_unique(array_merge($this->getAvailableIncludes(), $this->relations)); |
|
34 | + $relations = array_unique( array_merge( $this->getAvailableIncludes(), $this->relations ) ); |
|
35 | 35 | |
36 | - return array_filter($relations, function($relation) { |
|
36 | + return array_filter( $relations, function ( $relation ) { |
|
37 | 37 | return $relation !== '*'; |
38 | 38 | }); |
39 | 39 | } |
@@ -44,9 +44,9 @@ discard block |
||
44 | 44 | * @param array|string $relations |
45 | 45 | * @return self |
46 | 46 | */ |
47 | - public function setRelations($relations) |
|
47 | + public function setRelations( $relations ) |
|
48 | 48 | { |
49 | - $this->setAvailableIncludes(array_unique(array_merge($this->availableIncludes, (array) $relations))); |
|
49 | + $this->setAvailableIncludes( array_unique( array_merge( $this->availableIncludes, (array) $relations ) ) ); |
|
50 | 50 | |
51 | 51 | return $this; |
52 | 52 | } |
@@ -58,7 +58,7 @@ discard block |
||
58 | 58 | */ |
59 | 59 | public function allRelationsAllowed():bool |
60 | 60 | { |
61 | - return $this->relations == ['*']; |
|
61 | + return $this->relations == [ '*' ]; |
|
62 | 62 | } |
63 | 63 | |
64 | 64 | /** |
@@ -71,24 +71,24 @@ discard block |
||
71 | 71 | * @return \League\Fractal\Resource\ResourceInterface|bool |
72 | 72 | * @throws \Exception |
73 | 73 | */ |
74 | - protected function callIncludeMethod(Scope $scope, $includeName, $data) |
|
74 | + protected function callIncludeMethod( Scope $scope, $includeName, $data ) |
|
75 | 75 | { |
76 | - if ($includeName === 'pivot') { |
|
77 | - return $this->includePivot($data->$includeName); |
|
76 | + if ( $includeName === 'pivot' ) { |
|
77 | + return $this->includePivot( $data->$includeName ); |
|
78 | 78 | } |
79 | 79 | |
80 | - $params = $scope->getManager()->getIncludeParams($scope->getIdentifier($includeName)); |
|
80 | + $params = $scope->getManager()->getIncludeParams( $scope->getIdentifier( $includeName ) ); |
|
81 | 81 | |
82 | - if (method_exists($this, $includeName)) { |
|
83 | - $include = call_user_func([$this, $includeName], $data, $params); |
|
82 | + if ( method_exists( $this, $includeName ) ) { |
|
83 | + $include = call_user_func( [ $this, $includeName ], $data, $params ); |
|
84 | 84 | |
85 | - if ($include instanceof ResourceAbstract) { |
|
85 | + if ( $include instanceof ResourceAbstract ) { |
|
86 | 86 | return $include; |
87 | 87 | } |
88 | 88 | |
89 | - return app(Responder::class)->transform($include)->getResource(); |
|
89 | + return app( Responder::class )->transform( $include )->getResource(); |
|
90 | 90 | } else { |
91 | - return app(Responder::class)->transform($data->$includeName)->getResource(); |
|
91 | + return app( Responder::class )->transform( $data->$includeName )->getResource(); |
|
92 | 92 | } |
93 | 93 | } |
94 | 94 | |
@@ -98,14 +98,14 @@ discard block |
||
98 | 98 | * @param Pivot $pivot |
99 | 99 | * @return \League\Fractal\Resource\ResourceInterface|bool |
100 | 100 | */ |
101 | - protected function includePivot(Pivot $pivot) |
|
101 | + protected function includePivot( Pivot $pivot ) |
|
102 | 102 | { |
103 | - if (! method_exists($this, 'transformPivot')) { |
|
103 | + if ( ! method_exists( $this, 'transformPivot' ) ) { |
|
104 | 104 | return false; |
105 | 105 | } |
106 | 106 | |
107 | - return app(Responder::class)->transform($pivot, function ($pivot) { |
|
108 | - return $this->transformPivot($pivot); |
|
107 | + return app( Responder::class )->transform( $pivot, function ( $pivot ) { |
|
108 | + return $this->transformPivot( $pivot ); |
|
109 | 109 | })->getResource(); |
110 | 110 | } |
111 | 111 | } |
112 | 112 | \ No newline at end of file |
@@ -41,9 +41,9 @@ |
||
41 | 41 | * |
42 | 42 | * @param mixed $message |
43 | 43 | */ |
44 | - public function __construct($message = null) |
|
44 | + public function __construct( $message = null ) |
|
45 | 45 | { |
46 | - parent::__construct($this->statusCode, $this->message ?? $message); |
|
46 | + parent::__construct( $this->statusCode, $this->message ?? $message ); |
|
47 | 47 | } |
48 | 48 | |
49 | 49 | /** |
@@ -22,9 +22,9 @@ discard block |
||
22 | 22 | * @param array $data |
23 | 23 | * @return array |
24 | 24 | */ |
25 | - public function collection($resourceKey, array $data) |
|
25 | + public function collection( $resourceKey, array $data ) |
|
26 | 26 | { |
27 | - return $this->item($resourceKey, $data); |
|
27 | + return $this->item( $resourceKey, $data ); |
|
28 | 28 | } |
29 | 29 | |
30 | 30 | /** |
@@ -34,11 +34,11 @@ discard block |
||
34 | 34 | * @param array $data |
35 | 35 | * @return array |
36 | 36 | */ |
37 | - public function item($resourceKey, array $data) |
|
37 | + public function item( $resourceKey, array $data ) |
|
38 | 38 | { |
39 | - return array_merge($this->null(), [ |
|
39 | + return array_merge( $this->null(), [ |
|
40 | 40 | 'data' => $data |
41 | - ]); |
|
41 | + ] ); |
|
42 | 42 | } |
43 | 43 | |
44 | 44 | /** |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | * @param array $meta |
61 | 61 | * @return array |
62 | 62 | */ |
63 | - public function meta(array $meta) |
|
63 | + public function meta( array $meta ) |
|
64 | 64 | { |
65 | 65 | return $meta; |
66 | 66 | } |
@@ -72,20 +72,20 @@ discard block |
||
72 | 72 | * |
73 | 73 | * @return array |
74 | 74 | */ |
75 | - public function paginator(PaginatorInterface $paginator) |
|
75 | + public function paginator( PaginatorInterface $paginator ) |
|
76 | 76 | { |
77 | - $pagination = parent::paginator($paginator)['pagination']; |
|
77 | + $pagination = parent::paginator( $paginator )[ 'pagination' ]; |
|
78 | 78 | |
79 | 79 | $data = [ |
80 | - 'total' => $pagination['total'], |
|
81 | - 'count' => $pagination['count'], |
|
82 | - 'perPage' => $pagination['per_page'], |
|
83 | - 'currentPage' => $pagination['current_page'], |
|
84 | - 'totalPages' => $pagination['total_pages'], |
|
85 | - 'links' => $pagination['links'], |
|
80 | + 'total' => $pagination[ 'total' ], |
|
81 | + 'count' => $pagination[ 'count' ], |
|
82 | + 'perPage' => $pagination[ 'per_page' ], |
|
83 | + 'currentPage' => $pagination[ 'current_page' ], |
|
84 | + 'totalPages' => $pagination[ 'total_pages' ], |
|
85 | + 'links' => $pagination[ 'links' ], |
|
86 | 86 | ]; |
87 | 87 | |
88 | - return ['pagination' => $data]; |
|
88 | + return [ 'pagination' => $data ]; |
|
89 | 89 | } |
90 | 90 | |
91 | 91 | /** |
@@ -105,15 +105,15 @@ discard block |
||
105 | 105 | * @param array $includedData |
106 | 106 | * @return array |
107 | 107 | */ |
108 | - public function mergeIncludes($transformedData, $includedData) |
|
108 | + public function mergeIncludes( $transformedData, $includedData ) |
|
109 | 109 | { |
110 | - $keys = array_keys($includedData); |
|
110 | + $keys = array_keys( $includedData ); |
|
111 | 111 | |
112 | - foreach ($keys as $key) { |
|
113 | - $includedData[$key] = $includedData[$key]['data']; |
|
112 | + foreach ( $keys as $key ) { |
|
113 | + $includedData[ $key ] = $includedData[ $key ][ 'data' ]; |
|
114 | 114 | } |
115 | 115 | |
116 | - return array_merge($transformedData, $includedData); |
|
116 | + return array_merge( $transformedData, $includedData ); |
|
117 | 117 | } |
118 | 118 | |
119 | 119 | /** |
@@ -124,8 +124,8 @@ discard block |
||
124 | 124 | * |
125 | 125 | * @return array |
126 | 126 | */ |
127 | - public function includedData(ResourceInterface $resource, array $data) |
|
127 | + public function includedData( ResourceInterface $resource, array $data ) |
|
128 | 128 | { |
129 | - return []; |
|
129 | + return [ ]; |
|
130 | 130 | } |
131 | 131 | } |
@@ -46,17 +46,17 @@ discard block |
||
46 | 46 | * @param mixed|null $data |
47 | 47 | * @return \League\Fractal\Resource\ResourceInterface |
48 | 48 | */ |
49 | - public function make($data = null) |
|
49 | + public function make( $data = null ) |
|
50 | 50 | { |
51 | - if (is_null($data)) { |
|
51 | + if ( is_null( $data ) ) { |
|
52 | 52 | return new NullResource(); |
53 | - } elseif (is_array($data)) { |
|
54 | - return static::makeFromArray($data); |
|
53 | + } elseif ( is_array( $data ) ) { |
|
54 | + return static::makeFromArray( $data ); |
|
55 | 55 | } |
56 | 56 | |
57 | - $method = static::getMakeMethod($data); |
|
57 | + $method = static::getMakeMethod( $data ); |
|
58 | 58 | |
59 | - return static::$method($data); |
|
59 | + return static::$method( $data ); |
|
60 | 60 | } |
61 | 61 | |
62 | 62 | /** |
@@ -66,15 +66,15 @@ discard block |
||
66 | 66 | * @return string |
67 | 67 | * @throws \InvalidArgumentException |
68 | 68 | */ |
69 | - protected function getMakeMethod($data):string |
|
69 | + protected function getMakeMethod( $data ):string |
|
70 | 70 | { |
71 | - foreach (static::MAKE_METHODS as $class => $method) { |
|
72 | - if ($data instanceof $class) { |
|
71 | + foreach ( static::MAKE_METHODS as $class => $method ) { |
|
72 | + if ( $data instanceof $class ) { |
|
73 | 73 | return $method; |
74 | 74 | } |
75 | 75 | } |
76 | 76 | |
77 | - throw new InvalidArgumentException('Given data cannot be transformed.'); |
|
77 | + throw new InvalidArgumentException( 'Given data cannot be transformed.' ); |
|
78 | 78 | } |
79 | 79 | |
80 | 80 | /** |
@@ -83,9 +83,9 @@ discard block |
||
83 | 83 | * @param \Illuminate\Database\Eloquent\Model $model |
84 | 84 | * @return \League\Fractal\Resource\ResourceInterface |
85 | 85 | */ |
86 | - protected function makeFromModel(Model $model):ResourceInterface |
|
86 | + protected function makeFromModel( Model $model ):ResourceInterface |
|
87 | 87 | { |
88 | - return new ItemResource($model); |
|
88 | + return new ItemResource( $model ); |
|
89 | 89 | } |
90 | 90 | |
91 | 91 | /** |
@@ -94,9 +94,9 @@ discard block |
||
94 | 94 | * @param array $array |
95 | 95 | * @return \League\Fractal\Resource\ResourceInterface |
96 | 96 | */ |
97 | - protected function makeFromArray(array $array):ResourceInterface |
|
97 | + protected function makeFromArray( array $array ):ResourceInterface |
|
98 | 98 | { |
99 | - return empty($array) ? new NullResource() : new CollectionResource($array); |
|
99 | + return empty($array) ? new NullResource() : new CollectionResource( $array ); |
|
100 | 100 | } |
101 | 101 | |
102 | 102 | /** |
@@ -105,9 +105,9 @@ discard block |
||
105 | 105 | * @param \Illuminate\Support\Collection $collection |
106 | 106 | * @return \League\Fractal\Resource\ResourceInterface |
107 | 107 | */ |
108 | - protected function makeFromCollection(Collection $collection):ResourceInterface |
|
108 | + protected function makeFromCollection( Collection $collection ):ResourceInterface |
|
109 | 109 | { |
110 | - return static::makeFromArray($collection->all()); |
|
110 | + return static::makeFromArray( $collection->all() ); |
|
111 | 111 | } |
112 | 112 | |
113 | 113 | /** |
@@ -116,9 +116,9 @@ discard block |
||
116 | 116 | * @param \Illuminate\Database\Eloquent\Builder $query |
117 | 117 | * @return \League\Fractal\Resource\ResourceInterface |
118 | 118 | */ |
119 | - protected function makeFromBuilder(Builder $query):ResourceInterface |
|
119 | + protected function makeFromBuilder( Builder $query ):ResourceInterface |
|
120 | 120 | { |
121 | - return static::makeFromCollection($query->get()); |
|
121 | + return static::makeFromCollection( $query->get() ); |
|
122 | 122 | } |
123 | 123 | |
124 | 124 | /** |
@@ -127,15 +127,15 @@ discard block |
||
127 | 127 | * @param \Illuminate\Contracts\Pagination\LengthAwarePaginator $paginator |
128 | 128 | * @return \League\Fractal\Resource\ResourceInterface |
129 | 129 | */ |
130 | - protected function makeFromPaginator(Paginator $paginator):ResourceInterface |
|
130 | + protected function makeFromPaginator( Paginator $paginator ):ResourceInterface |
|
131 | 131 | { |
132 | - $resource = static::makeFromCollection($paginator->getCollection()); |
|
132 | + $resource = static::makeFromCollection( $paginator->getCollection() ); |
|
133 | 133 | |
134 | - if ($resource instanceof CollectionResource) { |
|
135 | - $queryParams = array_diff_key(request()->all(), array_flip(['page'])); |
|
136 | - $paginator->appends($queryParams); |
|
134 | + if ( $resource instanceof CollectionResource ) { |
|
135 | + $queryParams = array_diff_key( request()->all(), array_flip( [ 'page' ] ) ); |
|
136 | + $paginator->appends( $queryParams ); |
|
137 | 137 | |
138 | - $resource->setPaginator(new IlluminatePaginatorAdapter($paginator)); |
|
138 | + $resource->setPaginator( new IlluminatePaginatorAdapter( $paginator ) ); |
|
139 | 139 | } |
140 | 140 | |
141 | 141 | return $resource; |
@@ -147,9 +147,9 @@ discard block |
||
147 | 147 | * @param \Illuminate\Database\Eloquent\Relations\Pivot $pivot |
148 | 148 | * @return \League\Fractal\Resource\ResourceInterface |
149 | 149 | */ |
150 | - protected function makeFromPivot(Pivot $pivot):ResourceInterface |
|
150 | + protected function makeFromPivot( Pivot $pivot ):ResourceInterface |
|
151 | 151 | { |
152 | - return static::makeFromModel($pivot); |
|
152 | + return static::makeFromModel( $pivot ); |
|
153 | 153 | } |
154 | 154 | |
155 | 155 | /** |
@@ -158,8 +158,8 @@ discard block |
||
158 | 158 | * @param \Illuminate\Database\Eloquent\Relations\Relation $relation |
159 | 159 | * @return \League\Fractal\Resource\ResourceInterface |
160 | 160 | */ |
161 | - protected function makeFromRelation(Relation $relation):ResourceInterface |
|
161 | + protected function makeFromRelation( Relation $relation ):ResourceInterface |
|
162 | 162 | { |
163 | - return static::makeFromCollection($relation->get()); |
|
163 | + return static::makeFromCollection( $relation->get() ); |
|
164 | 164 | } |
165 | 165 | } |
@@ -59,7 +59,7 @@ |
||
59 | 59 | /** |
60 | 60 | * Constructor. |
61 | 61 | * |
62 | - * @param \Illuminate\Contracts\Routing\ResponseFactory|\Laravel\Lumen\Http\ResponseFactory $responseFactory |
|
62 | + * @param \Illuminate\Contracts\Routing\ResponseFactory $responseFactory |
|
63 | 63 | * @param \Symfony\Component\Translation\TranslatorInterface|Illuminate\Contracts\Translation\Translator $translator |
64 | 64 | */ |
65 | 65 | public function __construct($responseFactory, $translator) |
@@ -19,7 +19,7 @@ discard block |
||
19 | 19 | * |
20 | 20 | * @var array |
21 | 21 | */ |
22 | - protected $data = []; |
|
22 | + protected $data = [ ]; |
|
23 | 23 | |
24 | 24 | /** |
25 | 25 | * The error code used to identify the error. |
@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | * |
41 | 41 | * @var array |
42 | 42 | */ |
43 | - protected $parameters = []; |
|
43 | + protected $parameters = [ ]; |
|
44 | 44 | |
45 | 45 | /** |
46 | 46 | * The HTTP status code for the response. |
@@ -62,11 +62,11 @@ discard block |
||
62 | 62 | * @param \Illuminate\Contracts\Routing\ResponseFactory|\Laravel\Lumen\Http\ResponseFactory $responseFactory |
63 | 63 | * @param \Symfony\Component\Translation\TranslatorInterface|Illuminate\Contracts\Translation\Translator $translator |
64 | 64 | */ |
65 | - public function __construct($responseFactory, $translator) |
|
65 | + public function __construct( $responseFactory, $translator ) |
|
66 | 66 | { |
67 | 67 | $this->translator = $translator; |
68 | 68 | |
69 | - parent::__construct($responseFactory); |
|
69 | + parent::__construct( $responseFactory ); |
|
70 | 70 | } |
71 | 71 | |
72 | 72 | /** |
@@ -75,9 +75,9 @@ discard block |
||
75 | 75 | * @param array $data |
76 | 76 | * @return self |
77 | 77 | */ |
78 | - public function addData(array $data):ErrorResponseBuilder |
|
78 | + public function addData( array $data ):ErrorResponseBuilder |
|
79 | 79 | { |
80 | - $this->data = array_merge($this->data, $data); |
|
80 | + $this->data = array_merge( $this->data, $data ); |
|
81 | 81 | |
82 | 82 | return $this; |
83 | 83 | } |
@@ -89,11 +89,11 @@ discard block |
||
89 | 89 | * @param string|array|null $message |
90 | 90 | * @return self |
91 | 91 | */ |
92 | - public function setError($errorCode = null, $message = null):ErrorResponseBuilder |
|
92 | + public function setError( $errorCode = null, $message = null ):ErrorResponseBuilder |
|
93 | 93 | { |
94 | 94 | $this->errorCode = $errorCode; |
95 | 95 | |
96 | - if (is_array($message)) { |
|
96 | + if ( is_array( $message ) ) { |
|
97 | 97 | $this->parameters = $message; |
98 | 98 | } else { |
99 | 99 | $this->message = $message; |
@@ -109,12 +109,12 @@ discard block |
||
109 | 109 | * @return self |
110 | 110 | * @throws \InvalidArgumentException |
111 | 111 | */ |
112 | - public function setStatus(int $statusCode):ResponseBuilder |
|
112 | + public function setStatus( int $statusCode ):ResponseBuilder |
|
113 | 113 | { |
114 | - if ($statusCode < 400 || $statusCode >= 600) { |
|
115 | - throw new InvalidArgumentException("{$statusCode} is not a valid error HTTP status code."); |
|
114 | + if ( $statusCode < 400 || $statusCode >= 600 ) { |
|
115 | + throw new InvalidArgumentException( "{$statusCode} is not a valid error HTTP status code." ); |
|
116 | 116 | } |
117 | - return parent::setStatus($statusCode); |
|
117 | + return parent::setStatus( $statusCode ); |
|
118 | 118 | } |
119 | 119 | |
120 | 120 | /** |
@@ -136,7 +136,7 @@ discard block |
||
136 | 136 | */ |
137 | 137 | protected function buildErrorData() |
138 | 138 | { |
139 | - if (is_null($this->errorCode)) { |
|
139 | + if ( is_null( $this->errorCode ) ) { |
|
140 | 140 | return null; |
141 | 141 | } |
142 | 142 | |
@@ -145,7 +145,7 @@ discard block |
||
145 | 145 | 'message' => $this->message ?: $this->resolveMessage() |
146 | 146 | ]; |
147 | 147 | |
148 | - return array_merge($data, $this->data); |
|
148 | + return array_merge( $data, $this->data ); |
|
149 | 149 | } |
150 | 150 | |
151 | 151 | /** |
@@ -155,10 +155,10 @@ discard block |
||
155 | 155 | */ |
156 | 156 | protected function resolveMessage() |
157 | 157 | { |
158 | - if (! $this->translator->has($code = "errors.$this->errorCode")) { |
|
158 | + if ( ! $this->translator->has( $code = "errors.$this->errorCode" ) ) { |
|
159 | 159 | return null; |
160 | 160 | } |
161 | 161 | |
162 | - return $this->translator->trans($code, $this->parameters); |
|
162 | + return $this->translator->trans( $code, $this->parameters ); |
|
163 | 163 | } |
164 | 164 | } |
165 | 165 | \ No newline at end of file |
@@ -22,10 +22,10 @@ discard block |
||
22 | 22 | * @param int $status |
23 | 23 | * @return $this |
24 | 24 | */ |
25 | - protected function seeSuccess($data = null, $status = 200) |
|
25 | + protected function seeSuccess( $data = null, $status = 200 ) |
|
26 | 26 | { |
27 | - $response = $this->seeSuccessResponse($data, $status); |
|
28 | - $this->seeSuccessData($response->getData(true)['data']); |
|
27 | + $response = $this->seeSuccessResponse( $data, $status ); |
|
28 | + $this->seeSuccessData( $response->getData( true )[ 'data' ] ); |
|
29 | 29 | |
30 | 30 | return $this; |
31 | 31 | } |
@@ -37,10 +37,10 @@ discard block |
||
37 | 37 | * @param int $status |
38 | 38 | * @return $this |
39 | 39 | */ |
40 | - protected function seeSuccessEquals($data = null, $status = 200) |
|
40 | + protected function seeSuccessEquals( $data = null, $status = 200 ) |
|
41 | 41 | { |
42 | - $response = $this->seeSuccessResponse($data, $status); |
|
43 | - $this->seeJsonEquals($response->getData(true)); |
|
42 | + $response = $this->seeSuccessResponse( $data, $status ); |
|
43 | + $this->seeJsonEquals( $response->getData( true ) ); |
|
44 | 44 | |
45 | 45 | return $this; |
46 | 46 | } |
@@ -51,11 +51,11 @@ discard block |
||
51 | 51 | * @param mixed $data |
52 | 52 | * @return $this |
53 | 53 | */ |
54 | - protected function seeSuccessStructure($data = null) |
|
54 | + protected function seeSuccessStructure( $data = null ) |
|
55 | 55 | { |
56 | - $this->seeJsonStructure([ |
|
56 | + $this->seeJsonStructure( [ |
|
57 | 57 | 'data' => $data |
58 | - ]); |
|
58 | + ] ); |
|
59 | 59 | |
60 | 60 | return $this; |
61 | 61 | } |
@@ -67,14 +67,14 @@ discard block |
||
67 | 67 | * @param int $status |
68 | 68 | * @return JsonResponse |
69 | 69 | */ |
70 | - protected function seeSuccessResponse($data = null, $status = 200):JsonResponse |
|
70 | + protected function seeSuccessResponse( $data = null, $status = 200 ):JsonResponse |
|
71 | 71 | { |
72 | - $response = app(Responder::class)->success($data, $status); |
|
72 | + $response = app( Responder::class )->success( $data, $status ); |
|
73 | 73 | |
74 | - $this->seeStatusCode($response->getStatusCode())->seeJson([ |
|
74 | + $this->seeStatusCode( $response->getStatusCode() )->seeJson( [ |
|
75 | 75 | 'success' => true, |
76 | 76 | 'status' => $response->getStatusCode() |
77 | - ])->seeJsonStructure(['data']); |
|
77 | + ] )->seeJsonStructure( [ 'data' ] ); |
|
78 | 78 | |
79 | 79 | return $response; |
80 | 80 | } |
@@ -85,13 +85,13 @@ discard block |
||
85 | 85 | * @param mixed $data |
86 | 86 | * @return $this |
87 | 87 | */ |
88 | - protected function seeSuccessData($data = null) |
|
88 | + protected function seeSuccessData( $data = null ) |
|
89 | 89 | { |
90 | - collect($data)->each(function ($value, $key) { |
|
91 | - if (is_array($value)) { |
|
92 | - $this->seeSuccessData($value); |
|
90 | + collect( $data )->each( function ( $value, $key ) { |
|
91 | + if ( is_array( $value ) ) { |
|
92 | + $this->seeSuccessData( $value ); |
|
93 | 93 | } else { |
94 | - $this->seeJson([$key => $value]); |
|
94 | + $this->seeJson( [ $key => $value ] ); |
|
95 | 95 | } |
96 | 96 | }); |
97 | 97 | |
@@ -104,20 +104,20 @@ discard block |
||
104 | 104 | * @param string|array|null $attributes |
105 | 105 | * @return array |
106 | 106 | */ |
107 | - protected function getSuccessData($attributes = null) |
|
107 | + protected function getSuccessData( $attributes = null ) |
|
108 | 108 | { |
109 | - $rawData = $this->decodeResponseJson()['data']; |
|
109 | + $rawData = $this->decodeResponseJson()[ 'data' ]; |
|
110 | 110 | |
111 | - if (is_null($attributes)) { |
|
111 | + if ( is_null( $attributes ) ) { |
|
112 | 112 | return $rawData; |
113 | - } elseif (is_string($attributes)) { |
|
114 | - return array_get($rawData, $attributes); |
|
113 | + } elseif ( is_string( $attributes ) ) { |
|
114 | + return array_get( $rawData, $attributes ); |
|
115 | 115 | } |
116 | 116 | |
117 | - $data = []; |
|
117 | + $data = [ ]; |
|
118 | 118 | |
119 | - foreach ($attributes as $attribute) { |
|
120 | - $data[] = array_get($rawData, $attribute); |
|
119 | + foreach ( $attributes as $attribute ) { |
|
120 | + $data[ ] = array_get( $rawData, $attribute ); |
|
121 | 121 | } |
122 | 122 | |
123 | 123 | return $data; |
@@ -130,25 +130,25 @@ discard block |
||
130 | 130 | * @param int|null $status |
131 | 131 | * @return $this |
132 | 132 | */ |
133 | - protected function seeError(string $error, int $status = null) |
|
133 | + protected function seeError( string $error, int $status = null ) |
|
134 | 134 | { |
135 | - if (! is_null($status)) { |
|
136 | - $this->seeStatusCode($status); |
|
135 | + if ( ! is_null( $status ) ) { |
|
136 | + $this->seeStatusCode( $status ); |
|
137 | 137 | } |
138 | 138 | |
139 | - if ($this->app->config->get('responder.status_code')) { |
|
140 | - $this->seeJson([ |
|
139 | + if ( $this->app->config->get( 'responder.status_code' ) ) { |
|
140 | + $this->seeJson( [ |
|
141 | 141 | 'status' => $status |
142 | - ]); |
|
142 | + ] ); |
|
143 | 143 | } |
144 | 144 | |
145 | - return $this->seeJson([ |
|
145 | + return $this->seeJson( [ |
|
146 | 146 | 'success' => false |
147 | - ])->seeJsonSubset([ |
|
147 | + ] )->seeJsonSubset( [ |
|
148 | 148 | 'error' => [ |
149 | 149 | 'code' => $error |
150 | 150 | ] |
151 | - ]); |
|
151 | + ] ); |
|
152 | 152 | } |
153 | 153 | |
154 | 154 | /** |
@@ -157,7 +157,7 @@ discard block |
||
157 | 157 | * @param int $status |
158 | 158 | * @return $this |
159 | 159 | */ |
160 | - abstract protected function seeStatusCode($status); |
|
160 | + abstract protected function seeStatusCode( $status ); |
|
161 | 161 | |
162 | 162 | /** |
163 | 163 | * Assert that the response contains JSON. |
@@ -166,7 +166,7 @@ discard block |
||
166 | 166 | * @param bool $negate |
167 | 167 | * @return $this |
168 | 168 | */ |
169 | - abstract public function seeJson(array $data = null, $negate = false); |
|
169 | + abstract public function seeJson( array $data = null, $negate = false ); |
|
170 | 170 | |
171 | 171 | /** |
172 | 172 | * Assert that the JSON response has a given structure. |
@@ -175,7 +175,7 @@ discard block |
||
175 | 175 | * @param array|null $responseData |
176 | 176 | * @return $this |
177 | 177 | */ |
178 | - abstract public function seeJsonStructure(array $structure = null, $responseData = null); |
|
178 | + abstract public function seeJsonStructure( array $structure = null, $responseData = null ); |
|
179 | 179 | |
180 | 180 | /** |
181 | 181 | * Assert that the response is a superset of the given JSON. |
@@ -183,7 +183,7 @@ discard block |
||
183 | 183 | * @param array $data |
184 | 184 | * @return $this |
185 | 185 | */ |
186 | - abstract protected function seeJsonSubset(array $data); |
|
186 | + abstract protected function seeJsonSubset( array $data ); |
|
187 | 187 | |
188 | 188 | /** |
189 | 189 | * Assert that the response contains an exact JSON array. |
@@ -191,7 +191,7 @@ discard block |
||
191 | 191 | * @param array $data |
192 | 192 | * @return $this |
193 | 193 | */ |
194 | - abstract public function seeJsonEquals(array $data); |
|
194 | + abstract public function seeJsonEquals( array $data ); |
|
195 | 195 | |
196 | 196 | /** |
197 | 197 | * Validate and return the decoded response JSON. |
@@ -59,7 +59,7 @@ discard block |
||
59 | 59 | * |
60 | 60 | * @param \Illuminate\Contracts\Routing\ResponseFactory|\Laravel\Lumen\Http\ResponseFactory $responseFactory |
61 | 61 | */ |
62 | - public function __construct($responseFactory) |
|
62 | + public function __construct( $responseFactory ) |
|
63 | 63 | { |
64 | 64 | $this->responseFactory = $responseFactory; |
65 | 65 | } |
@@ -71,17 +71,17 @@ discard block |
||
71 | 71 | * @param array $headers |
72 | 72 | * @return \Illuminate\Http\JsonResponse |
73 | 73 | */ |
74 | - public function respond(int $statusCode = null, array $headers = []):JsonResponse |
|
74 | + public function respond( int $statusCode = null, array $headers = [ ] ):JsonResponse |
|
75 | 75 | { |
76 | - if (! is_null($statusCode)) { |
|
77 | - $this->setStatus($statusCode); |
|
76 | + if ( ! is_null( $statusCode ) ) { |
|
77 | + $this->setStatus( $statusCode ); |
|
78 | 78 | } |
79 | 79 | |
80 | 80 | $data = $this->toArray(); |
81 | - $data = $this->includeStatusCode($data); |
|
82 | - $data = $this->includeSuccessFlag($data); |
|
81 | + $data = $this->includeStatusCode( $data ); |
|
82 | + $data = $this->includeSuccessFlag( $data ); |
|
83 | 83 | |
84 | - return $this->responseFactory->json($data, $this->statusCode, $headers); |
|
84 | + return $this->responseFactory->json( $data, $this->statusCode, $headers ); |
|
85 | 85 | } |
86 | 86 | |
87 | 87 | /** |
@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | * @param int $statusCode |
91 | 91 | * @return self |
92 | 92 | */ |
93 | - public function setStatus(int $statusCode):ResponseBuilder |
|
93 | + public function setStatus( int $statusCode ):ResponseBuilder |
|
94 | 94 | { |
95 | 95 | $this->statusCode = $statusCode; |
96 | 96 | |
@@ -110,7 +110,7 @@ discard block |
||
110 | 110 | * @param bool $includeSuccessFlag |
111 | 111 | * @return self |
112 | 112 | */ |
113 | - public function setIncludeSuccessFlag(bool $includeSuccessFlag):ResponseBuilder |
|
113 | + public function setIncludeSuccessFlag( bool $includeSuccessFlag ):ResponseBuilder |
|
114 | 114 | { |
115 | 115 | $this->includeSuccessFlag = $includeSuccessFlag; |
116 | 116 | |
@@ -123,7 +123,7 @@ discard block |
||
123 | 123 | * @param bool $includeStatusCode |
124 | 124 | * @return self |
125 | 125 | */ |
126 | - public function setIncludeStatusCode(bool $includeStatusCode):ResponseBuilder |
|
126 | + public function setIncludeStatusCode( bool $includeStatusCode ):ResponseBuilder |
|
127 | 127 | { |
128 | 128 | $this->includeStatusCode = $includeStatusCode; |
129 | 129 | |
@@ -137,7 +137,7 @@ discard block |
||
137 | 137 | */ |
138 | 138 | public function toCollection():Collection |
139 | 139 | { |
140 | - return new Collection($this->toArray()); |
|
140 | + return new Collection( $this->toArray() ); |
|
141 | 141 | } |
142 | 142 | |
143 | 143 | /** |
@@ -146,9 +146,9 @@ discard block |
||
146 | 146 | * @param int $options |
147 | 147 | * @return string |
148 | 148 | */ |
149 | - public function toJson($options = 0) |
|
149 | + public function toJson( $options = 0 ) |
|
150 | 150 | { |
151 | - return json_encode($this->jsonSerialize(), $options); |
|
151 | + return json_encode( $this->jsonSerialize(), $options ); |
|
152 | 152 | } |
153 | 153 | |
154 | 154 | /** |
@@ -174,13 +174,13 @@ discard block |
||
174 | 174 | * @param array $data |
175 | 175 | * @return array |
176 | 176 | */ |
177 | - protected function includeSuccessFlag(array $data):array |
|
177 | + protected function includeSuccessFlag( array $data ):array |
|
178 | 178 | { |
179 | - if (! $this->includeSuccessFlag) { |
|
179 | + if ( ! $this->includeSuccessFlag ) { |
|
180 | 180 | return $data; |
181 | 181 | } |
182 | 182 | |
183 | - return array_merge(['success' => $this->isSuccessResponse()], $data); |
|
183 | + return array_merge( [ 'success' => $this->isSuccessResponse() ], $data ); |
|
184 | 184 | } |
185 | 185 | |
186 | 186 | /** |
@@ -189,12 +189,12 @@ discard block |
||
189 | 189 | * @param array $data |
190 | 190 | * @return array |
191 | 191 | */ |
192 | - protected function includeStatusCode(array $data):array |
|
192 | + protected function includeStatusCode( array $data ):array |
|
193 | 193 | { |
194 | - if (! $this->includeStatusCode) { |
|
194 | + if ( ! $this->includeStatusCode ) { |
|
195 | 195 | return $data; |
196 | 196 | } |
197 | 197 | |
198 | - return array_merge(['status' => $this->statusCode], $data); |
|
198 | + return array_merge( [ 'status' => $this->statusCode ], $data ); |
|
199 | 199 | } |
200 | 200 | } |
201 | 201 | \ No newline at end of file |