@@ -21,10 +21,10 @@ |
||
21 | 21 | * @param array $headers |
22 | 22 | * @return \Illuminate\Http\JsonResponse |
23 | 23 | */ |
24 | - public function make(array $data, int $status, array $headers = []): JsonResponse |
|
24 | + public function make( array $data, int $status, array $headers = [ ] ): JsonResponse |
|
25 | 25 | { |
26 | - return $this->factory->make(array_merge([ |
|
26 | + return $this->factory->make( array_merge( [ |
|
27 | 27 | 'success' => $status >= 100 || $status < 400, |
28 | - ], $data), $status, $headers); |
|
28 | + ], $data ), $status, $headers ); |
|
29 | 29 | } |
30 | 30 | } |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | * |
27 | 27 | * @param \Flugg\Responder\Contracts\ResponseFactory $factory |
28 | 28 | */ |
29 | - public function __construct(ResponseFactory $factory) |
|
29 | + public function __construct( ResponseFactory $factory ) |
|
30 | 30 | { |
31 | 31 | $this->factory = $factory; |
32 | 32 | } |
@@ -39,5 +39,5 @@ discard block |
||
39 | 39 | * @param array $headers |
40 | 40 | * @return \Illuminate\Http\JsonResponse |
41 | 41 | */ |
42 | - abstract public function make(array $data, int $status, array $headers = []): JsonResponse; |
|
42 | + abstract public function make( array $data, int $status, array $headers = [ ] ): JsonResponse; |
|
43 | 43 | } |
@@ -21,10 +21,10 @@ |
||
21 | 21 | * @param array $headers |
22 | 22 | * @return \Illuminate\Http\JsonResponse |
23 | 23 | */ |
24 | - public function make(array $data, int $status, array $headers = []): JsonResponse |
|
24 | + public function make( array $data, int $status, array $headers = [ ] ): JsonResponse |
|
25 | 25 | { |
26 | - return $this->factory->make(array_merge([ |
|
26 | + return $this->factory->make( array_merge( [ |
|
27 | 27 | 'status' => $status, |
28 | - ], $data), $status, $headers); |
|
28 | + ], $data ), $status, $headers ); |
|
29 | 29 | } |
30 | 30 | } |
@@ -30,12 +30,12 @@ |
||
30 | 30 | * @param array $data |
31 | 31 | * @return array |
32 | 32 | */ |
33 | - protected function cleanArray(array $data) |
|
33 | + protected function cleanArray( array $data ) |
|
34 | 34 | { |
35 | - return collect($data)->mapWithKeys(function ($value, $key) { |
|
36 | - $key = in_array($key, $this->except) ? $key : snake_case($key); |
|
35 | + return collect( $data )->mapWithKeys( function ( $value, $key ) { |
|
36 | + $key = in_array( $key, $this->except ) ? $key : snake_case( $key ); |
|
37 | 37 | |
38 | - return [$key => $value]; |
|
38 | + return [ $key => $value ]; |
|
39 | 39 | })->all(); |
40 | 40 | } |
41 | 41 | } |
@@ -26,14 +26,14 @@ discard block |
||
26 | 26 | * @param mixed $data |
27 | 27 | * @return mixed |
28 | 28 | */ |
29 | - public function normalize($data = null) |
|
29 | + public function normalize( $data = null ) |
|
30 | 30 | { |
31 | - if ($data instanceof Builder || $data instanceof CursorPaginator) { |
|
31 | + if ( $data instanceof Builder || $data instanceof CursorPaginator ) { |
|
32 | 32 | return $data->get(); |
33 | - } elseif ($data instanceof Paginator) { |
|
33 | + } elseif ( $data instanceof Paginator ) { |
|
34 | 34 | return $data->getCollection(); |
35 | - } elseif ($data instanceof Relation) { |
|
36 | - return $this->normalizeRelation($data); |
|
35 | + } elseif ( $data instanceof Relation ) { |
|
36 | + return $this->normalizeRelation( $data ); |
|
37 | 37 | } |
38 | 38 | |
39 | 39 | return $data; |
@@ -45,9 +45,9 @@ discard block |
||
45 | 45 | * @param \Illuminate\Database\Eloquent\Relations\Relation $relation |
46 | 46 | * @return \Illuminate\Support\Collection|\Illuminate\Database\Eloquent\Model|null |
47 | 47 | */ |
48 | - protected function normalizeRelation(Relation $relation) |
|
48 | + protected function normalizeRelation( Relation $relation ) |
|
49 | 49 | { |
50 | - return $this->isSingularRelation($relation) ? $relation->first() : $relation->get(); |
|
50 | + return $this->isSingularRelation( $relation ) ? $relation->first() : $relation->get(); |
|
51 | 51 | } |
52 | 52 | |
53 | 53 | /** |
@@ -56,12 +56,12 @@ discard block |
||
56 | 56 | * @param \Illuminate\Database\Eloquent\Relations\Relation $relation |
57 | 57 | * @return bool |
58 | 58 | */ |
59 | - protected function isSingularRelation(Relation $relation): bool |
|
59 | + protected function isSingularRelation( Relation $relation ): bool |
|
60 | 60 | { |
61 | - $singularRelations = [BelongsTo::class, HasOne::class, MorphOne::class, MorphTo::class]; |
|
61 | + $singularRelations = [ BelongsTo::class, HasOne::class, MorphOne::class, MorphTo::class ]; |
|
62 | 62 | |
63 | - foreach ($singularRelations as $singularRelation) { |
|
64 | - if ($relation instanceof $singularRelation) { |
|
63 | + foreach ( $singularRelations as $singularRelation ) { |
|
64 | + if ( $relation instanceof $singularRelation ) { |
|
65 | 65 | return true; |
66 | 66 | } |
67 | 67 | } |
@@ -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 | } |
@@ -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 | } |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | * @param \Flugg\Responder\Http\Responses\SuccessResponseBuilder $successResponseBuilder |
36 | 36 | * @param \Flugg\Responder\Http\Responses\ErrorResponseBuilder $errorResponseBuilder |
37 | 37 | */ |
38 | - public function __construct(SuccessResponseBuilder $successResponseBuilder, ErrorResponseBuilder $errorResponseBuilder) |
|
38 | + public function __construct( SuccessResponseBuilder $successResponseBuilder, ErrorResponseBuilder $errorResponseBuilder ) |
|
39 | 39 | { |
40 | 40 | $this->successResponseBuilder = $successResponseBuilder; |
41 | 41 | $this->errorResponseBuilder = $errorResponseBuilder; |
@@ -49,9 +49,9 @@ discard block |
||
49 | 49 | * @param string|null $resourceKey |
50 | 50 | * @return \Flugg\Responder\Http\Responses\SuccessResponseBuilder |
51 | 51 | */ |
52 | - public function success($data = null, $transformer = null, string $resourceKey = null): SuccessResponseBuilder |
|
52 | + public function success( $data = null, $transformer = null, string $resourceKey = null ): SuccessResponseBuilder |
|
53 | 53 | { |
54 | - return $this->successResponseBuilder->transform($data, $transformer, $resourceKey); |
|
54 | + return $this->successResponseBuilder->transform( $data, $transformer, $resourceKey ); |
|
55 | 55 | } |
56 | 56 | |
57 | 57 | /** |
@@ -61,8 +61,8 @@ discard block |
||
61 | 61 | * @param string|null $message |
62 | 62 | * @return \Flugg\Responder\Http\Responses\ErrorResponseBuilder |
63 | 63 | */ |
64 | - public function error(string $errorCode = null, string $message = null): ErrorResponseBuilder |
|
64 | + public function error( string $errorCode = null, string $message = null ): ErrorResponseBuilder |
|
65 | 65 | { |
66 | - return $this->errorResponseBuilder->error($errorCode, $message); |
|
66 | + return $this->errorResponseBuilder->error( $errorCode, $message ); |
|
67 | 67 | } |
68 | 68 | } |
69 | 69 | \ No newline at end of file |