@@ -39,7 +39,7 @@ discard block |
||
| 39 | 39 | * @param \Flugg\Responder\Resources\DataNormalizer $normalizer |
| 40 | 40 | * @param \Flugg\Responder\Contracts\Transformers\TransformerResolver $transformerResolver |
| 41 | 41 | */ |
| 42 | - public function __construct(DataNormalizer $normalizer, TransformerResolver $transformerResolver) |
|
| 42 | + public function __construct( DataNormalizer $normalizer, TransformerResolver $transformerResolver ) |
|
| 43 | 43 | { |
| 44 | 44 | $this->normalizer = $normalizer; |
| 45 | 45 | $this->transformerResolver = $transformerResolver; |
@@ -53,17 +53,17 @@ discard block |
||
| 53 | 53 | * @param string|null $resourceKey |
| 54 | 54 | * @return \League\Fractal\Resource\ResourceInterface |
| 55 | 55 | */ |
| 56 | - public function make($data = null, $transformer = null, string $resourceKey = null): ResourceInterface |
|
| 56 | + public function make( $data = null, $transformer = null, string $resourceKey = null ): ResourceInterface |
|
| 57 | 57 | { |
| 58 | - if ($data instanceof ResourceInterface) { |
|
| 59 | - return $data->setTransformer($this->resolveTransformer($data->getData(), $transformer)); |
|
| 60 | - } elseif (is_null($data = $this->normalizer->normalize($data))) { |
|
| 61 | - return $this->instatiateResource($data); |
|
| 58 | + if ( $data instanceof ResourceInterface ) { |
|
| 59 | + return $data->setTransformer( $this->resolveTransformer( $data->getData(), $transformer ) ); |
|
| 60 | + } elseif ( is_null( $data = $this->normalizer->normalize( $data ) ) ) { |
|
| 61 | + return $this->instatiateResource( $data ); |
|
| 62 | 62 | } |
| 63 | 63 | |
| 64 | - $transformer = $this->resolveTransformer($data, $transformer); |
|
| 64 | + $transformer = $this->resolveTransformer( $data, $transformer ); |
|
| 65 | 65 | |
| 66 | - return $this->instatiateResource($data, $transformer, $resourceKey); |
|
| 66 | + return $this->instatiateResource( $data, $transformer, $resourceKey ); |
|
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | /** |
@@ -73,13 +73,13 @@ discard block |
||
| 73 | 73 | * @param \Flugg\Responder\Transformers\Transformer|string|callable|null $transformer |
| 74 | 74 | * @return \Flugg\Responder\Transformers\Transformer|callable |
| 75 | 75 | */ |
| 76 | - protected function resolveTransformer($data, $transformer) |
|
| 76 | + protected function resolveTransformer( $data, $transformer ) |
|
| 77 | 77 | { |
| 78 | - if (isset($transformer)) { |
|
| 79 | - return $this->transformerResolver->resolve($transformer); |
|
| 78 | + if ( isset($transformer) ) { |
|
| 79 | + return $this->transformerResolver->resolve( $transformer ); |
|
| 80 | 80 | } |
| 81 | 81 | |
| 82 | - return $this->transformerResolver->resolveFromData($data); |
|
| 82 | + return $this->transformerResolver->resolveFromData( $data ); |
|
| 83 | 83 | } |
| 84 | 84 | |
| 85 | 85 | /** |
@@ -90,14 +90,14 @@ discard block |
||
| 90 | 90 | * @param string|null $resourceKey |
| 91 | 91 | * @return \League\Fractal\Resource\ResourceInterface |
| 92 | 92 | */ |
| 93 | - protected function instatiateResource($data, $transformer = null, string $resourceKey = null): ResourceInterface |
|
| 93 | + protected function instatiateResource( $data, $transformer = null, string $resourceKey = null ): ResourceInterface |
|
| 94 | 94 | { |
| 95 | - if (is_null($data)) { |
|
| 95 | + if ( is_null( $data ) ) { |
|
| 96 | 96 | return new NullResource(); |
| 97 | - } elseif (is_array($data) || $data instanceof Traversable) { |
|
| 98 | - return new CollectionResource($data, $transformer, $resourceKey); |
|
| 97 | + } elseif ( is_array( $data ) || $data instanceof Traversable ) { |
|
| 98 | + return new CollectionResource( $data, $transformer, $resourceKey ); |
|
| 99 | 99 | } |
| 100 | 100 | |
| 101 | - return new ItemResource($data, $transformer, $resourceKey); |
|
| 101 | + return new ItemResource( $data, $transformer, $resourceKey ); |
|
| 102 | 102 | } |
| 103 | 103 | } |
| 104 | 104 | \ No newline at end of file |
@@ -34,11 +34,11 @@ discard block |
||
| 34 | 34 | * @param \Exception $exception |
| 35 | 35 | * @return void |
| 36 | 36 | */ |
| 37 | - protected function transformException(Exception $exception) |
|
| 37 | + protected function transformException( Exception $exception ) |
|
| 38 | 38 | { |
| 39 | - $this->transformHttpException($exception); |
|
| 40 | - $this->transformEloquentException($exception); |
|
| 41 | - $this->transformValidationException($exception); |
|
| 39 | + $this->transformHttpException( $exception ); |
|
| 40 | + $this->transformEloquentException( $exception ); |
|
| 41 | + $this->transformValidationException( $exception ); |
|
| 42 | 42 | } |
| 43 | 43 | |
| 44 | 44 | /** |
@@ -48,17 +48,17 @@ discard block |
||
| 48 | 48 | * @return void |
| 49 | 49 | * @throws \Flugg\Responder\Exceptions\Http\PageNotFoundException |
| 50 | 50 | */ |
| 51 | - protected function transformHttpException(Exception $exception) |
|
| 51 | + protected function transformHttpException( Exception $exception ) |
|
| 52 | 52 | { |
| 53 | - if ($exception instanceof AuthenticationException) { |
|
| 53 | + if ( $exception instanceof AuthenticationException ) { |
|
| 54 | 54 | throw new UnauthenticatedException; |
| 55 | 55 | } |
| 56 | 56 | |
| 57 | - if ($exception instanceof AuthorizationException) { |
|
| 57 | + if ( $exception instanceof AuthorizationException ) { |
|
| 58 | 58 | throw new UnauthorizedException; |
| 59 | 59 | } |
| 60 | 60 | |
| 61 | - if ($exception instanceof NotFoundHttpException) { |
|
| 61 | + if ( $exception instanceof NotFoundHttpException ) { |
|
| 62 | 62 | throw new PageNotFoundException; |
| 63 | 63 | } |
| 64 | 64 | } |
@@ -71,13 +71,13 @@ discard block |
||
| 71 | 71 | * @throws \Flugg\Responder\Exceptions\Http\ResourceNotFoundException |
| 72 | 72 | * @throws \Flugg\Responder\Exceptions\Http\RelationNotFoundException |
| 73 | 73 | */ |
| 74 | - protected function transformEloquentException(Exception $exception) |
|
| 74 | + protected function transformEloquentException( Exception $exception ) |
|
| 75 | 75 | { |
| 76 | - if ($exception instanceof ModelNotFoundException) { |
|
| 76 | + if ( $exception instanceof ModelNotFoundException ) { |
|
| 77 | 77 | throw new ResourceNotFoundException; |
| 78 | 78 | } |
| 79 | 79 | |
| 80 | - if ($exception instanceof BaseRelationNotFoundException) { |
|
| 80 | + if ( $exception instanceof BaseRelationNotFoundException ) { |
|
| 81 | 81 | throw new RelationNotFoundException; |
| 82 | 82 | } |
| 83 | 83 | } |
@@ -89,10 +89,10 @@ discard block |
||
| 89 | 89 | * @return void |
| 90 | 90 | * @throws \Flugg\Responder\Exceptions\Http\ValidationFailedException |
| 91 | 91 | */ |
| 92 | - protected function transformValidationException(Exception $exception) |
|
| 92 | + protected function transformValidationException( Exception $exception ) |
|
| 93 | 93 | { |
| 94 | - if ($exception instanceof ValidationException) { |
|
| 95 | - throw new ValidationFailedException($exception->validator); |
|
| 94 | + if ( $exception instanceof ValidationException ) { |
|
| 95 | + throw new ValidationFailedException( $exception->validator ); |
|
| 96 | 96 | } |
| 97 | 97 | } |
| 98 | 98 | |
@@ -102,11 +102,11 @@ discard block |
||
| 102 | 102 | * @param \Flugg\Responder\Exceptions\Http\ApiException $exception |
| 103 | 103 | * @return \Illuminate\Http\JsonResponse |
| 104 | 104 | */ |
| 105 | - protected function renderApiError(ApiException $exception): JsonResponse |
|
| 105 | + protected function renderApiError( ApiException $exception ): JsonResponse |
|
| 106 | 106 | { |
| 107 | - return $this->container->make(ErrorResponseBuilder::class) |
|
| 108 | - ->error($exception->errorCode(), $exception->message()) |
|
| 109 | - ->data($exception->data()) |
|
| 110 | - ->respond($exception->statusCode()); |
|
| 107 | + return $this->container->make( ErrorResponseBuilder::class ) |
|
| 108 | + ->error( $exception->errorCode(), $exception->message() ) |
|
| 109 | + ->data( $exception->data() ) |
|
| 110 | + ->respond( $exception->statusCode() ); |
|
| 111 | 111 | } |
| 112 | 112 | } |
| 113 | 113 | \ No newline at end of file |