@@ -108,7 +108,7 @@ |
||
| 108 | 108 | /** |
| 109 | 109 | * Get the services provided by the provider. |
| 110 | 110 | * |
| 111 | - * @return array |
|
| 111 | + * @return string[] |
|
| 112 | 112 | */ |
| 113 | 113 | public function provides() |
| 114 | 114 | { |
@@ -3,7 +3,6 @@ |
||
| 3 | 3 | namespace Flugg\Responder; |
| 4 | 4 | |
| 5 | 5 | use Flugg\Responder\Console\MakeTransformer; |
| 6 | -use Flugg\Responder\Contracts\Manager as ManagerContract; |
|
| 7 | 6 | use Flugg\Responder\Http\ErrorResponseBuilder; |
| 8 | 7 | use Flugg\Responder\Http\SuccessResponseBuilder; |
| 9 | 8 | use Illuminate\Contracts\Routing\ResponseFactory; |
@@ -43,18 +43,18 @@ discard block |
||
| 43 | 43 | */ |
| 44 | 44 | public function boot() |
| 45 | 45 | { |
| 46 | - if ($this->app instanceof Laravel && $this->app->runningInConsole()) { |
|
| 46 | + if ( $this->app instanceof Laravel && $this->app->runningInConsole() ) { |
|
| 47 | 47 | $this->bootLaravelApplication(); |
| 48 | 48 | |
| 49 | - } elseif ($this->app instanceof Lumen) { |
|
| 49 | + } elseif ( $this->app instanceof Lumen ) { |
|
| 50 | 50 | $this->bootLumenApplication(); |
| 51 | 51 | } |
| 52 | 52 | |
| 53 | - $this->mergeConfigFrom(__DIR__ . '/../resources/config/responder.php', 'responder'); |
|
| 53 | + $this->mergeConfigFrom( __DIR__ . '/../resources/config/responder.php', 'responder' ); |
|
| 54 | 54 | |
| 55 | - $this->commands([ |
|
| 55 | + $this->commands( [ |
|
| 56 | 56 | MakeTransformer::class |
| 57 | - ]); |
|
| 57 | + ] ); |
|
| 58 | 58 | |
| 59 | 59 | include __DIR__ . '/helpers.php'; |
| 60 | 60 | } |
@@ -69,8 +69,8 @@ discard block |
||
| 69 | 69 | $this->registerFractal(); |
| 70 | 70 | $this->registerResponseBuilders(); |
| 71 | 71 | |
| 72 | - $this->app->bind(Responder::class, function ($app) { |
|
| 73 | - return new Responder($app[SuccessResponseBuilder::class], $app[ErrorResponseBuilder::class]); |
|
| 72 | + $this->app->bind( Responder::class, function ( $app ) { |
|
| 73 | + return new Responder( $app[ SuccessResponseBuilder::class ], $app[ ErrorResponseBuilder::class ] ); |
|
| 74 | 74 | }); |
| 75 | 75 | |
| 76 | 76 | $this->registerAliases(); |
@@ -83,7 +83,7 @@ discard block |
||
| 83 | 83 | */ |
| 84 | 84 | public function provides() |
| 85 | 85 | { |
| 86 | - return ['responder', 'responder.success', 'responder.error', 'responder.manager', 'responder.serializer']; |
|
| 86 | + return [ 'responder', 'responder.success', 'responder.error', 'responder.manager', 'responder.serializer' ]; |
|
| 87 | 87 | } |
| 88 | 88 | |
| 89 | 89 | /** |
@@ -94,17 +94,17 @@ discard block |
||
| 94 | 94 | */ |
| 95 | 95 | protected function registerFractal() |
| 96 | 96 | { |
| 97 | - $this->app->bind(SerializerAbstract::class, function ($app) { |
|
| 98 | - $serializer = $app->config->get('responder.serializer'); |
|
| 97 | + $this->app->bind( SerializerAbstract::class, function ( $app ) { |
|
| 98 | + $serializer = $app->config->get( 'responder.serializer' ); |
|
| 99 | 99 | |
| 100 | 100 | return new $serializer; |
| 101 | 101 | }); |
| 102 | 102 | |
| 103 | - $this->app->bind(Manager::class, function ($app) { |
|
| 104 | - return (new Manager())->setSerializer($app[SerializerAbstract::class]); |
|
| 103 | + $this->app->bind( Manager::class, function ( $app ) { |
|
| 104 | + return (new Manager())->setSerializer( $app[ SerializerAbstract::class ] ); |
|
| 105 | 105 | }); |
| 106 | 106 | |
| 107 | - $this->app->bind(ResourceFactory::class, function () { |
|
| 107 | + $this->app->bind( ResourceFactory::class, function () { |
|
| 108 | 108 | return new ResourceFactory(); |
| 109 | 109 | }); |
| 110 | 110 | } |
@@ -116,16 +116,16 @@ discard block |
||
| 116 | 116 | */ |
| 117 | 117 | protected function registerResponseBuilders() |
| 118 | 118 | { |
| 119 | - $this->app->bind(SuccessResponseBuilder::class, function ($app) { |
|
| 120 | - $builder = new SuccessResponseBuilder($app[ResponseFactory::class], $app[ResourceFactory::class], $app[Manager::class]); |
|
| 119 | + $this->app->bind( SuccessResponseBuilder::class, function ( $app ) { |
|
| 120 | + $builder = new SuccessResponseBuilder( $app[ ResponseFactory::class ], $app[ ResourceFactory::class ], $app[ Manager::class ] ); |
|
| 121 | 121 | |
| 122 | - return $builder->setIncludeStatusCode($app->config->get('responder.include_status_code')); |
|
| 122 | + return $builder->setIncludeStatusCode( $app->config->get( 'responder.include_status_code' ) ); |
|
| 123 | 123 | }); |
| 124 | 124 | |
| 125 | - $this->app->bind(ErrorResponseBuilder::class, function ($app) { |
|
| 126 | - $builder = new ErrorResponseBuilder($app[ResponseFactory::class], $app['translator']); |
|
| 125 | + $this->app->bind( ErrorResponseBuilder::class, function ( $app ) { |
|
| 126 | + $builder = new ErrorResponseBuilder( $app[ ResponseFactory::class ], $app[ 'translator' ] ); |
|
| 127 | 127 | |
| 128 | - return $builder->setIncludeStatusCode($app->config->get('responder.include_status_code')); |
|
| 128 | + return $builder->setIncludeStatusCode( $app->config->get( 'responder.include_status_code' ) ); |
|
| 129 | 129 | }); |
| 130 | 130 | } |
| 131 | 131 | |
@@ -136,11 +136,11 @@ discard block |
||
| 136 | 136 | */ |
| 137 | 137 | protected function registerAliases() |
| 138 | 138 | { |
| 139 | - $this->app->alias(Responder::class, 'responder'); |
|
| 140 | - $this->app->alias(SuccessResponseBuilder::class, 'responder.success'); |
|
| 141 | - $this->app->alias(ErrorResponseBuilder::class, 'responder.error'); |
|
| 142 | - $this->app->alias(Manager::class, 'responder.manager'); |
|
| 143 | - $this->app->alias(Manager::class, 'responder.serializer'); |
|
| 139 | + $this->app->alias( Responder::class, 'responder' ); |
|
| 140 | + $this->app->alias( SuccessResponseBuilder::class, 'responder.success' ); |
|
| 141 | + $this->app->alias( ErrorResponseBuilder::class, 'responder.error' ); |
|
| 142 | + $this->app->alias( Manager::class, 'responder.manager' ); |
|
| 143 | + $this->app->alias( Manager::class, 'responder.serializer' ); |
|
| 144 | 144 | } |
| 145 | 145 | |
| 146 | 146 | /** |
@@ -150,13 +150,13 @@ discard block |
||
| 150 | 150 | */ |
| 151 | 151 | protected function bootLaravelApplication() |
| 152 | 152 | { |
| 153 | - $this->publishes([ |
|
| 154 | - __DIR__ . '/../resources/config/responder.php' => config_path('responder.php') |
|
| 155 | - ], 'config'); |
|
| 153 | + $this->publishes( [ |
|
| 154 | + __DIR__ . '/../resources/config/responder.php' => config_path( 'responder.php' ) |
|
| 155 | + ], 'config' ); |
|
| 156 | 156 | |
| 157 | - $this->publishes([ |
|
| 158 | - __DIR__ . '/../resources/lang/en/errors.php' => resource_path('lang/en/errors.php') |
|
| 159 | - ], 'lang'); |
|
| 157 | + $this->publishes( [ |
|
| 158 | + __DIR__ . '/../resources/lang/en/errors.php' => resource_path( 'lang/en/errors.php' ) |
|
| 159 | + ], 'lang' ); |
|
| 160 | 160 | } |
| 161 | 161 | |
| 162 | 162 | /** |
@@ -166,6 +166,6 @@ discard block |
||
| 166 | 166 | */ |
| 167 | 167 | protected function bootLumenApplication() |
| 168 | 168 | { |
| 169 | - $this->app->configure('responder'); |
|
| 169 | + $this->app->configure( 'responder' ); |
|
| 170 | 170 | } |
| 171 | 171 | } |
| 172 | 172 | \ No newline at end of file |
@@ -5,10 +5,7 @@ |
||
| 5 | 5 | use Flugg\Responder\Contracts\Transformable; |
| 6 | 6 | use Flugg\Responder\Exceptions\InvalidSerializerException; |
| 7 | 7 | use Flugg\Responder\Exceptions\InvalidTransformerException; |
| 8 | -use Flugg\Responder\Exceptions\SerializerNotFoundException; |
|
| 9 | 8 | use Flugg\Responder\ResourceFactory; |
| 10 | -use Flugg\Responder\ResourceResolver; |
|
| 11 | -use Flugg\Responder\Transformation; |
|
| 12 | 9 | use Flugg\Responder\Transformer; |
| 13 | 10 | use Illuminate\Contracts\Routing\ResponseFactory; |
| 14 | 11 | use Illuminate\Database\Eloquent\Model; |
@@ -39,7 +39,7 @@ discard block |
||
| 39 | 39 | * |
| 40 | 40 | * @var array |
| 41 | 41 | */ |
| 42 | - protected $meta = []; |
|
| 42 | + protected $meta = [ ]; |
|
| 43 | 43 | |
| 44 | 44 | /** |
| 45 | 45 | * The Fractal resource instance containing the data and transformer. |
@@ -69,13 +69,13 @@ discard block |
||
| 69 | 69 | * @param \Flugg\Responder\ResourceFactory $resourceFactory |
| 70 | 70 | * @param \League\Fractal\Manager $manager |
| 71 | 71 | */ |
| 72 | - public function __construct(ResponseFactory $responseFactory, ResourceFactory $resourceFactory, Manager $manager) |
|
| 72 | + public function __construct( ResponseFactory $responseFactory, ResourceFactory $resourceFactory, Manager $manager ) |
|
| 73 | 73 | { |
| 74 | 74 | $this->resourceFactory = $resourceFactory; |
| 75 | 75 | $this->manager = $manager; |
| 76 | 76 | $this->resource = $this->resourceFactory->make(); |
| 77 | 77 | |
| 78 | - parent::__construct($responseFactory); |
|
| 78 | + parent::__construct( $responseFactory ); |
|
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | /** |
@@ -84,9 +84,9 @@ discard block |
||
| 84 | 84 | * @param array $data |
| 85 | 85 | * @return self |
| 86 | 86 | */ |
| 87 | - public function addMeta(array $data):SuccessResponseBuilder |
|
| 87 | + public function addMeta( array $data ):SuccessResponseBuilder |
|
| 88 | 88 | { |
| 89 | - $this->meta = array_merge($this->meta, $data); |
|
| 89 | + $this->meta = array_merge( $this->meta, $data ); |
|
| 90 | 90 | |
| 91 | 91 | return $this; |
| 92 | 92 | } |
@@ -97,9 +97,9 @@ discard block |
||
| 97 | 97 | * @param \League\Fractal\Serializer\SerializerAbstract|string $serializer |
| 98 | 98 | * @return self |
| 99 | 99 | */ |
| 100 | - public function serializer($serializer):SuccessResponseBuilder |
|
| 100 | + public function serializer( $serializer ):SuccessResponseBuilder |
|
| 101 | 101 | { |
| 102 | - $this->manager->setSerializer($this->resolveSerializer($serializer)); |
|
| 102 | + $this->manager->setSerializer( $this->resolveSerializer( $serializer ) ); |
|
| 103 | 103 | |
| 104 | 104 | return $this; |
| 105 | 105 | } |
@@ -111,13 +111,13 @@ discard block |
||
| 111 | 111 | * @return self |
| 112 | 112 | * @throws \InvalidArgumentException |
| 113 | 113 | */ |
| 114 | - public function setStatus(int $statusCode):ResponseBuilder |
|
| 114 | + public function setStatus( int $statusCode ):ResponseBuilder |
|
| 115 | 115 | { |
| 116 | - if ($statusCode < 100 || $statusCode >= 400) { |
|
| 117 | - throw new InvalidArgumentException("{$statusCode} is not a valid success HTTP status code."); |
|
| 116 | + if ( $statusCode < 100 || $statusCode >= 400 ) { |
|
| 117 | + throw new InvalidArgumentException( "{$statusCode} is not a valid success HTTP status code." ); |
|
| 118 | 118 | } |
| 119 | 119 | |
| 120 | - return parent::setStatus($statusCode); |
|
| 120 | + return parent::setStatus( $statusCode ); |
|
| 121 | 121 | } |
| 122 | 122 | |
| 123 | 123 | /** |
@@ -129,17 +129,17 @@ discard block |
||
| 129 | 129 | * @param string|null $resourceKey |
| 130 | 130 | * @return self |
| 131 | 131 | */ |
| 132 | - public function transform($data = null, $transformer = null, string $resourceKey = null):SuccessResponseBuilder |
|
| 132 | + public function transform( $data = null, $transformer = null, string $resourceKey = null ):SuccessResponseBuilder |
|
| 133 | 133 | { |
| 134 | - $resource = $this->resourceFactory->make($data); |
|
| 134 | + $resource = $this->resourceFactory->make( $data ); |
|
| 135 | 135 | |
| 136 | - if (! is_null($resource->getData())) { |
|
| 137 | - $model = $this->resolveModel($resource->getData()); |
|
| 138 | - $transformer = $this->resolveTransformer($model, $transformer); |
|
| 139 | - $resourceKey = $this->resolveResourceKey($model, $resourceKey); |
|
| 136 | + if ( ! is_null( $resource->getData() ) ) { |
|
| 137 | + $model = $this->resolveModel( $resource->getData() ); |
|
| 138 | + $transformer = $this->resolveTransformer( $model, $transformer ); |
|
| 139 | + $resourceKey = $this->resolveResourceKey( $model, $resourceKey ); |
|
| 140 | 140 | } |
| 141 | 141 | |
| 142 | - $this->resource = $resource->setTransformer($transformer)->setResourceKey($resourceKey); |
|
| 142 | + $this->resource = $resource->setTransformer( $transformer )->setResourceKey( $resourceKey ); |
|
| 143 | 143 | |
| 144 | 144 | return $this; |
| 145 | 145 | } |
@@ -151,7 +151,7 @@ discard block |
||
| 151 | 151 | */ |
| 152 | 152 | public function toArray():array |
| 153 | 153 | { |
| 154 | - return $this->serialize($this->getResource()); |
|
| 154 | + return $this->serialize( $this->getResource() ); |
|
| 155 | 155 | } |
| 156 | 156 | |
| 157 | 157 | /** |
@@ -161,7 +161,7 @@ discard block |
||
| 161 | 161 | */ |
| 162 | 162 | public function getResource():ResourceInterface |
| 163 | 163 | { |
| 164 | - return $this->resource->setMeta($this->meta); |
|
| 164 | + return $this->resource->setMeta( $this->meta ); |
|
| 165 | 165 | } |
| 166 | 166 | |
| 167 | 167 | /** |
@@ -181,13 +181,13 @@ discard block |
||
| 181 | 181 | * @return \League\Fractal\Serializer\SerializerAbstract |
| 182 | 182 | * @throws \Flugg\Responder\Exceptions\InvalidSerializerException |
| 183 | 183 | */ |
| 184 | - protected function resolveSerializer($serializer):SerializerAbstract |
|
| 184 | + protected function resolveSerializer( $serializer ):SerializerAbstract |
|
| 185 | 185 | { |
| 186 | - if (is_string($serializer)) { |
|
| 186 | + if ( is_string( $serializer ) ) { |
|
| 187 | 187 | $serializer = new $serializer; |
| 188 | 188 | } |
| 189 | 189 | |
| 190 | - if (! $serializer instanceof SerializerAbstract) { |
|
| 190 | + if ( ! $serializer instanceof SerializerAbstract ) { |
|
| 191 | 191 | throw new InvalidSerializerException(); |
| 192 | 192 | } |
| 193 | 193 | |
@@ -201,15 +201,15 @@ discard block |
||
| 201 | 201 | * @return \Illuminate\Database\Eloquent\Model |
| 202 | 202 | * @throws \InvalidArgumentException |
| 203 | 203 | */ |
| 204 | - protected function resolveModel($data):Model |
|
| 204 | + protected function resolveModel( $data ):Model |
|
| 205 | 205 | { |
| 206 | - if ($data instanceof Model) { |
|
| 206 | + if ( $data instanceof Model ) { |
|
| 207 | 207 | return $data; |
| 208 | 208 | } |
| 209 | 209 | |
| 210 | - $model = $data[0]; |
|
| 211 | - if (! $model instanceof Model) { |
|
| 212 | - throw new InvalidArgumentException('You can only transform data containing Eloquent models.'); |
|
| 210 | + $model = $data[ 0 ]; |
|
| 211 | + if ( ! $model instanceof Model ) { |
|
| 212 | + throw new InvalidArgumentException( 'You can only transform data containing Eloquent models.' ); |
|
| 213 | 213 | } |
| 214 | 214 | |
| 215 | 215 | return $model; |
@@ -222,15 +222,15 @@ discard block |
||
| 222 | 222 | * @param \Flugg\Responder\Transformer|callable|null $transformer |
| 223 | 223 | * @return \Flugg\Responder\Transformer|callable |
| 224 | 224 | */ |
| 225 | - protected function resolveTransformer(Model $model, $transformer = null) |
|
| 225 | + protected function resolveTransformer( Model $model, $transformer = null ) |
|
| 226 | 226 | { |
| 227 | - $transformer = $transformer ?: $this->resolveTransformerFromModel($model); |
|
| 227 | + $transformer = $transformer ?: $this->resolveTransformerFromModel( $model ); |
|
| 228 | 228 | |
| 229 | - if (is_string($transformer)) { |
|
| 229 | + if ( is_string( $transformer ) ) { |
|
| 230 | 230 | $transformer = new $transformer; |
| 231 | 231 | } |
| 232 | 232 | |
| 233 | - return $this->parseTransformer($transformer, $model); |
|
| 233 | + return $this->parseTransformer( $transformer, $model ); |
|
| 234 | 234 | } |
| 235 | 235 | |
| 236 | 236 | /** |
@@ -240,9 +240,9 @@ discard block |
||
| 240 | 240 | * @param \Illuminate\Database\ELoquent\Model $model |
| 241 | 241 | * @return \Flugg\Responder\Transformer|callable |
| 242 | 242 | */ |
| 243 | - protected function resolveTransformerFromModel(Model $model) |
|
| 243 | + protected function resolveTransformerFromModel( Model $model ) |
|
| 244 | 244 | { |
| 245 | - if (! $model instanceof Transformable) { |
|
| 245 | + if ( ! $model instanceof Transformable ) { |
|
| 246 | 246 | return function () use ($model) { |
| 247 | 247 | return $model->toArray(); |
| 248 | 248 | }; |
@@ -259,14 +259,14 @@ discard block |
||
| 259 | 259 | * @return \Flugg\Responder\Transformer|callable |
| 260 | 260 | * @throws \InvalidTransformerException |
| 261 | 261 | */ |
| 262 | - protected function parseTransformer($transformer, Model $model) |
|
| 262 | + protected function parseTransformer( $transformer, Model $model ) |
|
| 263 | 263 | { |
| 264 | - if ($transformer instanceof Transformer) { |
|
| 265 | - $transformer = $transformer->setRelations($this->resolveRelations($model)); |
|
| 266 | - $this->manager->parseIncludes($transformer->getRelations()); |
|
| 264 | + if ( $transformer instanceof Transformer ) { |
|
| 265 | + $transformer = $transformer->setRelations( $this->resolveRelations( $model ) ); |
|
| 266 | + $this->manager->parseIncludes( $transformer->getRelations() ); |
|
| 267 | 267 | |
| 268 | - } elseif (! is_callable($transformer)) { |
|
| 269 | - throw new InvalidTransformerException($model); |
|
| 268 | + } elseif ( ! is_callable( $transformer ) ) { |
|
| 269 | + throw new InvalidTransformerException( $model ); |
|
| 270 | 270 | } |
| 271 | 271 | |
| 272 | 272 | return $transformer; |
@@ -278,9 +278,9 @@ discard block |
||
| 278 | 278 | * @param \Illuminate\Database\Eloquent\Model $model |
| 279 | 279 | * @return array |
| 280 | 280 | */ |
| 281 | - protected function resolveRelations(Model $model):array |
|
| 281 | + protected function resolveRelations( Model $model ):array |
|
| 282 | 282 | { |
| 283 | - return array_keys($model->getRelations()); |
|
| 283 | + return array_keys( $model->getRelations() ); |
|
| 284 | 284 | } |
| 285 | 285 | |
| 286 | 286 | /** |
@@ -290,13 +290,13 @@ discard block |
||
| 290 | 290 | * @param string|null $resourceKey |
| 291 | 291 | * @return string |
| 292 | 292 | */ |
| 293 | - protected function resolveResourceKey(Model $model, string $resourceKey = null):string |
|
| 293 | + protected function resolveResourceKey( Model $model, string $resourceKey = null ):string |
|
| 294 | 294 | { |
| 295 | - if (! is_null($resourceKey)) { |
|
| 295 | + if ( ! is_null( $resourceKey ) ) { |
|
| 296 | 296 | return $resourceKey; |
| 297 | 297 | } |
| 298 | 298 | |
| 299 | - if (method_exists($model, 'getResourceKey')) { |
|
| 299 | + if ( method_exists( $model, 'getResourceKey' ) ) { |
|
| 300 | 300 | return $model->getResourceKey(); |
| 301 | 301 | } |
| 302 | 302 | |
@@ -309,8 +309,8 @@ discard block |
||
| 309 | 309 | * @param ResourceInterface $resource |
| 310 | 310 | * @return array |
| 311 | 311 | */ |
| 312 | - protected function serialize(ResourceInterface $resource):array |
|
| 312 | + protected function serialize( ResourceInterface $resource ):array |
|
| 313 | 313 | { |
| 314 | - return $this->manager->createData($resource)->toArray(); |
|
| 314 | + return $this->manager->createData( $resource )->toArray(); |
|
| 315 | 315 | } |
| 316 | 316 | } |
| 317 | 317 | \ No newline at end of file |
@@ -23,7 +23,7 @@ discard block |
||
| 23 | 23 | */ |
| 24 | 24 | public function getRelations():array |
| 25 | 25 | { |
| 26 | - return array_merge($this->getAvailableIncludes(), $this->getDefaultIncludes()); |
|
| 26 | + return array_merge( $this->getAvailableIncludes(), $this->getDefaultIncludes() ); |
|
| 27 | 27 | } |
| 28 | 28 | |
| 29 | 29 | /** |
@@ -32,9 +32,9 @@ discard block |
||
| 32 | 32 | * @param array|string $relations |
| 33 | 33 | * @return self |
| 34 | 34 | */ |
| 35 | - public function setRelations($relations) |
|
| 35 | + public function setRelations( $relations ) |
|
| 36 | 36 | { |
| 37 | - $this->setAvailableIncludes(array_merge($this->availableIncludes, (array) $relations)); |
|
| 37 | + $this->setAvailableIncludes( array_merge( $this->availableIncludes, (array) $relations ) ); |
|
| 38 | 38 | |
| 39 | 39 | return $this; |
| 40 | 40 | } |
@@ -49,13 +49,13 @@ discard block |
||
| 49 | 49 | * @return \League\Fractal\Resource\ResourceInterface|bool |
| 50 | 50 | * @throws \Exception |
| 51 | 51 | */ |
| 52 | - protected function callIncludeMethod(Scope $scope, $includeName, $data) |
|
| 52 | + protected function callIncludeMethod( Scope $scope, $includeName, $data ) |
|
| 53 | 53 | { |
| 54 | - if ($includeName === 'pivot') { |
|
| 55 | - return $this->includePivot($data->$includeName); |
|
| 54 | + if ( $includeName === 'pivot' ) { |
|
| 55 | + return $this->includePivot( $data->$includeName ); |
|
| 56 | 56 | } |
| 57 | 57 | |
| 58 | - return app(Responder::class)->transform($data->$includeName)->getResource(); |
|
| 58 | + return app( Responder::class )->transform( $data->$includeName )->getResource(); |
|
| 59 | 59 | } |
| 60 | 60 | |
| 61 | 61 | /** |
@@ -64,14 +64,14 @@ discard block |
||
| 64 | 64 | * @param Pivot $pivot |
| 65 | 65 | * @return \League\Fractal\Resource\ResourceInterface|bool |
| 66 | 66 | */ |
| 67 | - protected function includePivot(Pivot $pivot) |
|
| 67 | + protected function includePivot( Pivot $pivot ) |
|
| 68 | 68 | { |
| 69 | - if (! method_exists($this, 'transformPivot')) { |
|
| 69 | + if ( ! method_exists( $this, 'transformPivot' ) ) { |
|
| 70 | 70 | return false; |
| 71 | 71 | } |
| 72 | 72 | |
| 73 | - return app(Responder::class)->transform($pivot, function () use ($pivot) { |
|
| 74 | - return $this->transformPivot($pivot); |
|
| 73 | + return app( Responder::class )->transform( $pivot, function () use ($pivot) { |
|
| 74 | + return $this->transformPivot( $pivot ); |
|
| 75 | 75 | })->getResource(); |
| 76 | 76 | } |
| 77 | 77 | } |
| 78 | 78 | \ No newline at end of file |
@@ -22,9 +22,9 @@ discard block |
||
| 22 | 22 | * @param array $data |
| 23 | 23 | * @return array |
| 24 | 24 | */ |
| 25 | - public function collection($resourceKey, array $data) |
|
| 25 | + public function collection( $resourceKey, array $data ) |
|
| 26 | 26 | { |
| 27 | - return $this->item($resourceKey, $data); |
|
| 27 | + return $this->item( $resourceKey, $data ); |
|
| 28 | 28 | } |
| 29 | 29 | |
| 30 | 30 | /** |
@@ -34,11 +34,11 @@ discard block |
||
| 34 | 34 | * @param array $data |
| 35 | 35 | * @return array |
| 36 | 36 | */ |
| 37 | - public function item($resourceKey, array $data) |
|
| 37 | + public function item( $resourceKey, array $data ) |
|
| 38 | 38 | { |
| 39 | - return array_merge($this->null(), [ |
|
| 39 | + return array_merge( $this->null(), [ |
|
| 40 | 40 | 'data' => $data |
| 41 | - ]); |
|
| 41 | + ] ); |
|
| 42 | 42 | } |
| 43 | 43 | |
| 44 | 44 | /** |
@@ -60,7 +60,7 @@ discard block |
||
| 60 | 60 | * @param array $meta |
| 61 | 61 | * @return array |
| 62 | 62 | */ |
| 63 | - public function meta(array $meta) |
|
| 63 | + public function meta( array $meta ) |
|
| 64 | 64 | { |
| 65 | 65 | return $meta; |
| 66 | 66 | } |
@@ -72,19 +72,19 @@ discard block |
||
| 72 | 72 | * |
| 73 | 73 | * @return array |
| 74 | 74 | */ |
| 75 | - public function paginator(PaginatorInterface $paginator) |
|
| 75 | + public function paginator( PaginatorInterface $paginator ) |
|
| 76 | 76 | { |
| 77 | - $pagination = parent::paginator($paginator)['pagination']; |
|
| 77 | + $pagination = parent::paginator( $paginator )[ 'pagination' ]; |
|
| 78 | 78 | |
| 79 | 79 | $data = [ |
| 80 | - 'total' => $pagination['total'], |
|
| 81 | - 'count' => $pagination['count'], |
|
| 82 | - 'perPage' => $pagination['per_page'], |
|
| 83 | - 'currentPage' => $pagination['current_page'], |
|
| 84 | - 'totalPages' => $pagination['total_pages'], |
|
| 80 | + 'total' => $pagination[ 'total' ], |
|
| 81 | + 'count' => $pagination[ 'count' ], |
|
| 82 | + 'perPage' => $pagination[ 'per_page' ], |
|
| 83 | + 'currentPage' => $pagination[ 'current_page' ], |
|
| 84 | + 'totalPages' => $pagination[ 'total_pages' ], |
|
| 85 | 85 | ]; |
| 86 | 86 | |
| 87 | - return ['pagination' => $data]; |
|
| 87 | + return [ 'pagination' => $data ]; |
|
| 88 | 88 | } |
| 89 | 89 | |
| 90 | 90 | /** |
@@ -104,15 +104,15 @@ discard block |
||
| 104 | 104 | * @param array $includedData |
| 105 | 105 | * @return array |
| 106 | 106 | */ |
| 107 | - public function mergeIncludes($transformedData, $includedData) |
|
| 107 | + public function mergeIncludes( $transformedData, $includedData ) |
|
| 108 | 108 | { |
| 109 | - $keys = array_keys($includedData); |
|
| 109 | + $keys = array_keys( $includedData ); |
|
| 110 | 110 | |
| 111 | - foreach ($keys as $key) { |
|
| 112 | - $includedData[$key] = $includedData[$key]['data']; |
|
| 111 | + foreach ( $keys as $key ) { |
|
| 112 | + $includedData[ $key ] = $includedData[ $key ][ 'data' ]; |
|
| 113 | 113 | } |
| 114 | 114 | |
| 115 | - return array_merge($transformedData, $includedData); |
|
| 115 | + return array_merge( $transformedData, $includedData ); |
|
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | /** |
@@ -123,8 +123,8 @@ discard block |
||
| 123 | 123 | * |
| 124 | 124 | * @return array |
| 125 | 125 | */ |
| 126 | - public function includedData(ResourceInterface $resource, array $data) |
|
| 126 | + public function includedData( ResourceInterface $resource, array $data ) |
|
| 127 | 127 | { |
| 128 | - return []; |
|
| 128 | + return [ ]; |
|
| 129 | 129 | } |
| 130 | 130 | } |
| 131 | 131 | \ No newline at end of file |
@@ -21,7 +21,7 @@ discard block |
||
| 21 | 21 | * |
| 22 | 22 | * @var array |
| 23 | 23 | */ |
| 24 | - protected $data = []; |
|
| 24 | + protected $data = [ ]; |
|
| 25 | 25 | |
| 26 | 26 | /** |
| 27 | 27 | * The error code used to identify the error. |
@@ -42,7 +42,7 @@ discard block |
||
| 42 | 42 | * |
| 43 | 43 | * @var array |
| 44 | 44 | */ |
| 45 | - protected $parameters = []; |
|
| 45 | + protected $parameters = [ ]; |
|
| 46 | 46 | |
| 47 | 47 | /** |
| 48 | 48 | * The HTTP status code for the response. |
@@ -64,11 +64,11 @@ discard block |
||
| 64 | 64 | * @param \Illuminate\Contracts\Routing\ResponseFactory $responseFactory |
| 65 | 65 | * @param \Symfony\Component\Translation\TranslatorInterface $translator |
| 66 | 66 | */ |
| 67 | - public function __construct(ResponseFactory $responseFactory, TranslatorInterface $translator) |
|
| 67 | + public function __construct( ResponseFactory $responseFactory, TranslatorInterface $translator ) |
|
| 68 | 68 | { |
| 69 | 69 | $this->translator = $translator; |
| 70 | 70 | |
| 71 | - parent::__construct($responseFactory); |
|
| 71 | + parent::__construct( $responseFactory ); |
|
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | /** |
@@ -77,9 +77,9 @@ discard block |
||
| 77 | 77 | * @param array $data |
| 78 | 78 | * @return self |
| 79 | 79 | */ |
| 80 | - public function addData(array $data):ErrorResponseBuilder |
|
| 80 | + public function addData( array $data ):ErrorResponseBuilder |
|
| 81 | 81 | { |
| 82 | - $this->data = array_merge($this->data, $data); |
|
| 82 | + $this->data = array_merge( $this->data, $data ); |
|
| 83 | 83 | |
| 84 | 84 | return $this; |
| 85 | 85 | } |
@@ -91,11 +91,11 @@ discard block |
||
| 91 | 91 | * @param string|array|null $message |
| 92 | 92 | * @return self |
| 93 | 93 | */ |
| 94 | - public function setError(string $errorCode = null, $message = null):ErrorResponseBuilder |
|
| 94 | + public function setError( string $errorCode = null, $message = null ):ErrorResponseBuilder |
|
| 95 | 95 | { |
| 96 | 96 | $this->errorCode = $errorCode; |
| 97 | 97 | |
| 98 | - if (is_array($message)) { |
|
| 98 | + if ( is_array( $message ) ) { |
|
| 99 | 99 | $this->parameters = $message; |
| 100 | 100 | } else { |
| 101 | 101 | $this->message = $message; |
@@ -111,13 +111,13 @@ discard block |
||
| 111 | 111 | * @return self |
| 112 | 112 | * @throws \InvalidArgumentException |
| 113 | 113 | */ |
| 114 | - public function setStatus(int $statusCode):ResponseBuilder |
|
| 114 | + public function setStatus( int $statusCode ):ResponseBuilder |
|
| 115 | 115 | { |
| 116 | - if ($statusCode < 400 || $statusCode >= 600) { |
|
| 117 | - throw new InvalidArgumentException("{$statusCode} is not a valid error HTTP status code."); |
|
| 116 | + if ( $statusCode < 400 || $statusCode >= 600 ) { |
|
| 117 | + throw new InvalidArgumentException( "{$statusCode} is not a valid error HTTP status code." ); |
|
| 118 | 118 | } |
| 119 | 119 | |
| 120 | - return parent::setStatus($statusCode); |
|
| 120 | + return parent::setStatus( $statusCode ); |
|
| 121 | 121 | } |
| 122 | 122 | |
| 123 | 123 | /** |
@@ -140,7 +140,7 @@ discard block |
||
| 140 | 140 | */ |
| 141 | 141 | protected function buildErrorData() |
| 142 | 142 | { |
| 143 | - if (is_null($this->errorCode)) { |
|
| 143 | + if ( is_null( $this->errorCode ) ) { |
|
| 144 | 144 | return null; |
| 145 | 145 | } |
| 146 | 146 | |
@@ -149,7 +149,7 @@ discard block |
||
| 149 | 149 | 'message' => $this->message ?: $this->resolveMessage() |
| 150 | 150 | ]; |
| 151 | 151 | |
| 152 | - return array_merge($data, $this->data); |
|
| 152 | + return array_merge( $data, $this->data ); |
|
| 153 | 153 | } |
| 154 | 154 | |
| 155 | 155 | /** |
@@ -159,10 +159,10 @@ discard block |
||
| 159 | 159 | */ |
| 160 | 160 | protected function resolveMessage() |
| 161 | 161 | { |
| 162 | - if (! $this->translator->has($code = "errors.$this->errorCode")) { |
|
| 162 | + if ( ! $this->translator->has( $code = "errors.$this->errorCode" ) ) { |
|
| 163 | 163 | return null; |
| 164 | 164 | } |
| 165 | 165 | |
| 166 | - return $this->translator->trans($code, $this->parameters); |
|
| 166 | + return $this->translator->trans( $code, $this->parameters ); |
|
| 167 | 167 | } |
| 168 | 168 | } |
| 169 | 169 | \ No newline at end of file |
@@ -2,7 +2,7 @@ discard block |
||
| 2 | 2 | |
| 3 | 3 | use Flugg\Responder\Responder; |
| 4 | 4 | |
| 5 | -if (! function_exists('responder')) { |
|
| 5 | +if ( ! function_exists( 'responder' ) ) { |
|
| 6 | 6 | |
| 7 | 7 | /** |
| 8 | 8 | * A helper method to quickly resolve the responder out of the service container. |
@@ -11,6 +11,6 @@ discard block |
||
| 11 | 11 | */ |
| 12 | 12 | function responder() |
| 13 | 13 | { |
| 14 | - return app(Responder::class); |
|
| 14 | + return app( Responder::class ); |
|
| 15 | 15 | } |
| 16 | 16 | } |
| 17 | 17 | \ No newline at end of file |
@@ -46,17 +46,17 @@ discard block |
||
| 46 | 46 | * @param mixed|null $data |
| 47 | 47 | * @return \League\Fractal\Resource\ResourceInterface |
| 48 | 48 | */ |
| 49 | - public function make($data = null) |
|
| 49 | + public function make( $data = null ) |
|
| 50 | 50 | { |
| 51 | - if (is_null($data)) { |
|
| 51 | + if ( is_null( $data ) ) { |
|
| 52 | 52 | return new NullResource(); |
| 53 | - } elseif (is_array($data)) { |
|
| 54 | - return static::makeFromArray($data); |
|
| 53 | + } elseif ( is_array( $data ) ) { |
|
| 54 | + return static::makeFromArray( $data ); |
|
| 55 | 55 | } |
| 56 | 56 | |
| 57 | - $method = static::getMakeMethod($data); |
|
| 57 | + $method = static::getMakeMethod( $data ); |
|
| 58 | 58 | |
| 59 | - return static::$method($data); |
|
| 59 | + return static::$method( $data ); |
|
| 60 | 60 | } |
| 61 | 61 | |
| 62 | 62 | /** |
@@ -66,15 +66,15 @@ discard block |
||
| 66 | 66 | * @return string |
| 67 | 67 | * @throws \InvalidArgumentException |
| 68 | 68 | */ |
| 69 | - protected function getMakeMethod($data):string |
|
| 69 | + protected function getMakeMethod( $data ):string |
|
| 70 | 70 | { |
| 71 | - foreach (static::MAKE_METHODS as $class => $method) { |
|
| 72 | - if ($data instanceof $class) { |
|
| 71 | + foreach ( static::MAKE_METHODS as $class => $method ) { |
|
| 72 | + if ( $data instanceof $class ) { |
|
| 73 | 73 | return $method; |
| 74 | 74 | } |
| 75 | 75 | } |
| 76 | 76 | |
| 77 | - throw new InvalidArgumentException('Given data cannot be transformed.'); |
|
| 77 | + throw new InvalidArgumentException( 'Given data cannot be transformed.' ); |
|
| 78 | 78 | } |
| 79 | 79 | |
| 80 | 80 | /** |
@@ -83,9 +83,9 @@ discard block |
||
| 83 | 83 | * @param \Illuminate\Database\Eloquent\Model $model |
| 84 | 84 | * @return \League\Fractal\Resource\ResourceInterface |
| 85 | 85 | */ |
| 86 | - protected function makeFromModel(Model $model):ResourceInterface |
|
| 86 | + protected function makeFromModel( Model $model ):ResourceInterface |
|
| 87 | 87 | { |
| 88 | - return new ItemResource($model); |
|
| 88 | + return new ItemResource( $model ); |
|
| 89 | 89 | } |
| 90 | 90 | |
| 91 | 91 | /** |
@@ -94,9 +94,9 @@ discard block |
||
| 94 | 94 | * @param array $array |
| 95 | 95 | * @return \League\Fractal\Resource\ResourceInterface |
| 96 | 96 | */ |
| 97 | - protected function makeFromArray(array $array):ResourceInterface |
|
| 97 | + protected function makeFromArray( array $array ):ResourceInterface |
|
| 98 | 98 | { |
| 99 | - return empty($array) ? new NullResource() : new CollectionResource($array); |
|
| 99 | + return empty($array) ? new NullResource() : new CollectionResource( $array ); |
|
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | /** |
@@ -105,9 +105,9 @@ discard block |
||
| 105 | 105 | * @param \Illuminate\Support\Collection $collection |
| 106 | 106 | * @return \League\Fractal\Resource\ResourceInterface |
| 107 | 107 | */ |
| 108 | - protected function makeFromCollection(Collection $collection):ResourceInterface |
|
| 108 | + protected function makeFromCollection( Collection $collection ):ResourceInterface |
|
| 109 | 109 | { |
| 110 | - return static::makeFromArray($collection->all()); |
|
| 110 | + return static::makeFromArray( $collection->all() ); |
|
| 111 | 111 | } |
| 112 | 112 | |
| 113 | 113 | /** |
@@ -116,9 +116,9 @@ discard block |
||
| 116 | 116 | * @param \Illuminate\Database\Eloquent\Builder $query |
| 117 | 117 | * @return \League\Fractal\Resource\ResourceInterface |
| 118 | 118 | */ |
| 119 | - protected function makeFromBuilder(Builder $query):ResourceInterface |
|
| 119 | + protected function makeFromBuilder( Builder $query ):ResourceInterface |
|
| 120 | 120 | { |
| 121 | - return static::makeFromCollection($query->get()); |
|
| 121 | + return static::makeFromCollection( $query->get() ); |
|
| 122 | 122 | } |
| 123 | 123 | |
| 124 | 124 | /** |
@@ -127,12 +127,12 @@ discard block |
||
| 127 | 127 | * @param \Illuminate\Contracts\Pagination\LengthAwarePaginator $paginator |
| 128 | 128 | * @return \League\Fractal\Resource\ResourceInterface |
| 129 | 129 | */ |
| 130 | - protected function makeFromPaginator(Paginator $paginator):ResourceInterface |
|
| 130 | + protected function makeFromPaginator( Paginator $paginator ):ResourceInterface |
|
| 131 | 131 | { |
| 132 | - $resource = static::makeFromCollection($paginator->getCollection()); |
|
| 132 | + $resource = static::makeFromCollection( $paginator->getCollection() ); |
|
| 133 | 133 | |
| 134 | - if ($resource instanceof CollectionResource) { |
|
| 135 | - $resource->setPaginator(new IlluminatePaginatorAdapter($paginator)); |
|
| 134 | + if ( $resource instanceof CollectionResource ) { |
|
| 135 | + $resource->setPaginator( new IlluminatePaginatorAdapter( $paginator ) ); |
|
| 136 | 136 | } |
| 137 | 137 | |
| 138 | 138 | return $resource; |
@@ -144,9 +144,9 @@ discard block |
||
| 144 | 144 | * @param \Illuminate\Database\Eloquent\Relations\Pivot $pivot |
| 145 | 145 | * @return \League\Fractal\Resource\ResourceInterface |
| 146 | 146 | */ |
| 147 | - protected function makeFromPivot(Pivot $pivot):ResourceInterface |
|
| 147 | + protected function makeFromPivot( Pivot $pivot ):ResourceInterface |
|
| 148 | 148 | { |
| 149 | - return static::makeFromModel($pivot); |
|
| 149 | + return static::makeFromModel( $pivot ); |
|
| 150 | 150 | } |
| 151 | 151 | |
| 152 | 152 | /** |
@@ -155,8 +155,8 @@ discard block |
||
| 155 | 155 | * @param \Illuminate\Database\Eloquent\Relations\Relation $relation |
| 156 | 156 | * @return \League\Fractal\Resource\ResourceInterface |
| 157 | 157 | */ |
| 158 | - protected function makeFromRelation(Relation $relation):ResourceInterface |
|
| 158 | + protected function makeFromRelation( Relation $relation ):ResourceInterface |
|
| 159 | 159 | { |
| 160 | - return static::makeFromCollection($relation->get()); |
|
| 160 | + return static::makeFromCollection( $relation->get() ); |
|
| 161 | 161 | } |
| 162 | 162 | } |
| 163 | 163 | \ No newline at end of file |
@@ -39,7 +39,7 @@ discard block |
||
| 39 | 39 | * |
| 40 | 40 | * @param Validator $validator |
| 41 | 41 | */ |
| 42 | - public function __construct(Validator $validator) |
|
| 42 | + public function __construct( Validator $validator ) |
|
| 43 | 43 | { |
| 44 | 44 | $this->validator = $validator; |
| 45 | 45 | |
@@ -53,6 +53,6 @@ discard block |
||
| 53 | 53 | */ |
| 54 | 54 | public function getData() |
| 55 | 55 | { |
| 56 | - return ['fields' => $this->validator->getMessageBag()->toArray()]; |
|
| 56 | + return [ 'fields' => $this->validator->getMessageBag()->toArray() ]; |
|
| 57 | 57 | } |
| 58 | 58 | } |
| 59 | 59 | \ No newline at end of file |
@@ -34,9 +34,9 @@ |
||
| 34 | 34 | * |
| 35 | 35 | * @param mixed $message |
| 36 | 36 | */ |
| 37 | - public function __construct($message = null) |
|
| 37 | + public function __construct( $message = null ) |
|
| 38 | 38 | { |
| 39 | - parent::__construct($this->statusCode, $message); |
|
| 39 | + parent::__construct( $this->statusCode, $message ); |
|
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | /** |