Completed
Pull Request — master (#30)
by Brian
06:45
created
src/Exceptions/InvalidTransformerException.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -19,8 +19,8 @@
 block discarded – undo
19 19
      *
20 20
      * @param Model $model
21 21
      */
22
-    public function __construct(Model $model)
22
+    public function __construct( Model $model )
23 23
     {
24
-        parent::__construct('The given transformer does not exist for model [' . get_class($model) . '].');
24
+        parent::__construct( 'The given transformer does not exist for model [' . get_class( $model ) . '].' );
25 25
     }
26 26
 }
27 27
\ No newline at end of file
Please login to merge, or discard this patch.
src/Exceptions/Handler.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -18,14 +18,14 @@
 block discarded – undo
18 18
      * @param  Exception                $exception
19 19
      * @return \Illuminate\Http\Response|\Illuminate\Http\JsonResponse
20 20
      */
21
-    public function render($request, Exception $exception)
21
+    public function render( $request, Exception $exception )
22 22
     {
23
-        $this->transformException($exception);
23
+        $this->transformException( $exception );
24 24
 
25
-        if ($exception instanceof ApiException) {
26
-            return $this->renderApiError($exception);
25
+        if ( $exception instanceof ApiException ) {
26
+            return $this->renderApiError( $exception );
27 27
         }
28 28
 
29
-        return parent::render($request, $exception);
29
+        return parent::render( $request, $exception );
30 30
     }
31 31
 }
32 32
\ No newline at end of file
Please login to merge, or discard this patch.
src/Traits/RespondsWithJson.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -24,9 +24,9 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
Please login to merge, or discard this patch.
src/Http/SuccessResponseBuilder.php 3 patches
Unused Use Statements   -2 removed lines patch added patch discarded remove patch
@@ -6,8 +6,6 @@
 block discarded – undo
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\Contracts\Routing\ResponseFactory;
13 11
 use Illuminate\Database\Eloquent\Model;
Please login to merge, or discard this patch.
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -70,7 +70,7 @@
 block discarded – undo
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
      */
Please login to merge, or discard this patch.
Spacing   +68 added lines, -68 removed lines patch added patch discarded remove patch
@@ -37,14 +37,14 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
src/Http/ErrorResponseBuilder.php 2 patches
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -20,7 +20,7 @@  discard block
 block discarded – undo
20 20
      *
21 21
      * @var array
22 22
      */
23
-    protected $data = [];
23
+    protected $data = [ ];
24 24
 
25 25
     /**
26 26
      * The error code used to identify the error.
@@ -41,7 +41,7 @@  discard block
 block discarded – undo
41 41
      *
42 42
      * @var array
43 43
      */
44
-    protected $parameters = [];
44
+    protected $parameters = [ ];
45 45
 
46 46
     /**
47 47
      * The HTTP status code for the response.
@@ -63,11 +63,11 @@  discard block
 block discarded – undo
63 63
      * @param \Illuminate\Contracts\Routing\ResponseFactory|\Laravel\Lumen\Http\ResponseFactory $responseFactory
64 64
      * @param \Symfony\Component\Translation\TranslatorInterface                                $translator
65 65
      */
66
-    public function __construct($responseFactory, TranslatorInterface $translator)
66
+    public function __construct( $responseFactory, TranslatorInterface $translator )
67 67
     {
68 68
         $this->translator = $translator;
69 69
 
70
-        parent::__construct($responseFactory);
70
+        parent::__construct( $responseFactory );
71 71
     }
72 72
 
73 73
     /**
@@ -76,9 +76,9 @@  discard block
 block discarded – undo
76 76
      * @param  array $data
77 77
      * @return self
78 78
      */
79
-    public function addData(array $data):ErrorResponseBuilder
79
+    public function addData( array $data ):ErrorResponseBuilder
80 80
     {
81
-        $this->data = array_merge($this->data, $data);
81
+        $this->data = array_merge( $this->data, $data );
82 82
 
83 83
         return $this;
84 84
     }
@@ -90,11 +90,11 @@  discard block
 block discarded – undo
90 90
      * @param  string|array|null $message
91 91
      * @return self
92 92
      */
93
-    public function setError(string $errorCode = null, $message = null):ErrorResponseBuilder
93
+    public function setError( string $errorCode = null, $message = null ):ErrorResponseBuilder
94 94
     {
95 95
         $this->errorCode = $errorCode;
96 96
 
97
-        if (is_array($message)) {
97
+        if ( is_array( $message ) ) {
98 98
             $this->parameters = $message;
99 99
         } else {
100 100
             $this->message = $message;
@@ -110,13 +110,13 @@  discard block
 block discarded – undo
110 110
      * @return self
111 111
      * @throws \InvalidArgumentException
112 112
      */
113
-    public function setStatus(int $statusCode):ResponseBuilder
113
+    public function setStatus( int $statusCode ):ResponseBuilder
114 114
     {
115
-        if ($statusCode < 400 || $statusCode >= 600) {
116
-            throw new InvalidArgumentException("{$statusCode} is not a valid error HTTP status code.");
115
+        if ( $statusCode < 400 || $statusCode >= 600 ) {
116
+            throw new InvalidArgumentException( "{$statusCode} is not a valid error HTTP status code." );
117 117
         }
118 118
 
119
-        return parent::setStatus($statusCode);
119
+        return parent::setStatus( $statusCode );
120 120
     }
121 121
 
122 122
     /**
@@ -139,7 +139,7 @@  discard block
 block discarded – undo
139 139
      */
140 140
     protected function buildErrorData()
141 141
     {
142
-        if (is_null($this->errorCode)) {
142
+        if ( is_null( $this->errorCode ) ) {
143 143
             return null;
144 144
         }
145 145
 
@@ -148,7 +148,7 @@  discard block
 block discarded – undo
148 148
             'message' => $this->message ?: $this->resolveMessage()
149 149
         ];
150 150
 
151
-        return array_merge($data, $this->data);
151
+        return array_merge( $data, $this->data );
152 152
     }
153 153
 
154 154
     /**
@@ -158,10 +158,10 @@  discard block
 block discarded – undo
158 158
      */
159 159
     protected function resolveMessage()
160 160
     {
161
-        if (! $this->translator->has($code = "errors.$this->errorCode")) {
161
+        if ( ! $this->translator->has( $code = "errors.$this->errorCode" ) ) {
162 162
             return null;
163 163
         }
164 164
 
165
-        return $this->translator->trans($code, $this->parameters);
165
+        return $this->translator->trans( $code, $this->parameters );
166 166
     }
167 167
 }
168 168
\ No newline at end of file
Please login to merge, or discard this patch.
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -70,7 +70,7 @@
 block discarded – undo
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
      */
Please login to merge, or discard this patch.
src/Http/ResponseBuilder.php 1 patch
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -44,7 +44,7 @@  discard block
 block discarded – undo
44 44
      *
45 45
      * @param \Illuminate\Contracts\Routing\ResponseFactory|\Laravel\Lumen\Http\ResponseFactory $responseFactory
46 46
      */
47
-    public function __construct($responseFactory)
47
+    public function __construct( $responseFactory )
48 48
     {
49 49
         $this->responseFactory = $responseFactory;
50 50
     }
@@ -56,15 +56,15 @@  discard block
 block discarded – undo
56 56
      * @param  array    $headers
57 57
      * @return \Illuminate\Http\JsonResponse
58 58
      */
59
-    public function respond(int $statusCode = null, array $headers = []):JsonResponse
59
+    public function respond( int $statusCode = null, array $headers = [ ] ):JsonResponse
60 60
     {
61
-        if (! is_null($statusCode)) {
62
-            $this->setStatus($statusCode);
61
+        if ( ! is_null( $statusCode ) ) {
62
+            $this->setStatus( $statusCode );
63 63
         }
64 64
 
65
-        $data = $this->includeStatusCode($this->toArray());
65
+        $data = $this->includeStatusCode( $this->toArray() );
66 66
 
67
-        return $this->responseFactory->json($data, $this->statusCode, $headers);
67
+        return $this->responseFactory->json( $data, $this->statusCode, $headers );
68 68
     }
69 69
 
70 70
     /**
@@ -73,7 +73,7 @@  discard block
 block discarded – undo
73 73
      * @param  int $statusCode
74 74
      * @return self
75 75
      */
76
-    public function setStatus(int $statusCode):ResponseBuilder
76
+    public function setStatus( int $statusCode ):ResponseBuilder
77 77
     {
78 78
         $this->statusCode = $statusCode;
79 79
 
@@ -86,7 +86,7 @@  discard block
 block discarded – undo
86 86
      * @param  bool $includeStatusCode
87 87
      * @return self
88 88
      */
89
-    public function setIncludeStatusCode(bool $includeStatusCode):ResponseBuilder
89
+    public function setIncludeStatusCode( bool $includeStatusCode ):ResponseBuilder
90 90
     {
91 91
         $this->includeStatusCode = $includeStatusCode;
92 92
 
@@ -100,7 +100,7 @@  discard block
 block discarded – undo
100 100
      */
101 101
     public function toCollection():Collection
102 102
     {
103
-        return new Collection($this->toArray());
103
+        return new Collection( $this->toArray() );
104 104
     }
105 105
 
106 106
     /**
@@ -109,9 +109,9 @@  discard block
 block discarded – undo
109 109
      * @param  int $options
110 110
      * @return string
111 111
      */
112
-    public function toJson($options = 0)
112
+    public function toJson( $options = 0 )
113 113
     {
114
-        return json_encode($this->jsonSerialize(), $options);
114
+        return json_encode( $this->jsonSerialize(), $options );
115 115
     }
116 116
 
117 117
     /**
@@ -137,12 +137,12 @@  discard block
 block discarded – undo
137 137
      * @param  array $data
138 138
      * @return array
139 139
      */
140
-    protected function includeStatusCode(array $data):array
140
+    protected function includeStatusCode( array $data ):array
141 141
     {
142
-        if (! $this->includeStatusCode) {
142
+        if ( ! $this->includeStatusCode ) {
143 143
             return $data;
144 144
         }
145 145
 
146
-        return array_merge(['status' => $this->statusCode], $data);
146
+        return array_merge( [ 'status' => $this->statusCode ], $data );
147 147
     }
148 148
 }
149 149
\ No newline at end of file
Please login to merge, or discard this patch.
src/Traits/HandlesApiErrors.php 1 patch
Spacing   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -32,12 +32,12 @@  discard block
 block discarded – undo
32 32
      * @param  Exception $exception
33 33
      * @return void
34 34
      */
35
-    protected function transformException(Exception $exception)
35
+    protected function transformException( Exception $exception )
36 36
     {
37
-        if (Request::capture()->wantsJson()) {
38
-            $this->transformAuthException($exception);
39
-            $this->transformEloquentException($exception);
40
-            $this->transformValidationException($exception);
37
+        if ( Request::capture()->wantsJson() ) {
38
+            $this->transformAuthException( $exception );
39
+            $this->transformEloquentException( $exception );
40
+            $this->transformValidationException( $exception );
41 41
         }
42 42
     }
43 43
 
@@ -49,13 +49,13 @@  discard block
 block discarded – undo
49 49
      * @throws UnauthenticatedException
50 50
      * @throws UnauthorizedException
51 51
      */
52
-    protected function transformAuthException(Exception $exception)
52
+    protected function transformAuthException( Exception $exception )
53 53
     {
54
-        if ($exception instanceof AuthenticationException) {
54
+        if ( $exception instanceof AuthenticationException ) {
55 55
             throw new UnauthenticatedException();
56 56
         }
57 57
 
58
-        if ($exception instanceof AuthorizationException) {
58
+        if ( $exception instanceof AuthorizationException ) {
59 59
             throw new UnauthorizedException();
60 60
         }
61 61
     }
@@ -68,13 +68,13 @@  discard block
 block discarded – undo
68 68
      * @throws ResourceNotFoundException
69 69
      * @throws RelationNotFoundException
70 70
      */
71
-    protected function transformEloquentException(Exception $exception)
71
+    protected function transformEloquentException( Exception $exception )
72 72
     {
73
-        if ($exception instanceof ModelNotFoundException) {
73
+        if ( $exception instanceof ModelNotFoundException ) {
74 74
             throw new ResourceNotFoundException();
75 75
         }
76 76
 
77
-        if ($exception instanceof RelationNotFoundException) {
77
+        if ( $exception instanceof RelationNotFoundException ) {
78 78
             throw new RelationNotFoundException();
79 79
         }
80 80
     }
@@ -86,10 +86,10 @@  discard block
 block discarded – undo
86 86
      * @return void
87 87
      * @throws ValidationFailedException
88 88
      */
89
-    protected function transformValidationException(Exception $exception)
89
+    protected function transformValidationException( Exception $exception )
90 90
     {
91
-        if ($exception instanceof ValidationException) {
92
-            throw new ValidationFailedException($exception->validator);
91
+        if ( $exception instanceof ValidationException ) {
92
+            throw new ValidationFailedException( $exception->validator );
93 93
         }
94 94
     }
95 95
 
@@ -99,11 +99,11 @@  discard block
 block discarded – undo
99 99
      * @param  ApiException $exception
100 100
      * @return JsonResponse
101 101
      */
102
-    protected function renderApiError(ApiException $exception):JsonResponse
102
+    protected function renderApiError( ApiException $exception ):JsonResponse
103 103
     {
104
-        return app('responder.error')
105
-            ->setError($exception->getErrorCode(), $exception->getMessage())
106
-            ->addData($exception->getData() ?: [])
107
-            ->respond($exception->getStatusCode());
104
+        return app( 'responder.error' )
105
+            ->setError( $exception->getErrorCode(), $exception->getMessage() )
106
+            ->addData( $exception->getData() ?: [ ] )
107
+            ->respond( $exception->getStatusCode() );
108 108
     }
109 109
 }
110 110
\ No newline at end of file
Please login to merge, or discard this patch.
src/Transformer.php 1 patch
Spacing   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -22,7 +22,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
Please login to merge, or discard this patch.
src/Exceptions/Http/ApiException.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -41,9 +41,9 @@
 block discarded – undo
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
     /**
Please login to merge, or discard this patch.