@@ -46,11 +46,11 @@ discard block |
||
46 | 46 | * @param \Flugg\Responder\Contracts\ResponseFactory $responseFactory |
47 | 47 | * @param \Flugg\Responder\TransformBuilder $transformBuilder |
48 | 48 | */ |
49 | - public function __construct(ResponseFactory $responseFactory, TransformBuilder $transformBuilder) |
|
49 | + public function __construct( ResponseFactory $responseFactory, TransformBuilder $transformBuilder ) |
|
50 | 50 | { |
51 | 51 | $this->transformBuilder = $transformBuilder; |
52 | 52 | |
53 | - parent::__construct($responseFactory); |
|
53 | + parent::__construct( $responseFactory ); |
|
54 | 54 | } |
55 | 55 | |
56 | 56 | /** |
@@ -61,9 +61,9 @@ discard block |
||
61 | 61 | * @param string|null $resourceKey |
62 | 62 | * @return self |
63 | 63 | */ |
64 | - public function transform($data = null, $transformer = null, string $resourceKey = null): SuccessResponseBuilder |
|
64 | + public function transform( $data = null, $transformer = null, string $resourceKey = null ): SuccessResponseBuilder |
|
65 | 65 | { |
66 | - $this->transformBuilder->resource($data, $transformer, $resourceKey); |
|
66 | + $this->transformBuilder->resource( $data, $transformer, $resourceKey ); |
|
67 | 67 | |
68 | 68 | return $this; |
69 | 69 | } |
@@ -75,10 +75,10 @@ discard block |
||
75 | 75 | * @param array $arguments |
76 | 76 | * @return self|void |
77 | 77 | */ |
78 | - public function __call($name, $arguments) |
|
78 | + public function __call( $name, $arguments ) |
|
79 | 79 | { |
80 | - if (in_array($name, ['meta', 'with', 'without', 'serializer', 'paginator', 'cursor'])) { |
|
81 | - $this->transformBuilder->$name(...$arguments); |
|
80 | + if ( in_array( $name, [ 'meta', 'with', 'without', 'serializer', 'paginator', 'cursor' ] ) ) { |
|
81 | + $this->transformBuilder->$name( ...$arguments ); |
|
82 | 82 | |
83 | 83 | return $this; |
84 | 84 | } |
@@ -103,10 +103,10 @@ discard block |
||
103 | 103 | * @return void |
104 | 104 | * @throws \InvalidArgumentException |
105 | 105 | */ |
106 | - protected function validateStatusCode(int $status) |
|
106 | + protected function validateStatusCode( int $status ) |
|
107 | 107 | { |
108 | - if ($status < 100 || $status >= 400) { |
|
109 | - throw new InvalidArgumentException("{$status} is not a valid success HTTP status code."); |
|
108 | + if ( $status < 100 || $status >= 400 ) { |
|
109 | + throw new InvalidArgumentException( "{$status} is not a valid success HTTP status code." ); |
|
110 | 110 | } |
111 | 111 | } |
112 | 112 | } |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | * |
37 | 37 | * @param \Flugg\Responder\Contracts\ResponseFactory $responseFactory |
38 | 38 | */ |
39 | - public function __construct(ResponseFactory $responseFactory) |
|
39 | + public function __construct( ResponseFactory $responseFactory ) |
|
40 | 40 | { |
41 | 41 | $this->responseFactory = $responseFactory; |
42 | 42 | } |
@@ -48,13 +48,13 @@ discard block |
||
48 | 48 | * @param array $headers |
49 | 49 | * @return \Illuminate\Http\JsonResponse |
50 | 50 | */ |
51 | - public function respond(int $status = null, array $headers = []): JsonResponse |
|
51 | + public function respond( int $status = null, array $headers = [ ] ): JsonResponse |
|
52 | 52 | { |
53 | - if (! is_null($status)) { |
|
54 | - $this->setStatusCode($status); |
|
53 | + if ( ! is_null( $status ) ) { |
|
54 | + $this->setStatusCode( $status ); |
|
55 | 55 | } |
56 | 56 | |
57 | - return $this->responseFactory->make($this->toArray(), $this->status, $headers); |
|
57 | + return $this->responseFactory->make( $this->toArray(), $this->status, $headers ); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | /** |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | */ |
75 | 75 | public function toCollection(): Collection |
76 | 76 | { |
77 | - return new Collection($this->toArray()); |
|
77 | + return new Collection( $this->toArray() ); |
|
78 | 78 | } |
79 | 79 | |
80 | 80 | /** |
@@ -83,9 +83,9 @@ discard block |
||
83 | 83 | * @param int $options |
84 | 84 | * @return string |
85 | 85 | */ |
86 | - public function toJson($options = 0): string |
|
86 | + public function toJson( $options = 0 ): string |
|
87 | 87 | { |
88 | - return json_encode($this->toArray(), $options); |
|
88 | + return json_encode( $this->toArray(), $options ); |
|
89 | 89 | } |
90 | 90 | |
91 | 91 | /** |
@@ -94,9 +94,9 @@ discard block |
||
94 | 94 | * @param int $status |
95 | 95 | * @return void |
96 | 96 | */ |
97 | - protected function setStatusCode(int $status) |
|
97 | + protected function setStatusCode( int $status ) |
|
98 | 98 | { |
99 | - $this->validateStatusCode($this->status = $status); |
|
99 | + $this->validateStatusCode( $this->status = $status ); |
|
100 | 100 | } |
101 | 101 | |
102 | 102 | /** |
@@ -112,5 +112,5 @@ discard block |
||
112 | 112 | * @param int $status |
113 | 113 | * @return void |
114 | 114 | */ |
115 | - abstract protected function validateStatusCode(int $status); |
|
115 | + abstract protected function validateStatusCode( int $status ); |
|
116 | 116 | } |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | * @param \Flugg\Responder\Contracts\ErrorMessageResolver $messageResolver |
36 | 36 | * @param \Flugg\Responder\Contracts\ErrorSerializer $serializer |
37 | 37 | */ |
38 | - public function __construct(ErrorMessageResolverContract $messageResolver, ErrorSerializerContract $serializer) |
|
38 | + public function __construct( ErrorMessageResolverContract $messageResolver, ErrorSerializerContract $serializer ) |
|
39 | 39 | { |
40 | 40 | $this->messageResolver = $messageResolver; |
41 | 41 | $this->serializer = $serializer; |
@@ -49,12 +49,12 @@ discard block |
||
49 | 49 | * @param array|null $data |
50 | 50 | * @return array |
51 | 51 | */ |
52 | - public function make(string $errorCode = null, string $message = null, array $data = null): array |
|
52 | + public function make( string $errorCode = null, string $message = null, array $data = null ): array |
|
53 | 53 | { |
54 | - if (isset($errorCode) && ! isset($message)) { |
|
55 | - $message = $this->messageResolver->resolve($errorCode); |
|
54 | + if ( isset($errorCode) && ! isset($message) ) { |
|
55 | + $message = $this->messageResolver->resolve( $errorCode ); |
|
56 | 56 | } |
57 | 57 | |
58 | - return $this->serializer->format($errorCode, $message, $data); |
|
58 | + return $this->serializer->format( $errorCode, $message, $data ); |
|
59 | 59 | } |
60 | 60 | } |
61 | 61 | \ No newline at end of file |
@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | use Flugg\Responder\Contracts\Responder; |
4 | 4 | use Flugg\Responder\Contracts\Transformer; |
5 | 5 | |
6 | -if (! function_exists('responder')) { |
|
6 | +if ( ! function_exists( 'responder' ) ) { |
|
7 | 7 | |
8 | 8 | /** |
9 | 9 | * A helper method to resolve the responder service out of the service container. |
@@ -12,11 +12,11 @@ discard block |
||
12 | 12 | */ |
13 | 13 | function responder(): Responder |
14 | 14 | { |
15 | - return app(Responder::class); |
|
15 | + return app( Responder::class ); |
|
16 | 16 | } |
17 | 17 | } |
18 | 18 | |
19 | -if (! function_exists('transform')) { |
|
19 | +if ( ! function_exists( 'transform' ) ) { |
|
20 | 20 | |
21 | 21 | /** |
22 | 22 | * A helper method to transform data without serializing. |
@@ -27,8 +27,8 @@ discard block |
||
27 | 27 | * @param string[] $without |
28 | 28 | * @return array |
29 | 29 | */ |
30 | - function transform($data = null, $transformer = null, array $with = [], array $without = []): array |
|
30 | + function transform( $data = null, $transformer = null, array $with = [ ], array $without = [ ] ): array |
|
31 | 31 | { |
32 | - return app(Transformer::class)->transform($data, $transformer, $with, $without); |
|
32 | + return app( Transformer::class )->transform( $data, $transformer, $with, $without ); |
|
33 | 33 | } |
34 | 34 | } |
@@ -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 | } |
@@ -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 |