@@ -158,7 +158,7 @@ discard block |
||
| 158 | 158 | /** |
| 159 | 159 | * Include relations to the transform. |
| 160 | 160 | * |
| 161 | - * @param string[]|string $relations |
|
| 161 | + * @param string[] $relations |
|
| 162 | 162 | * @return self |
| 163 | 163 | */ |
| 164 | 164 | public function with($relations): TransformBuilder |
@@ -171,7 +171,7 @@ discard block |
||
| 171 | 171 | /** |
| 172 | 172 | * Exclude relations from the transform. |
| 173 | 173 | * |
| 174 | - * @param string[]|string $relations |
|
| 174 | + * @param string[] $relations |
|
| 175 | 175 | * @return self |
| 176 | 176 | */ |
| 177 | 177 | public function without($relations): TransformBuilder |
@@ -197,7 +197,7 @@ discard block |
||
| 197 | 197 | /** |
| 198 | 198 | * Set the serializer. |
| 199 | 199 | * |
| 200 | - * @param \League\Fractal\Serializer\SerializerAbstract|string $serializer |
|
| 200 | + * @param Serializers\NullSerializer $serializer |
|
| 201 | 201 | * @return self |
| 202 | 202 | * @throws \Flugg\Responder\Exceptions\InvalidSerializerException |
| 203 | 203 | */ |
@@ -64,21 +64,21 @@ discard block |
||
| 64 | 64 | * |
| 65 | 65 | * @var array |
| 66 | 66 | */ |
| 67 | - protected $with = []; |
|
| 67 | + protected $with = [ ]; |
|
| 68 | 68 | |
| 69 | 69 | /** |
| 70 | 70 | * A list of excluded relations. |
| 71 | 71 | * |
| 72 | 72 | * @var array |
| 73 | 73 | */ |
| 74 | - protected $without = []; |
|
| 74 | + protected $without = [ ]; |
|
| 75 | 75 | |
| 76 | 76 | /** |
| 77 | 77 | * A list of sparse fieldsets. |
| 78 | 78 | * |
| 79 | 79 | * @var array |
| 80 | 80 | */ |
| 81 | - protected $only = []; |
|
| 81 | + protected $only = [ ]; |
|
| 82 | 82 | |
| 83 | 83 | /** |
| 84 | 84 | * Construct the builder class. |
@@ -87,7 +87,7 @@ discard block |
||
| 87 | 87 | * @param \Flugg\Responder\Contracts\TransformFactory $transformFactory |
| 88 | 88 | * @param \Flugg\Responder\Contracts\Pagination\PaginatorFactory $paginatorFactory |
| 89 | 89 | */ |
| 90 | - public function __construct(ResourceFactory $resourceFactory, TransformFactory $transformFactory, PaginatorFactory $paginatorFactory) |
|
| 90 | + public function __construct( ResourceFactory $resourceFactory, TransformFactory $transformFactory, PaginatorFactory $paginatorFactory ) |
|
| 91 | 91 | { |
| 92 | 92 | $this->resourceFactory = $resourceFactory; |
| 93 | 93 | $this->transformFactory = $transformFactory; |
@@ -103,14 +103,14 @@ discard block |
||
| 103 | 103 | * @param string|null $resourceKey |
| 104 | 104 | * @return self |
| 105 | 105 | */ |
| 106 | - public function resource($data = null, $transformer = null, string $resourceKey = null): TransformBuilder |
|
| 106 | + public function resource( $data = null, $transformer = null, string $resourceKey = null ): TransformBuilder |
|
| 107 | 107 | { |
| 108 | - $this->resource = $this->resourceFactory->make($data, $transformer, $resourceKey); |
|
| 108 | + $this->resource = $this->resourceFactory->make( $data, $transformer, $resourceKey ); |
|
| 109 | 109 | |
| 110 | - if ($data instanceof CursorPaginator) { |
|
| 111 | - $this->cursor($this->paginatorFactory->makeCursor($data)); |
|
| 112 | - } elseif ($data instanceof LengthAwarePaginator) { |
|
| 113 | - $this->paginator($this->paginatorFactory->make($data)); |
|
| 110 | + if ( $data instanceof CursorPaginator ) { |
|
| 111 | + $this->cursor( $this->paginatorFactory->makeCursor( $data ) ); |
|
| 112 | + } elseif ( $data instanceof LengthAwarePaginator ) { |
|
| 113 | + $this->paginator( $this->paginatorFactory->make( $data ) ); |
|
| 114 | 114 | } |
| 115 | 115 | |
| 116 | 116 | return $this; |
@@ -122,9 +122,9 @@ discard block |
||
| 122 | 122 | * @param \League\Fractal\Pagination\Cursor $cursor |
| 123 | 123 | * @return self |
| 124 | 124 | */ |
| 125 | - public function cursor(Cursor $cursor): TransformBuilder |
|
| 125 | + public function cursor( Cursor $cursor ): TransformBuilder |
|
| 126 | 126 | { |
| 127 | - $this->resource->setCursor($cursor); |
|
| 127 | + $this->resource->setCursor( $cursor ); |
|
| 128 | 128 | |
| 129 | 129 | return $this; |
| 130 | 130 | } |
@@ -135,9 +135,9 @@ discard block |
||
| 135 | 135 | * @param \League\Fractal\Pagination\IlluminatePaginatorAdapter $paginator |
| 136 | 136 | * @return self |
| 137 | 137 | */ |
| 138 | - public function paginator(IlluminatePaginatorAdapter $paginator): TransformBuilder |
|
| 138 | + public function paginator( IlluminatePaginatorAdapter $paginator ): TransformBuilder |
|
| 139 | 139 | { |
| 140 | - $this->resource->setPaginator($paginator); |
|
| 140 | + $this->resource->setPaginator( $paginator ); |
|
| 141 | 141 | |
| 142 | 142 | return $this; |
| 143 | 143 | } |
@@ -148,9 +148,9 @@ discard block |
||
| 148 | 148 | * @param array $meta |
| 149 | 149 | * @return self |
| 150 | 150 | */ |
| 151 | - public function meta(array $meta): TransformBuilder |
|
| 151 | + public function meta( array $meta ): TransformBuilder |
|
| 152 | 152 | { |
| 153 | - $this->resource->setMeta($meta); |
|
| 153 | + $this->resource->setMeta( $meta ); |
|
| 154 | 154 | |
| 155 | 155 | return $this; |
| 156 | 156 | } |
@@ -161,9 +161,9 @@ discard block |
||
| 161 | 161 | * @param string[]|string $relations |
| 162 | 162 | * @return self |
| 163 | 163 | */ |
| 164 | - public function with($relations): TransformBuilder |
|
| 164 | + public function with( $relations ): TransformBuilder |
|
| 165 | 165 | { |
| 166 | - $this->with = array_merge($this->with, is_array($relations) ? $relations : func_get_args()); |
|
| 166 | + $this->with = array_merge( $this->with, is_array( $relations ) ? $relations : func_get_args() ); |
|
| 167 | 167 | |
| 168 | 168 | return $this; |
| 169 | 169 | } |
@@ -174,9 +174,9 @@ discard block |
||
| 174 | 174 | * @param string[]|string $relations |
| 175 | 175 | * @return self |
| 176 | 176 | */ |
| 177 | - public function without($relations): TransformBuilder |
|
| 177 | + public function without( $relations ): TransformBuilder |
|
| 178 | 178 | { |
| 179 | - $this->without = array_merge($this->without, is_array($relations) ? $relations : func_get_args()); |
|
| 179 | + $this->without = array_merge( $this->without, is_array( $relations ) ? $relations : func_get_args() ); |
|
| 180 | 180 | |
| 181 | 181 | return $this; |
| 182 | 182 | } |
@@ -187,9 +187,9 @@ discard block |
||
| 187 | 187 | * @param string[]|string $fields |
| 188 | 188 | * @return self |
| 189 | 189 | */ |
| 190 | - public function only($fields): TransformBuilder |
|
| 190 | + public function only( $fields ): TransformBuilder |
|
| 191 | 191 | { |
| 192 | - $this->only = array_merge($this->only, is_array($fields) ? $fields : func_get_args()); |
|
| 192 | + $this->only = array_merge( $this->only, is_array( $fields ) ? $fields : func_get_args() ); |
|
| 193 | 193 | |
| 194 | 194 | return $this; |
| 195 | 195 | } |
@@ -201,13 +201,13 @@ discard block |
||
| 201 | 201 | * @return self |
| 202 | 202 | * @throws \Flugg\Responder\Exceptions\InvalidSerializerException |
| 203 | 203 | */ |
| 204 | - public function serializer($serializer): TransformBuilder |
|
| 204 | + public function serializer( $serializer ): TransformBuilder |
|
| 205 | 205 | { |
| 206 | - if (is_string($serializer)) { |
|
| 206 | + if ( is_string( $serializer ) ) { |
|
| 207 | 207 | $serializer = new $serializer; |
| 208 | 208 | } |
| 209 | 209 | |
| 210 | - if (! $serializer instanceof SerializerAbstract) { |
|
| 210 | + if ( ! $serializer instanceof SerializerAbstract ) { |
|
| 211 | 211 | throw new InvalidSerializerException; |
| 212 | 212 | } |
| 213 | 213 | |
@@ -225,11 +225,11 @@ discard block |
||
| 225 | 225 | { |
| 226 | 226 | $this->prepareRelations(); |
| 227 | 227 | |
| 228 | - return $this->transformFactory->make($this->resource, $this->serializer, [ |
|
| 228 | + return $this->transformFactory->make( $this->resource, $this->serializer, [ |
|
| 229 | 229 | 'includes' => $this->with, |
| 230 | 230 | 'excludes' => $this->without, |
| 231 | 231 | 'fields' => $this->only, |
| 232 | - ]); |
|
| 232 | + ] ); |
|
| 233 | 233 | } |
| 234 | 234 | |
| 235 | 235 | /** |
@@ -239,10 +239,10 @@ discard block |
||
| 239 | 239 | */ |
| 240 | 240 | protected function prepareRelations() |
| 241 | 241 | { |
| 242 | - $this->setDefaultIncludes($this->resource->getTransformer()); |
|
| 243 | - $this->eagerLoadIfApplicable($this->resource->getData()); |
|
| 242 | + $this->setDefaultIncludes( $this->resource->getTransformer() ); |
|
| 243 | + $this->eagerLoadIfApplicable( $this->resource->getData() ); |
|
| 244 | 244 | |
| 245 | - $this->with = $this->trimEagerLoadFunctions($this->with); |
|
| 245 | + $this->with = $this->trimEagerLoadFunctions( $this->with ); |
|
| 246 | 246 | } |
| 247 | 247 | |
| 248 | 248 | /** |
@@ -251,10 +251,10 @@ discard block |
||
| 251 | 251 | * @param \Flugg\Responder\Transformers\Transformer|callable $transformer |
| 252 | 252 | * @return void |
| 253 | 253 | */ |
| 254 | - protected function setDefaultIncludes($transformer) |
|
| 254 | + protected function setDefaultIncludes( $transformer ) |
|
| 255 | 255 | { |
| 256 | - if ($transformer instanceof Transformer) { |
|
| 257 | - $this->with($transformer->extractDefaultRelations()); |
|
| 256 | + if ( $transformer instanceof Transformer ) { |
|
| 257 | + $this->with( $transformer->extractDefaultRelations() ); |
|
| 258 | 258 | } |
| 259 | 259 | } |
| 260 | 260 | |
@@ -264,10 +264,10 @@ discard block |
||
| 264 | 264 | * @param mixed $data |
| 265 | 265 | * @return void |
| 266 | 266 | */ |
| 267 | - protected function eagerLoadIfApplicable($data) |
|
| 267 | + protected function eagerLoadIfApplicable( $data ) |
|
| 268 | 268 | { |
| 269 | - if ($data instanceof Model || $data instanceof Collection) { |
|
| 270 | - $data->load($this->with); |
|
| 269 | + if ( $data instanceof Model || $data instanceof Collection ) { |
|
| 270 | + $data->load( $this->with ); |
|
| 271 | 271 | } |
| 272 | 272 | } |
| 273 | 273 | |
@@ -277,10 +277,10 @@ discard block |
||
| 277 | 277 | * @param array $relations |
| 278 | 278 | * @return void |
| 279 | 279 | */ |
| 280 | - protected function trimEagerLoadFunctions(array $relations) |
|
| 280 | + protected function trimEagerLoadFunctions( array $relations ) |
|
| 281 | 281 | { |
| 282 | - return collect($relations)->map(function ($value, $key) { |
|
| 283 | - return is_numeric($key) ? $value : $key; |
|
| 282 | + return collect( $relations )->map( function ( $value, $key ) { |
|
| 283 | + return is_numeric( $key ) ? $value : $key; |
|
| 284 | 284 | })->values()->all(); |
| 285 | 285 | } |
| 286 | 286 | } |
| 287 | 287 | \ No newline at end of file |
@@ -129,7 +129,7 @@ |
||
| 129 | 129 | /** |
| 130 | 130 | * Make a simple closure transformer. |
| 131 | 131 | * |
| 132 | - * @return callable |
|
| 132 | + * @return \Closure |
|
| 133 | 133 | */ |
| 134 | 134 | protected function makeClosureTransformer(): callable |
| 135 | 135 | { |
@@ -29,14 +29,14 @@ discard block |
||
| 29 | 29 | * |
| 30 | 30 | * @var array |
| 31 | 31 | */ |
| 32 | - protected $bindings = []; |
|
| 32 | + protected $bindings = [ ]; |
|
| 33 | 33 | |
| 34 | 34 | /** |
| 35 | 35 | * Construct the resolver class. |
| 36 | 36 | * |
| 37 | 37 | * @param \Illuminate\Contracts\Container\Container $container |
| 38 | 38 | */ |
| 39 | - public function __construct(Container $container) |
|
| 39 | + public function __construct( Container $container ) |
|
| 40 | 40 | { |
| 41 | 41 | $this->container = $container; |
| 42 | 42 | } |
@@ -48,11 +48,11 @@ discard block |
||
| 48 | 48 | * @param string|callback $transformer |
| 49 | 49 | * @return void |
| 50 | 50 | */ |
| 51 | - public function bind($transformable, $transformer) |
|
| 51 | + public function bind( $transformable, $transformer ) |
|
| 52 | 52 | { |
| 53 | - $this->bindings = array_merge($this->bindings, is_array($transformable) ? $transformable : [ |
|
| 53 | + $this->bindings = array_merge( $this->bindings, is_array( $transformable ) ? $transformable : [ |
|
| 54 | 54 | $transformable => $transformer, |
| 55 | - ]); |
|
| 55 | + ] ); |
|
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | /** |
@@ -62,13 +62,13 @@ discard block |
||
| 62 | 62 | * @return \Flugg\Responder\Transformers\Transformer|callable |
| 63 | 63 | * @throws \Flugg\Responder\Exceptions\InvalidTransformerException |
| 64 | 64 | */ |
| 65 | - public function resolve($transformer) |
|
| 65 | + public function resolve( $transformer ) |
|
| 66 | 66 | { |
| 67 | - if (is_string($transformer)) { |
|
| 68 | - return $this->container->make($transformer); |
|
| 67 | + if ( is_string( $transformer ) ) { |
|
| 68 | + return $this->container->make( $transformer ); |
|
| 69 | 69 | } |
| 70 | 70 | |
| 71 | - if (! is_callable($transformer) && ! $transformer instanceof Transformer) { |
|
| 71 | + if ( ! is_callable( $transformer ) && ! $transformer instanceof Transformer ) { |
|
| 72 | 72 | throw new InvalidTransformerException; |
| 73 | 73 | } |
| 74 | 74 | |
@@ -81,11 +81,11 @@ discard block |
||
| 81 | 81 | * @param mixed $data |
| 82 | 82 | * @return \Flugg\Responder\Transformers\Transformer|callable|null |
| 83 | 83 | */ |
| 84 | - public function resolveFromData($data) |
|
| 84 | + public function resolveFromData( $data ) |
|
| 85 | 85 | { |
| 86 | - if ($transformable = $this->resolveTransformable($data)) { |
|
| 87 | - if ($transformer = $this->resolveTransformer()) { |
|
| 88 | - return $this->resolve($transformer); |
|
| 86 | + if ( $transformable = $this->resolveTransformable( $data ) ) { |
|
| 87 | + if ( $transformer = $this->resolveTransformer() ) { |
|
| 88 | + return $this->resolve( $transformer ); |
|
| 89 | 89 | } |
| 90 | 90 | } |
| 91 | 91 | |
@@ -98,11 +98,11 @@ discard block |
||
| 98 | 98 | * @param mixed $data |
| 99 | 99 | * @return \Flugg\Responder\Contracts\Transformable|null |
| 100 | 100 | */ |
| 101 | - protected function resolveTransformable($data) |
|
| 101 | + protected function resolveTransformable( $data ) |
|
| 102 | 102 | { |
| 103 | - if (is_array($data) || $data instanceof Traversable) { |
|
| 104 | - foreach ($data as $item) { |
|
| 105 | - if ($item instanceof Transformable) { |
|
| 103 | + if ( is_array( $data ) || $data instanceof Traversable ) { |
|
| 104 | + foreach ( $data as $item ) { |
|
| 105 | + if ( $item instanceof Transformable ) { |
|
| 106 | 106 | return $item; |
| 107 | 107 | } |
| 108 | 108 | } |
@@ -117,10 +117,10 @@ discard block |
||
| 117 | 117 | * @param \Flugg\Responder\Contracts\Transformable $transformable |
| 118 | 118 | * @return \Flugg\Responder\Contracts\Transformable|null |
| 119 | 119 | */ |
| 120 | - protected function resolveTransformer(Transformable $transformable) |
|
| 120 | + protected function resolveTransformer( Transformable $transformable ) |
|
| 121 | 121 | { |
| 122 | - if (key_exists($this->bindings, get_class($transformable))) { |
|
| 123 | - return $this->bindings[get_class($transformable)]; |
|
| 122 | + if ( key_exists( $this->bindings, get_class( $transformable ) ) ) { |
|
| 123 | + return $this->bindings[ get_class( $transformable ) ]; |
|
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | return $transformable->transformer(); |
@@ -133,7 +133,7 @@ discard block |
||
| 133 | 133 | */ |
| 134 | 134 | protected function makeClosureTransformer(): callable |
| 135 | 135 | { |
| 136 | - return function ($data) { |
|
| 136 | + return function ( $data ) { |
|
| 137 | 137 | return $data instanceof Arrayable ? $data->toArray() : $data; |
| 138 | 138 | }; |
| 139 | 139 | } |
@@ -28,7 +28,7 @@ discard block |
||
| 28 | 28 | * |
| 29 | 29 | * @param \League\Fractal\Manager $manager |
| 30 | 30 | */ |
| 31 | - public function __construct(Manager $manager) |
|
| 31 | + public function __construct( Manager $manager ) |
|
| 32 | 32 | { |
| 33 | 33 | $this->manager = $manager; |
| 34 | 34 | } |
@@ -41,13 +41,13 @@ discard block |
||
| 41 | 41 | * @param array $options |
| 42 | 42 | * @return array |
| 43 | 43 | */ |
| 44 | - public function make(ResourceInterface $resource, SerializerAbstract $serializer, array $options = []): array |
|
| 44 | + public function make( ResourceInterface $resource, SerializerAbstract $serializer, array $options = [ ] ): array |
|
| 45 | 45 | { |
| 46 | - return $this->manager->setSerializer($serializer) |
|
| 47 | - ->parseIncludes($options['includes'] ?? []) |
|
| 48 | - ->parseExcludes($options['excludes'] ?? []) |
|
| 49 | - ->parseFieldsets($options['fields'] ?? []) |
|
| 50 | - ->createData($resource) |
|
| 46 | + return $this->manager->setSerializer( $serializer ) |
|
| 47 | + ->parseIncludes( $options[ 'includes' ] ?? [ ] ) |
|
| 48 | + ->parseExcludes( $options[ 'excludes' ] ?? [ ] ) |
|
| 49 | + ->parseFieldsets( $options[ 'fields' ] ?? [ ] ) |
|
| 50 | + ->createData( $resource ) |
|
| 51 | 51 | ->toArray(); |
| 52 | 52 | } |
| 53 | 53 | } |
| 54 | 54 | \ No newline at end of file |
@@ -21,10 +21,10 @@ discard block |
||
| 21 | 21 | * @param int $status |
| 22 | 22 | * @return $this |
| 23 | 23 | */ |
| 24 | - protected function seeSuccess($data = null, $status = 200) |
|
| 24 | + protected function seeSuccess( $data = null, $status = 200 ) |
|
| 25 | 25 | { |
| 26 | - $response = $this->seeSuccessResponse($data, $status); |
|
| 27 | - $this->seeSuccessData($response->getData(true)['data']); |
|
| 26 | + $response = $this->seeSuccessResponse( $data, $status ); |
|
| 27 | + $this->seeSuccessData( $response->getData( true )[ 'data' ] ); |
|
| 28 | 28 | |
| 29 | 29 | return $this; |
| 30 | 30 | } |
@@ -36,10 +36,10 @@ discard block |
||
| 36 | 36 | * @param int $status |
| 37 | 37 | * @return $this |
| 38 | 38 | */ |
| 39 | - protected function seeSuccessEquals($data = null, $status = 200) |
|
| 39 | + protected function seeSuccessEquals( $data = null, $status = 200 ) |
|
| 40 | 40 | { |
| 41 | - $response = $this->seeSuccessResponse($data, $status); |
|
| 42 | - $this->seeJsonEquals($response->getData(true)); |
|
| 41 | + $response = $this->seeSuccessResponse( $data, $status ); |
|
| 42 | + $this->seeJsonEquals( $response->getData( true ) ); |
|
| 43 | 43 | |
| 44 | 44 | return $this; |
| 45 | 45 | } |
@@ -50,11 +50,11 @@ discard block |
||
| 50 | 50 | * @param mixed $data |
| 51 | 51 | * @return $this |
| 52 | 52 | */ |
| 53 | - protected function seeSuccessStructure($data = null) |
|
| 53 | + protected function seeSuccessStructure( $data = null ) |
|
| 54 | 54 | { |
| 55 | - $this->seeJsonStructure([ |
|
| 55 | + $this->seeJsonStructure( [ |
|
| 56 | 56 | 'data' => $data, |
| 57 | - ]); |
|
| 57 | + ] ); |
|
| 58 | 58 | |
| 59 | 59 | return $this; |
| 60 | 60 | } |
@@ -66,14 +66,14 @@ discard block |
||
| 66 | 66 | * @param int $status |
| 67 | 67 | * @return \Illuminate\Http\JsonResponse |
| 68 | 68 | */ |
| 69 | - protected function seeSuccessResponse($data = null, $status = 200): JsonResponse |
|
| 69 | + protected function seeSuccessResponse( $data = null, $status = 200 ): JsonResponse |
|
| 70 | 70 | { |
| 71 | - $response = $this->app->make(Responder::class)->success($data, $status); |
|
| 71 | + $response = $this->app->make( Responder::class )->success( $data, $status ); |
|
| 72 | 72 | |
| 73 | - $this->seeStatusCode($response->getStatusCode())->seeJson([ |
|
| 73 | + $this->seeStatusCode( $response->getStatusCode() )->seeJson( [ |
|
| 74 | 74 | 'success' => true, |
| 75 | 75 | 'status' => $response->getStatusCode(), |
| 76 | - ])->seeJsonStructure(['data']); |
|
| 76 | + ] )->seeJsonStructure( [ 'data' ] ); |
|
| 77 | 77 | |
| 78 | 78 | return $response; |
| 79 | 79 | } |
@@ -84,13 +84,13 @@ discard block |
||
| 84 | 84 | * @param mixed $data |
| 85 | 85 | * @return $this |
| 86 | 86 | */ |
| 87 | - protected function seeSuccessData($data = null) |
|
| 87 | + protected function seeSuccessData( $data = null ) |
|
| 88 | 88 | { |
| 89 | - collect($data)->each(function ($value, $key) { |
|
| 90 | - if (is_array($value)) { |
|
| 91 | - $this->seeSuccessData($value); |
|
| 89 | + collect( $data )->each( function ( $value, $key ) { |
|
| 90 | + if ( is_array( $value ) ) { |
|
| 91 | + $this->seeSuccessData( $value ); |
|
| 92 | 92 | } else { |
| 93 | - $this->seeJson([$key => $value]); |
|
| 93 | + $this->seeJson( [ $key => $value ] ); |
|
| 94 | 94 | } |
| 95 | 95 | }); |
| 96 | 96 | |
@@ -103,20 +103,20 @@ discard block |
||
| 103 | 103 | * @param string|array|null $attributes |
| 104 | 104 | * @return array |
| 105 | 105 | */ |
| 106 | - protected function getSuccessData($attributes = null) |
|
| 106 | + protected function getSuccessData( $attributes = null ) |
|
| 107 | 107 | { |
| 108 | - $rawData = $this->decodeResponseJson()['data']; |
|
| 108 | + $rawData = $this->decodeResponseJson()[ 'data' ]; |
|
| 109 | 109 | |
| 110 | - if (is_null($attributes)) { |
|
| 110 | + if ( is_null( $attributes ) ) { |
|
| 111 | 111 | return $rawData; |
| 112 | - } elseif (is_string($attributes)) { |
|
| 113 | - return array_get($rawData, $attributes); |
|
| 112 | + } elseif ( is_string( $attributes ) ) { |
|
| 113 | + return array_get( $rawData, $attributes ); |
|
| 114 | 114 | } |
| 115 | 115 | |
| 116 | - $data = []; |
|
| 116 | + $data = [ ]; |
|
| 117 | 117 | |
| 118 | - foreach ($attributes as $attribute) { |
|
| 119 | - $data[] = array_get($rawData, $attribute); |
|
| 118 | + foreach ( $attributes as $attribute ) { |
|
| 119 | + $data[ ] = array_get( $rawData, $attribute ); |
|
| 120 | 120 | } |
| 121 | 121 | |
| 122 | 122 | return $data; |
@@ -129,25 +129,25 @@ discard block |
||
| 129 | 129 | * @param int|null $status |
| 130 | 130 | * @return $this |
| 131 | 131 | */ |
| 132 | - protected function seeError(string $error, int $status = null) |
|
| 132 | + protected function seeError( string $error, int $status = null ) |
|
| 133 | 133 | { |
| 134 | - if (! is_null($status)) { |
|
| 135 | - $this->seeStatusCode($status); |
|
| 134 | + if ( ! is_null( $status ) ) { |
|
| 135 | + $this->seeStatusCode( $status ); |
|
| 136 | 136 | } |
| 137 | 137 | |
| 138 | - if ($this->app->config->get('responder.status_code')) { |
|
| 139 | - $this->seeJson([ |
|
| 138 | + if ( $this->app->config->get( 'responder.status_code' ) ) { |
|
| 139 | + $this->seeJson( [ |
|
| 140 | 140 | 'status' => $status, |
| 141 | - ]); |
|
| 141 | + ] ); |
|
| 142 | 142 | } |
| 143 | 143 | |
| 144 | - return $this->seeJson([ |
|
| 144 | + return $this->seeJson( [ |
|
| 145 | 145 | 'success' => false, |
| 146 | - ])->seeJsonSubset([ |
|
| 146 | + ] )->seeJsonSubset( [ |
|
| 147 | 147 | 'error' => [ |
| 148 | 148 | 'code' => $error, |
| 149 | 149 | ], |
| 150 | - ]); |
|
| 150 | + ] ); |
|
| 151 | 151 | } |
| 152 | 152 | |
| 153 | 153 | /** |
@@ -156,7 +156,7 @@ discard block |
||
| 156 | 156 | * @param int $status |
| 157 | 157 | * @return $this |
| 158 | 158 | */ |
| 159 | - abstract protected function seeStatusCode($status); |
|
| 159 | + abstract protected function seeStatusCode( $status ); |
|
| 160 | 160 | |
| 161 | 161 | /** |
| 162 | 162 | * Assert that the response contains JSON. |
@@ -165,7 +165,7 @@ discard block |
||
| 165 | 165 | * @param bool $negate |
| 166 | 166 | * @return $this |
| 167 | 167 | */ |
| 168 | - abstract public function seeJson(array $data = null, $negate = false); |
|
| 168 | + abstract public function seeJson( array $data = null, $negate = false ); |
|
| 169 | 169 | |
| 170 | 170 | /** |
| 171 | 171 | * Assert that the JSON response has a given structure. |
@@ -174,7 +174,7 @@ discard block |
||
| 174 | 174 | * @param array|null $responseData |
| 175 | 175 | * @return $this |
| 176 | 176 | */ |
| 177 | - abstract public function seeJsonStructure(array $structure = null, $responseData = null); |
|
| 177 | + abstract public function seeJsonStructure( array $structure = null, $responseData = null ); |
|
| 178 | 178 | |
| 179 | 179 | /** |
| 180 | 180 | * Assert that the response is a superset of the given JSON. |
@@ -182,7 +182,7 @@ discard block |
||
| 182 | 182 | * @param array $data |
| 183 | 183 | * @return $this |
| 184 | 184 | */ |
| 185 | - abstract protected function seeJsonSubset(array $data); |
|
| 185 | + abstract protected function seeJsonSubset( array $data ); |
|
| 186 | 186 | |
| 187 | 187 | /** |
| 188 | 188 | * Assert that the response contains an exact JSON array. |
@@ -190,7 +190,7 @@ discard block |
||
| 190 | 190 | * @param array $data |
| 191 | 191 | * @return $this |
| 192 | 192 | */ |
| 193 | - abstract public function seeJsonEquals(array $data); |
|
| 193 | + abstract public function seeJsonEquals( array $data ); |
|
| 194 | 194 | |
| 195 | 195 | /** |
| 196 | 196 | * Validate and return the decoded response JSON. |
@@ -26,7 +26,7 @@ discard block |
||
| 26 | 26 | * |
| 27 | 27 | * @param \Illuminate\Contracts\Translation\Translator $translator |
| 28 | 28 | */ |
| 29 | - public function __construct(Translator $translator) |
|
| 29 | + public function __construct( Translator $translator ) |
|
| 30 | 30 | { |
| 31 | 31 | $this->translator = $translator; |
| 32 | 32 | } |
@@ -37,12 +37,12 @@ discard block |
||
| 37 | 37 | * @param string $errorCode |
| 38 | 38 | * @return string|null |
| 39 | 39 | */ |
| 40 | - public function resolve(string $errorCode) |
|
| 40 | + public function resolve( string $errorCode ) |
|
| 41 | 41 | { |
| 42 | - if (! $this->translator->has($errorCode = "errors.$errorCode")) { |
|
| 42 | + if ( ! $this->translator->has( $errorCode = "errors.$errorCode" ) ) { |
|
| 43 | 43 | return null; |
| 44 | 44 | } |
| 45 | 45 | |
| 46 | - return $this->translator->trans($errorCode); |
|
| 46 | + return $this->translator->trans( $errorCode ); |
|
| 47 | 47 | } |
| 48 | 48 | } |
| 49 | 49 | \ No newline at end of file |
@@ -26,7 +26,7 @@ discard block |
||
| 26 | 26 | * |
| 27 | 27 | * @param \Flugg\Responder\TransformBuilder $transformBuilder |
| 28 | 28 | */ |
| 29 | - public function __construct(TransformBuilder $transformBuilder) |
|
| 29 | + public function __construct( TransformBuilder $transformBuilder ) |
|
| 30 | 30 | { |
| 31 | 31 | $this->transformBuilder = $transformBuilder; |
| 32 | 32 | } |
@@ -40,12 +40,12 @@ discard block |
||
| 40 | 40 | * @param string[] $without |
| 41 | 41 | * @return array |
| 42 | 42 | */ |
| 43 | - public function transform($data = null, $transformer = null, array $with = [], array $without = []): array |
|
| 43 | + public function transform( $data = null, $transformer = null, array $with = [ ], array $without = [ ] ): array |
|
| 44 | 44 | { |
| 45 | - return $this->transformBuilder->resource($data, $transformer) |
|
| 46 | - ->with($with) |
|
| 47 | - ->without($without) |
|
| 48 | - ->serializer(new NullSerializer) |
|
| 45 | + return $this->transformBuilder->resource( $data, $transformer ) |
|
| 46 | + ->with( $with ) |
|
| 47 | + ->without( $without ) |
|
| 48 | + ->serializer( new NullSerializer ) |
|
| 49 | 49 | ->transform(); |
| 50 | 50 | } |
| 51 | 51 | } |
| 52 | 52 | \ No newline at end of file |
@@ -19,6 +19,6 @@ |
||
| 19 | 19 | */ |
| 20 | 20 | public function __construct() |
| 21 | 21 | { |
| 22 | - parent::__construct('Given serializer must be an instance of [' . SerializerAbstract::class . '].'); |
|
| 22 | + parent::__construct( 'Given serializer must be an instance of [' . SerializerAbstract::class . '].' ); |
|
| 23 | 23 | } |
| 24 | 24 | } |
| 25 | 25 | \ No newline at end of file |
@@ -40,7 +40,7 @@ discard block |
||
| 40 | 40 | * |
| 41 | 41 | * @param \Illuminate\Contracts\Validation\Validator $validator |
| 42 | 42 | */ |
| 43 | - public function __construct(Validator $validator) |
|
| 43 | + public function __construct( Validator $validator ) |
|
| 44 | 44 | { |
| 45 | 45 | $this->validator = $validator; |
| 46 | 46 | |
@@ -54,6 +54,6 @@ discard block |
||
| 54 | 54 | */ |
| 55 | 55 | public function data() |
| 56 | 56 | { |
| 57 | - return [$this->validator->getMessageBag()->toArray()]; |
|
| 57 | + return [ $this->validator->getMessageBag()->toArray() ]; |
|
| 58 | 58 | } |
| 59 | 59 | } |
| 60 | 60 | \ No newline at end of file |
@@ -19,6 +19,6 @@ |
||
| 19 | 19 | */ |
| 20 | 20 | public function __construct() |
| 21 | 21 | { |
| 22 | - parent::__construct('Given transformer must be a callable or an instance of [' . Transformer::class . '].'); |
|
| 22 | + parent::__construct( 'Given transformer must be a callable or an instance of [' . Transformer::class . '].' ); |
|
| 23 | 23 | } |
| 24 | 24 | } |
| 25 | 25 | \ No newline at end of file |