@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | * |
44 | 44 | * @param Filesystem $files |
45 | 45 | */ |
46 | - public function __construct(Filesystem $files) |
|
46 | + public function __construct( Filesystem $files ) |
|
47 | 47 | { |
48 | 48 | parent::__construct(); |
49 | 49 | |
@@ -67,21 +67,21 @@ discard block |
||
67 | 67 | */ |
68 | 68 | protected function generateTransformer() |
69 | 69 | { |
70 | - $name = (string) $this->argument('name'); |
|
70 | + $name = (string) $this->argument( 'name' ); |
|
71 | 71 | $path = $this->laravel->basePath() . '/app/Transformers/' . $name . '.php'; |
72 | 72 | |
73 | - if ($this->files->exists($path)) { |
|
74 | - return $this->error($name . ' already exists!'); |
|
73 | + if ( $this->files->exists( $path ) ) { |
|
74 | + return $this->error( $name . ' already exists!' ); |
|
75 | 75 | } |
76 | 76 | |
77 | - $this->makeDirectory($path); |
|
77 | + $this->makeDirectory( $path ); |
|
78 | 78 | |
79 | - $stubPath = $this->option('pivot') ? 'resources/stubs/transformer.pivot.stub' : 'resources/stubs/transformer.stub'; |
|
80 | - $stub = $this->files->get(__DIR__ . '/../../' . $stubPath); |
|
79 | + $stubPath = $this->option( 'pivot' ) ? 'resources/stubs/transformer.pivot.stub' : 'resources/stubs/transformer.stub'; |
|
80 | + $stub = $this->files->get( __DIR__ . '/../../' . $stubPath ); |
|
81 | 81 | |
82 | - $this->files->put($path, $this->makeTransformer($name, $stub)); |
|
82 | + $this->files->put( $path, $this->makeTransformer( $name, $stub ) ); |
|
83 | 83 | |
84 | - $this->info('Transformer created successfully.'); |
|
84 | + $this->info( 'Transformer created successfully.' ); |
|
85 | 85 | } |
86 | 86 | |
87 | 87 | /** |
@@ -90,10 +90,10 @@ discard block |
||
90 | 90 | * @param string $path |
91 | 91 | * @return void |
92 | 92 | */ |
93 | - protected function makeDirectory(string $path) |
|
93 | + protected function makeDirectory( string $path ) |
|
94 | 94 | { |
95 | - if (! $this->files->isDirectory(dirname($path))) { |
|
96 | - $this->files->makeDirectory(dirname($path), 0777, true, true); |
|
95 | + if ( ! $this->files->isDirectory( dirname( $path ) ) ) { |
|
96 | + $this->files->makeDirectory( dirname( $path ), 0777, true, true ); |
|
97 | 97 | } |
98 | 98 | } |
99 | 99 | |
@@ -104,11 +104,11 @@ discard block |
||
104 | 104 | * @param string $stub |
105 | 105 | * @return string |
106 | 106 | */ |
107 | - protected function makeTransformer(string $name, string $stub):string |
|
107 | + protected function makeTransformer( string $name, string $stub ):string |
|
108 | 108 | { |
109 | - $stub = $this->replaceNamespace($stub); |
|
110 | - $stub = $this->replaceClass($stub, $name); |
|
111 | - $stub = $this->replaceModel($stub, $name); |
|
109 | + $stub = $this->replaceNamespace( $stub ); |
|
110 | + $stub = $this->replaceClass( $stub, $name ); |
|
111 | + $stub = $this->replaceModel( $stub, $name ); |
|
112 | 112 | |
113 | 113 | return $stub; |
114 | 114 | } |
@@ -119,15 +119,15 @@ discard block |
||
119 | 119 | * @param string $stub |
120 | 120 | * @return string |
121 | 121 | */ |
122 | - protected function replaceNamespace(string $stub):string |
|
122 | + protected function replaceNamespace( string $stub ):string |
|
123 | 123 | { |
124 | - if (method_exists($this->laravel, 'getNameSpace')) { |
|
124 | + if ( method_exists( $this->laravel, 'getNameSpace' ) ) { |
|
125 | 125 | $namespace = $this->laravel->getNamespace() . 'Transformers'; |
126 | 126 | } else { |
127 | 127 | $namespace = 'App\Transformers'; |
128 | 128 | } |
129 | 129 | |
130 | - $stub = str_replace('DummyNamespace', $namespace, $stub); |
|
130 | + $stub = str_replace( 'DummyNamespace', $namespace, $stub ); |
|
131 | 131 | |
132 | 132 | return $stub; |
133 | 133 | } |
@@ -139,9 +139,9 @@ discard block |
||
139 | 139 | * @param string $name |
140 | 140 | * @return string |
141 | 141 | */ |
142 | - protected function replaceClass(string $stub, string $name):string |
|
142 | + protected function replaceClass( string $stub, string $name ):string |
|
143 | 143 | { |
144 | - $stub = str_replace('DummyClass', $name, $stub); |
|
144 | + $stub = str_replace( 'DummyClass', $name, $stub ); |
|
145 | 145 | |
146 | 146 | return $stub; |
147 | 147 | } |
@@ -153,14 +153,14 @@ discard block |
||
153 | 153 | * @param string $name |
154 | 154 | * @return string |
155 | 155 | */ |
156 | - protected function replaceModel(string $stub, string $name):string |
|
156 | + protected function replaceModel( string $stub, string $name ):string |
|
157 | 157 | { |
158 | - $model = $this->getModelNamespace($name); |
|
159 | - $class = $this->getClassFromNamespace($model); |
|
158 | + $model = $this->getModelNamespace( $name ); |
|
159 | + $class = $this->getClassFromNamespace( $model ); |
|
160 | 160 | |
161 | - $stub = str_replace('DummyModelNamespace', $model, $stub); |
|
162 | - $stub = str_replace('DummyModelClass', $class, $stub); |
|
163 | - $stub = str_replace('DummyModelVariable', camel_case($class), $stub); |
|
161 | + $stub = str_replace( 'DummyModelNamespace', $model, $stub ); |
|
162 | + $stub = str_replace( 'DummyModelClass', $class, $stub ); |
|
163 | + $stub = str_replace( 'DummyModelVariable', camel_case( $class ), $stub ); |
|
164 | 164 | |
165 | 165 | return $stub; |
166 | 166 | } |
@@ -171,13 +171,13 @@ discard block |
||
171 | 171 | * @param string $name |
172 | 172 | * @return string |
173 | 173 | */ |
174 | - protected function getModelNamespace(string $name):string |
|
174 | + protected function getModelNamespace( string $name ):string |
|
175 | 175 | { |
176 | - if ($this->option('model')) { |
|
177 | - return $this->option('model'); |
|
176 | + if ( $this->option( 'model' ) ) { |
|
177 | + return $this->option( 'model' ); |
|
178 | 178 | } |
179 | 179 | |
180 | - return 'App\\' . str_replace('Transformer', '', $name); |
|
180 | + return 'App\\' . str_replace( 'Transformer', '', $name ); |
|
181 | 181 | } |
182 | 182 | |
183 | 183 | /** |
@@ -186,8 +186,8 @@ discard block |
||
186 | 186 | * @param string $namespace |
187 | 187 | * @return string |
188 | 188 | */ |
189 | - protected function getClassFromNamespace(string $namespace):string |
|
189 | + protected function getClassFromNamespace( string $namespace ):string |
|
190 | 190 | { |
191 | - return last(explode('\\', $namespace)); |
|
191 | + return last( explode( '\\', $namespace ) ); |
|
192 | 192 | } |
193 | 193 | } |
194 | 194 | \ No newline at end of file |
@@ -19,6 +19,6 @@ |
||
19 | 19 | */ |
20 | 20 | public function __construct() |
21 | 21 | { |
22 | - parent::__construct('Given serializer is not an instance of [' . SerializerAbstract::class . '].'); |
|
22 | + parent::__construct( 'Given serializer is not an instance of [' . SerializerAbstract::class . '].' ); |
|
23 | 23 | } |
24 | 24 | } |
25 | 25 | \ No newline at end of file |
@@ -19,8 +19,8 @@ |
||
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 |
@@ -18,14 +18,14 @@ |
||
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 |
@@ -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 |
@@ -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\Contracts\Routing\ResponseFactory; |
13 | 11 | use Illuminate\Database\Eloquent\Model; |
@@ -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,7 +104,7 @@ discard block |
||
104 | 104 | */ |
105 | 105 | public function include($relations):SuccessResponseBuilder |
106 | 106 | { |
107 | - $this->relations = array_merge($this->relations, (array) $relations); |
|
107 | + $this->relations = array_merge( $this->relations, (array) $relations ); |
|
108 | 108 | |
109 | 109 | return $this; |
110 | 110 | } |
@@ -115,9 +115,9 @@ discard block |
||
115 | 115 | * @param \League\Fractal\Serializer\SerializerAbstract|string $serializer |
116 | 116 | * @return self |
117 | 117 | */ |
118 | - public function serializer($serializer):SuccessResponseBuilder |
|
118 | + public function serializer( $serializer ):SuccessResponseBuilder |
|
119 | 119 | { |
120 | - $this->manager->setSerializer($this->resolveSerializer($serializer)); |
|
120 | + $this->manager->setSerializer( $this->resolveSerializer( $serializer ) ); |
|
121 | 121 | |
122 | 122 | return $this; |
123 | 123 | } |
@@ -129,13 +129,13 @@ discard block |
||
129 | 129 | * @return self |
130 | 130 | * @throws \InvalidArgumentException |
131 | 131 | */ |
132 | - public function setStatus(int $statusCode):ResponseBuilder |
|
132 | + public function setStatus( int $statusCode ):ResponseBuilder |
|
133 | 133 | { |
134 | - if ($statusCode < 100 || $statusCode >= 400) { |
|
135 | - throw new InvalidArgumentException("{$statusCode} is not a valid success HTTP status code."); |
|
134 | + if ( $statusCode < 100 || $statusCode >= 400 ) { |
|
135 | + throw new InvalidArgumentException( "{$statusCode} is not a valid success HTTP status code." ); |
|
136 | 136 | } |
137 | 137 | |
138 | - return parent::setStatus($statusCode); |
|
138 | + return parent::setStatus( $statusCode ); |
|
139 | 139 | } |
140 | 140 | |
141 | 141 | /** |
@@ -147,25 +147,25 @@ discard block |
||
147 | 147 | * @param string|null $resourceKey |
148 | 148 | * @return self |
149 | 149 | */ |
150 | - public function transform($data = null, $transformer = null, string $resourceKey = null):SuccessResponseBuilder |
|
150 | + public function transform( $data = null, $transformer = null, string $resourceKey = null ):SuccessResponseBuilder |
|
151 | 151 | { |
152 | - $resource = $this->resourceFactory->make($data); |
|
152 | + $resource = $this->resourceFactory->make( $data ); |
|
153 | 153 | |
154 | - if (! is_null($resource->getData())) { |
|
155 | - $model = $this->resolveModel($resource->getData()); |
|
156 | - $transformer = $this->resolveTransformer($model, $transformer); |
|
157 | - $resourceKey = $this->resolveResourceKey($model, $resourceKey); |
|
154 | + if ( ! is_null( $resource->getData() ) ) { |
|
155 | + $model = $this->resolveModel( $resource->getData() ); |
|
156 | + $transformer = $this->resolveTransformer( $model, $transformer ); |
|
157 | + $resourceKey = $this->resolveResourceKey( $model, $resourceKey ); |
|
158 | 158 | } |
159 | 159 | |
160 | - if ($transformer instanceof Transformer) { |
|
161 | - $this->include($relations = $this->resolveNestedRelations($resource->getData())); |
|
160 | + if ( $transformer instanceof Transformer ) { |
|
161 | + $this->include( $relations = $this->resolveNestedRelations( $resource->getData() ) ); |
|
162 | 162 | |
163 | - if ($transformer->allRelationsAllowed()) { |
|
164 | - $transformer->setRelations($relations); |
|
163 | + if ( $transformer->allRelationsAllowed() ) { |
|
164 | + $transformer->setRelations( $relations ); |
|
165 | 165 | } |
166 | 166 | } |
167 | 167 | |
168 | - $this->resource = $resource->setTransformer($transformer)->setResourceKey($resourceKey); |
|
168 | + $this->resource = $resource->setTransformer( $transformer )->setResourceKey( $resourceKey ); |
|
169 | 169 | |
170 | 170 | return $this; |
171 | 171 | } |
@@ -177,7 +177,7 @@ discard block |
||
177 | 177 | */ |
178 | 178 | public function toArray():array |
179 | 179 | { |
180 | - return $this->serialize($this->getResource()); |
|
180 | + return $this->serialize( $this->getResource() ); |
|
181 | 181 | } |
182 | 182 | |
183 | 183 | /** |
@@ -187,14 +187,14 @@ discard block |
||
187 | 187 | */ |
188 | 188 | public function getResource():ResourceInterface |
189 | 189 | { |
190 | - $this->manager->parseIncludes($this->relations); |
|
190 | + $this->manager->parseIncludes( $this->relations ); |
|
191 | 191 | $transformer = $this->resource->getTransformer(); |
192 | 192 | |
193 | - if ($transformer instanceof Transformer && $transformer->allRelationsAllowed()) { |
|
194 | - $this->resource->setTransformer($transformer->setRelations($this->manager->getRequestedIncludes())); |
|
193 | + if ( $transformer instanceof Transformer && $transformer->allRelationsAllowed() ) { |
|
194 | + $this->resource->setTransformer( $transformer->setRelations( $this->manager->getRequestedIncludes() ) ); |
|
195 | 195 | } |
196 | 196 | |
197 | - return $this->resource->setMeta($this->meta); |
|
197 | + return $this->resource->setMeta( $this->meta ); |
|
198 | 198 | } |
199 | 199 | |
200 | 200 | /** |
@@ -214,13 +214,13 @@ discard block |
||
214 | 214 | * @return \League\Fractal\Serializer\SerializerAbstract |
215 | 215 | * @throws \Flugg\Responder\Exceptions\InvalidSerializerException |
216 | 216 | */ |
217 | - protected function resolveSerializer($serializer):SerializerAbstract |
|
217 | + protected function resolveSerializer( $serializer ):SerializerAbstract |
|
218 | 218 | { |
219 | - if (is_string($serializer)) { |
|
219 | + if ( is_string( $serializer ) ) { |
|
220 | 220 | $serializer = new $serializer; |
221 | 221 | } |
222 | 222 | |
223 | - if (! $serializer instanceof SerializerAbstract) { |
|
223 | + if ( ! $serializer instanceof SerializerAbstract ) { |
|
224 | 224 | throw new InvalidSerializerException(); |
225 | 225 | } |
226 | 226 | |
@@ -234,15 +234,15 @@ discard block |
||
234 | 234 | * @return \Illuminate\Database\Eloquent\Model |
235 | 235 | * @throws \InvalidArgumentException |
236 | 236 | */ |
237 | - protected function resolveModel($data):Model |
|
237 | + protected function resolveModel( $data ):Model |
|
238 | 238 | { |
239 | - if ($data instanceof Model) { |
|
239 | + if ( $data instanceof Model ) { |
|
240 | 240 | return $data; |
241 | 241 | } |
242 | 242 | |
243 | - $model = array_values($data)[0]; |
|
244 | - if (! $model instanceof Model) { |
|
245 | - throw new InvalidArgumentException('You can only transform data containing Eloquent models.'); |
|
243 | + $model = array_values( $data )[ 0 ]; |
|
244 | + if ( ! $model instanceof Model ) { |
|
245 | + throw new InvalidArgumentException( 'You can only transform data containing Eloquent models.' ); |
|
246 | 246 | } |
247 | 247 | |
248 | 248 | return $model; |
@@ -255,15 +255,15 @@ discard block |
||
255 | 255 | * @param \Flugg\Responder\Transformer|callable|null $transformer |
256 | 256 | * @return \Flugg\Responder\Transformer|callable |
257 | 257 | */ |
258 | - protected function resolveTransformer(Model $model, $transformer = null) |
|
258 | + protected function resolveTransformer( Model $model, $transformer = null ) |
|
259 | 259 | { |
260 | - $transformer = $transformer ?: $this->resolveTransformerFromModel($model); |
|
260 | + $transformer = $transformer ?: $this->resolveTransformerFromModel( $model ); |
|
261 | 261 | |
262 | - if (is_string($transformer)) { |
|
262 | + if ( is_string( $transformer ) ) { |
|
263 | 263 | $transformer = new $transformer; |
264 | 264 | } |
265 | 265 | |
266 | - return $this->parseTransformer($transformer, $model); |
|
266 | + return $this->parseTransformer( $transformer, $model ); |
|
267 | 267 | } |
268 | 268 | |
269 | 269 | /** |
@@ -273,10 +273,10 @@ discard block |
||
273 | 273 | * @param \Illuminate\Database\ELoquent\Model $model |
274 | 274 | * @return \Flugg\Responder\Transformer|callable |
275 | 275 | */ |
276 | - protected function resolveTransformerFromModel(Model $model) |
|
276 | + protected function resolveTransformerFromModel( Model $model ) |
|
277 | 277 | { |
278 | - if (! $model instanceof Transformable) { |
|
279 | - return function ($model) { |
|
278 | + if ( ! $model instanceof Transformable ) { |
|
279 | + return function ( $model ) { |
|
280 | 280 | return $model->toArray(); |
281 | 281 | }; |
282 | 282 | } |
@@ -292,14 +292,14 @@ discard block |
||
292 | 292 | * @return \Flugg\Responder\Transformer|callable |
293 | 293 | * @throws \InvalidTransformerException |
294 | 294 | */ |
295 | - protected function parseTransformer($transformer, Model $model) |
|
295 | + protected function parseTransformer( $transformer, Model $model ) |
|
296 | 296 | { |
297 | - if ($transformer instanceof Transformer) { |
|
298 | - $relations = $transformer->allRelationsAllowed() ? $this->resolveRelations($model) : $transformer->getRelations(); |
|
299 | - $transformer = $transformer->setRelations($relations); |
|
297 | + if ( $transformer instanceof Transformer ) { |
|
298 | + $relations = $transformer->allRelationsAllowed() ? $this->resolveRelations( $model ) : $transformer->getRelations(); |
|
299 | + $transformer = $transformer->setRelations( $relations ); |
|
300 | 300 | |
301 | - } elseif (! is_callable($transformer)) { |
|
302 | - throw new InvalidTransformerException($model); |
|
301 | + } elseif ( ! is_callable( $transformer ) ) { |
|
302 | + throw new InvalidTransformerException( $model ); |
|
303 | 303 | } |
304 | 304 | |
305 | 305 | return $transformer; |
@@ -311,9 +311,9 @@ discard block |
||
311 | 311 | * @param \Illuminate\Database\Eloquent\Model $model |
312 | 312 | * @return array |
313 | 313 | */ |
314 | - protected function resolveRelations(Model $model):array |
|
314 | + protected function resolveRelations( Model $model ):array |
|
315 | 315 | { |
316 | - return array_keys($model->getRelations()); |
|
316 | + return array_keys( $model->getRelations() ); |
|
317 | 317 | } |
318 | 318 | |
319 | 319 | /** |
@@ -322,22 +322,22 @@ discard block |
||
322 | 322 | * @param \Illuminate\Support\Collection|\Illuminate\Database\Eloquent\Model $data |
323 | 323 | * @return array |
324 | 324 | */ |
325 | - protected function resolveNestedRelations($data):array |
|
325 | + protected function resolveNestedRelations( $data ):array |
|
326 | 326 | { |
327 | - if (is_null($data)) { |
|
328 | - return []; |
|
327 | + if ( is_null( $data ) ) { |
|
328 | + return [ ]; |
|
329 | 329 | } |
330 | 330 | |
331 | - $data = $data instanceof Model ? [$data] : $data; |
|
331 | + $data = $data instanceof Model ? [ $data ] : $data; |
|
332 | 332 | |
333 | - return collect($data)->flatMap(function ($model) { |
|
334 | - $relations = collect($model->getRelations()); |
|
333 | + return collect( $data )->flatMap( function ( $model ) { |
|
334 | + $relations = collect( $model->getRelations() ); |
|
335 | 335 | |
336 | - return $relations->keys()->merge($relations->flatMap(function ($relation, $key) { |
|
337 | - return collect($this->resolveNestedRelations($relation))->map(function ($nestedRelation) use ($key) { |
|
336 | + return $relations->keys()->merge( $relations->flatMap( function ( $relation, $key ) { |
|
337 | + return collect( $this->resolveNestedRelations( $relation ) )->map( function ( $nestedRelation ) use ($key) { |
|
338 | 338 | return $key . '.' . $nestedRelation; |
339 | 339 | }); |
340 | - })); |
|
340 | + }) ); |
|
341 | 341 | })->toArray(); |
342 | 342 | } |
343 | 343 | |
@@ -348,13 +348,13 @@ discard block |
||
348 | 348 | * @param string|null $resourceKey |
349 | 349 | * @return string |
350 | 350 | */ |
351 | - protected function resolveResourceKey(Model $model, string $resourceKey = null):string |
|
351 | + protected function resolveResourceKey( Model $model, string $resourceKey = null ):string |
|
352 | 352 | { |
353 | - if (! is_null($resourceKey)) { |
|
353 | + if ( ! is_null( $resourceKey ) ) { |
|
354 | 354 | return $resourceKey; |
355 | 355 | } |
356 | 356 | |
357 | - if (method_exists($model, 'getResourceKey')) { |
|
357 | + if ( method_exists( $model, 'getResourceKey' ) ) { |
|
358 | 358 | return $model->getResourceKey(); |
359 | 359 | } |
360 | 360 | |
@@ -367,8 +367,8 @@ discard block |
||
367 | 367 | * @param ResourceInterface $resource |
368 | 368 | * @return array |
369 | 369 | */ |
370 | - protected function serialize(ResourceInterface $resource):array |
|
370 | + protected function serialize( ResourceInterface $resource ):array |
|
371 | 371 | { |
372 | - return $this->manager->createData($resource)->toArray(); |
|
372 | + return $this->manager->createData( $resource )->toArray(); |
|
373 | 373 | } |
374 | 374 | } |
375 | 375 | \ No newline at end of file |
@@ -20,7 +20,7 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
@@ -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 | */ |
@@ -44,7 +44,7 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
@@ -32,12 +32,12 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |