@@ -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 |
@@ -35,7 +35,7 @@ discard block |
||
| 35 | 35 | * @param \Flugg\Responder\Http\Responses\ErrorResponseBuilder $errorResponseBuilder |
| 36 | 36 | * @param \Flugg\Responder\Http\Responses\SuccessResponseBuilder $successResponseBuilder |
| 37 | 37 | */ |
| 38 | - public function __construct(ErrorResponseBuilder $errorResponseBuilder, SuccessResponseBuilder $successResponseBuilder) |
|
| 38 | + public function __construct( ErrorResponseBuilder $errorResponseBuilder, SuccessResponseBuilder $successResponseBuilder ) |
|
| 39 | 39 | { |
| 40 | 40 | $this->errorResponseBuilder = $errorResponseBuilder; |
| 41 | 41 | $this->successResponseBuilder = $successResponseBuilder; |
@@ -48,9 +48,9 @@ discard block |
||
| 48 | 48 | * @param string|null $message |
| 49 | 49 | * @return \Flugg\Responder\Http\Responses\ErrorResponseBuilder |
| 50 | 50 | */ |
| 51 | - public function error(string $errorCode = null, string $message = null): ErrorResponseBuilder |
|
| 51 | + public function error( string $errorCode = null, string $message = null ): ErrorResponseBuilder |
|
| 52 | 52 | { |
| 53 | - return $this->errorResponseBuilder->error($errorCode, $message); |
|
| 53 | + return $this->errorResponseBuilder->error( $errorCode, $message ); |
|
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | /** |
@@ -61,8 +61,8 @@ discard block |
||
| 61 | 61 | * @param string|null $resourceKey |
| 62 | 62 | * @return \Flugg\Responder\Http\Responses\SuccessResponseBuilder |
| 63 | 63 | */ |
| 64 | - public function success($data = null, $transformer = null, string $resourceKey = null): SuccessResponseBuilder |
|
| 64 | + public function success( $data = null, $transformer = null, string $resourceKey = null ): SuccessResponseBuilder |
|
| 65 | 65 | { |
| 66 | - return $this->successResponseBuilder->transform($data, $transformer, $resourceKey); |
|
| 66 | + return $this->successResponseBuilder->transform( $data, $transformer, $resourceKey ); |
|
| 67 | 67 | } |
| 68 | 68 | } |
| 69 | 69 | \ 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 |
@@ -24,14 +24,14 @@ |
||
| 24 | 24 | * @param \Exception $exception |
| 25 | 25 | * @return \Symfony\Component\HttpFoundation\Response |
| 26 | 26 | */ |
| 27 | - public function render($request, Exception $exception) |
|
| 27 | + public function render( $request, Exception $exception ) |
|
| 28 | 28 | { |
| 29 | - $this->transformException($exception); |
|
| 29 | + $this->transformException( $exception ); |
|
| 30 | 30 | |
| 31 | - if ($exception instanceof ApiException) { |
|
| 32 | - return $this->renderApiError($exception); |
|
| 31 | + if ( $exception instanceof ApiException ) { |
|
| 32 | + return $this->renderApiError( $exception ); |
|
| 33 | 33 | } |
| 34 | 34 | |
| 35 | - return parent::render($request, $exception); |
|
| 35 | + return parent::render( $request, $exception ); |
|
| 36 | 36 | } |
| 37 | 37 | } |
| 38 | 38 | \ No newline at end of file |
@@ -32,11 +32,11 @@ 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 | - $this->transformAuthException($exception); |
|
| 38 | - $this->transformEloquentException($exception); |
|
| 39 | - $this->transformValidationException($exception); |
|
| 37 | + $this->transformAuthException( $exception ); |
|
| 38 | + $this->transformEloquentException( $exception ); |
|
| 39 | + $this->transformValidationException( $exception ); |
|
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | /** |
@@ -47,13 +47,13 @@ discard block |
||
| 47 | 47 | * @throws UnauthenticatedException |
| 48 | 48 | * @throws UnauthorizedException |
| 49 | 49 | */ |
| 50 | - protected function transformAuthException(Exception $exception) |
|
| 50 | + protected function transformAuthException( Exception $exception ) |
|
| 51 | 51 | { |
| 52 | - if ($exception instanceof AuthenticationException) { |
|
| 52 | + if ( $exception instanceof AuthenticationException ) { |
|
| 53 | 53 | throw new UnauthenticatedException; |
| 54 | 54 | } |
| 55 | 55 | |
| 56 | - if ($exception instanceof AuthorizationException) { |
|
| 56 | + if ( $exception instanceof AuthorizationException ) { |
|
| 57 | 57 | throw new UnauthorizedException; |
| 58 | 58 | } |
| 59 | 59 | } |
@@ -66,13 +66,13 @@ discard block |
||
| 66 | 66 | * @throws ResourceNotFoundException |
| 67 | 67 | * @throws RelationNotFoundException |
| 68 | 68 | */ |
| 69 | - protected function transformEloquentException(Exception $exception) |
|
| 69 | + protected function transformEloquentException( Exception $exception ) |
|
| 70 | 70 | { |
| 71 | - if ($exception instanceof ModelNotFoundException) { |
|
| 71 | + if ( $exception instanceof ModelNotFoundException ) { |
|
| 72 | 72 | throw new ResourceNotFoundException; |
| 73 | 73 | } |
| 74 | 74 | |
| 75 | - if ($exception instanceof BaseRelationNotFoundException) { |
|
| 75 | + if ( $exception instanceof BaseRelationNotFoundException ) { |
|
| 76 | 76 | throw new RelationNotFoundException; |
| 77 | 77 | } |
| 78 | 78 | } |
@@ -84,10 +84,10 @@ discard block |
||
| 84 | 84 | * @return void |
| 85 | 85 | * @throws ValidationFailedException |
| 86 | 86 | */ |
| 87 | - protected function transformValidationException(Exception $exception) |
|
| 87 | + protected function transformValidationException( Exception $exception ) |
|
| 88 | 88 | { |
| 89 | - if ($exception instanceof ValidationException) { |
|
| 90 | - throw new ValidationFailedException($exception->validator); |
|
| 89 | + if ( $exception instanceof ValidationException ) { |
|
| 90 | + throw new ValidationFailedException( $exception->validator ); |
|
| 91 | 91 | } |
| 92 | 92 | } |
| 93 | 93 | |
@@ -97,11 +97,11 @@ discard block |
||
| 97 | 97 | * @param \Flugg\Responder\Exceptions\Http\ApiException $exception |
| 98 | 98 | * @return \Illuminate\Http\JsonResponse |
| 99 | 99 | */ |
| 100 | - protected function renderApiError(ApiException $exception): JsonResponse |
|
| 100 | + protected function renderApiError( ApiException $exception ): JsonResponse |
|
| 101 | 101 | { |
| 102 | - return $this->container->make(ErrorResponseBuilder::class) |
|
| 103 | - ->error($exception->errorCode(), $exception->message()) |
|
| 104 | - ->data($exception->data()) |
|
| 105 | - ->respond($exception->statusCode()); |
|
| 102 | + return $this->container->make( ErrorResponseBuilder::class ) |
|
| 103 | + ->error( $exception->errorCode(), $exception->message() ) |
|
| 104 | + ->data( $exception->data() ) |
|
| 105 | + ->respond( $exception->statusCode() ); |
|
| 106 | 106 | } |
| 107 | 107 | } |
| 108 | 108 | \ 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 |