@@ -65,21 +65,21 @@ discard block |
||
| 65 | 65 | * |
| 66 | 66 | * @var array |
| 67 | 67 | */ |
| 68 | - protected $with = []; |
|
| 68 | + protected $with = [ ]; |
|
| 69 | 69 | |
| 70 | 70 | /** |
| 71 | 71 | * A list of excluded relations. |
| 72 | 72 | * |
| 73 | 73 | * @var array |
| 74 | 74 | */ |
| 75 | - protected $without = []; |
|
| 75 | + protected $without = [ ]; |
|
| 76 | 76 | |
| 77 | 77 | /** |
| 78 | 78 | * A list of sparse fieldsets. |
| 79 | 79 | * |
| 80 | 80 | * @var array |
| 81 | 81 | */ |
| 82 | - protected $only = []; |
|
| 82 | + protected $only = [ ]; |
|
| 83 | 83 | |
| 84 | 84 | /** |
| 85 | 85 | * Construct the builder class. |
@@ -88,7 +88,7 @@ discard block |
||
| 88 | 88 | * @param \Flugg\Responder\Contracts\TransformFactory $transformFactory |
| 89 | 89 | * @param \Flugg\Responder\Contracts\Pagination\PaginatorFactory $paginatorFactory |
| 90 | 90 | */ |
| 91 | - public function __construct(ResourceFactory $resourceFactory, TransformFactory $transformFactory, PaginatorFactory $paginatorFactory) |
|
| 91 | + public function __construct( ResourceFactory $resourceFactory, TransformFactory $transformFactory, PaginatorFactory $paginatorFactory ) |
|
| 92 | 92 | { |
| 93 | 93 | $this->resourceFactory = $resourceFactory; |
| 94 | 94 | $this->transformFactory = $transformFactory; |
@@ -103,14 +103,14 @@ discard block |
||
| 103 | 103 | * @param string|null $resourceKey |
| 104 | 104 | * @return $this |
| 105 | 105 | */ |
| 106 | - public function resource($data = null, $transformer = null, string $resourceKey = null) |
|
| 106 | + public function resource( $data = null, $transformer = null, string $resourceKey = null ) |
|
| 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 $this |
| 124 | 124 | */ |
| 125 | - public function cursor(Cursor $cursor) |
|
| 125 | + public function cursor( Cursor $cursor ) |
|
| 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 $this |
| 137 | 137 | */ |
| 138 | - public function paginator(IlluminatePaginatorAdapter $paginator) |
|
| 138 | + public function paginator( IlluminatePaginatorAdapter $paginator ) |
|
| 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 $data |
| 149 | 149 | * @return $this |
| 150 | 150 | */ |
| 151 | - public function meta(array $data) |
|
| 151 | + public function meta( array $data ) |
|
| 152 | 152 | { |
| 153 | - $this->resource->setMeta($data); |
|
| 153 | + $this->resource->setMeta( $data ); |
|
| 154 | 154 | |
| 155 | 155 | return $this; |
| 156 | 156 | } |
@@ -161,9 +161,9 @@ discard block |
||
| 161 | 161 | * @param string[]|string $relations |
| 162 | 162 | * @return $this |
| 163 | 163 | */ |
| 164 | - public function with($relations) |
|
| 164 | + public function with( $relations ) |
|
| 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 $this |
| 176 | 176 | */ |
| 177 | - public function without($relations) |
|
| 177 | + public function without( $relations ) |
|
| 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 $this |
| 189 | 189 | */ |
| 190 | - public function only($fields) |
|
| 190 | + public function only( $fields ) |
|
| 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 $this |
| 202 | 202 | * @throws \Flugg\Responder\Exceptions\InvalidSerializerException |
| 203 | 203 | */ |
| 204 | - public function serializer($serializer) |
|
| 204 | + public function serializer( $serializer ) |
|
| 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 | |
@@ -223,13 +223,13 @@ discard block |
||
| 223 | 223 | */ |
| 224 | 224 | public function transform(): array |
| 225 | 225 | { |
| 226 | - $this->prepareRelations($this->resource->getData(), $this->resource->getTransformer()); |
|
| 226 | + $this->prepareRelations( $this->resource->getData(), $this->resource->getTransformer() ); |
|
| 227 | 227 | |
| 228 | - return $this->transformFactory->make($this->resource ?: new NullResource, $this->serializer, [ |
|
| 228 | + return $this->transformFactory->make( $this->resource ?: new NullResource, $this->serializer, [ |
|
| 229 | 229 | 'includes' => $this->with, |
| 230 | 230 | 'excludes' => $this->without, |
| 231 | 231 | 'fieldsets' => $this->only, |
| 232 | - ]); |
|
| 232 | + ] ); |
|
| 233 | 233 | } |
| 234 | 234 | |
| 235 | 235 | /** |
@@ -239,17 +239,17 @@ discard block |
||
| 239 | 239 | * @param \Flugg\Responder\Transformers\Transformer|callable|string|null $transformer |
| 240 | 240 | * @return void |
| 241 | 241 | */ |
| 242 | - protected function prepareRelations($data, $transformer) |
|
| 242 | + protected function prepareRelations( $data, $transformer ) |
|
| 243 | 243 | { |
| 244 | - if ($transformer instanceof Transformer) { |
|
| 245 | - $this->with($transformer->extractDefaultRelations()); |
|
| 244 | + if ( $transformer instanceof Transformer ) { |
|
| 245 | + $this->with( $transformer->extractDefaultRelations() ); |
|
| 246 | 246 | } |
| 247 | 247 | |
| 248 | - if ($data instanceof Model || $data instanceof Collection) { |
|
| 249 | - $data->load($this->with); |
|
| 248 | + if ( $data instanceof Model || $data instanceof Collection ) { |
|
| 249 | + $data->load( $this->with ); |
|
| 250 | 250 | } |
| 251 | 251 | |
| 252 | - $this->with = $this->stripEagerLoadConstraints($this->with); |
|
| 252 | + $this->with = $this->stripEagerLoadConstraints( $this->with ); |
|
| 253 | 253 | } |
| 254 | 254 | |
| 255 | 255 | /** |
@@ -258,10 +258,10 @@ discard block |
||
| 258 | 258 | * @param array $relations |
| 259 | 259 | * @return array |
| 260 | 260 | */ |
| 261 | - protected function stripEagerLoadConstraints(array $relations): array |
|
| 261 | + protected function stripEagerLoadConstraints( array $relations ): array |
|
| 262 | 262 | { |
| 263 | - return collect($relations)->map(function ($value, $key) { |
|
| 264 | - return is_numeric($key) ? $value : $key; |
|
| 263 | + return collect( $relations )->map( function ( $value, $key ) { |
|
| 264 | + return is_numeric( $key ) ? $value : $key; |
|
| 265 | 265 | })->values()->all(); |
| 266 | 266 | } |
| 267 | 267 | } |
| 268 | 268 | \ No newline at end of file |