Completed
Pull Request — master (#26)
by Brian
03:13
created
src/Traits/ConvertsParameters.php 1 patch
Spacing   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -19,9 +19,9 @@  discard block
 block discarded – undo
19 19
      * @param  string $key
20 20
      * @return bool
21 21
      */
22
-    public function __isset($key)
22
+    public function __isset( $key )
23 23
     {
24
-        return parent::__isset(snake_case($key));
24
+        return parent::__isset( snake_case( $key ) );
25 25
     }
26 26
 
27 27
     /**
@@ -30,9 +30,9 @@  discard block
 block discarded – undo
30 30
      * @param  string $key
31 31
      * @return mixed
32 32
      */
33
-    public function __get($key)
33
+    public function __get( $key )
34 34
     {
35
-        return parent::__get(snake_case($key));
35
+        return parent::__get( snake_case( $key ) );
36 36
     }
37 37
 
38 38
     /**
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
42 42
      */
43 43
     protected function getValidatorInstance()
44 44
     {
45
-        $this->getInputSource()->replace($this->getConvertedParameters());
45
+        $this->getInputSource()->replace( $this->getConvertedParameters() );
46 46
 
47 47
         return parent::getValidatorInstance();
48 48
     }
@@ -62,11 +62,11 @@  discard block
 block discarded – undo
62 62
     protected function getConvertedParameters():array
63 63
     {
64 64
         $parameters = $this->all();
65
-        $parameters = $this->castBooleans($parameters);
66
-        $parameters = $this->convertToSnakeCase($parameters);
65
+        $parameters = $this->castBooleans( $parameters );
66
+        $parameters = $this->convertToSnakeCase( $parameters );
67 67
 
68
-        if (method_exists($this, 'convertParameters')) {
69
-            $parameters = $this->convertParameters($parameters);
68
+        if ( method_exists( $this, 'convertParameters' ) ) {
69
+            $parameters = $this->convertParameters( $parameters );
70 70
         }
71 71
 
72 72
         return $parameters;
@@ -85,16 +85,16 @@  discard block
 block discarded – undo
85 85
      * @param  mixed $input
86 86
      * @return array
87 87
      */
88
-    protected function castBooleans($input):array
88
+    protected function castBooleans( $input ):array
89 89
     {
90
-        if ($this->castToBooleanIsDisabled()) {
90
+        if ( $this->castToBooleanIsDisabled() ) {
91 91
             return;
92 92
         }
93 93
 
94
-        $casted = [];
94
+        $casted = [ ];
95 95
 
96
-        foreach ($input as $key => $value) {
97
-            $casted[$key] = $this->castValueToBoolean($value);
96
+        foreach ( $input as $key => $value ) {
97
+            $casted[ $key ] = $this->castValueToBoolean( $value );
98 98
         }
99 99
 
100 100
         return $casted;
@@ -116,10 +116,10 @@  discard block
 block discarded – undo
116 116
      * @param  mixed $value
117 117
      * @return mixed
118 118
      */
119
-    protected function castValueToBoolean($value)
119
+    protected function castValueToBoolean( $value )
120 120
     {
121
-        if (in_array($value, ['true', 'false'])) {
122
-            return filter_var($value, FILTER_VALIDATE_BOOLEAN);
121
+        if ( in_array( $value, [ 'true', 'false' ] ) ) {
122
+            return filter_var( $value, FILTER_VALIDATE_BOOLEAN );
123 123
         }
124 124
 
125 125
         return $value;
@@ -131,19 +131,19 @@  discard block
 block discarded – undo
131 131
      * @param  mixed $input
132 132
      * @return mixed
133 133
      */
134
-    protected function convertToSnakeCase($input)
134
+    protected function convertToSnakeCase( $input )
135 135
     {
136
-        if ($this->convertToSnakeCaseIsDisabled()) {
136
+        if ( $this->convertToSnakeCaseIsDisabled() ) {
137 137
             return;
138 138
         }
139 139
 
140
-        if (is_null($input)) {
140
+        if ( is_null( $input ) ) {
141 141
             return null;
142
-        } elseif (is_array($input)) {
143
-            return $this->convertArrayToSnakeCase($input);
142
+        } elseif ( is_array( $input ) ) {
143
+            return $this->convertArrayToSnakeCase( $input );
144 144
         }
145 145
 
146
-        return snake_case($input);
146
+        return snake_case( $input );
147 147
     }
148 148
 
149 149
     /**
@@ -162,12 +162,12 @@  discard block
 block discarded – undo
162 162
      * @param  array $input
163 163
      * @return array
164 164
      */
165
-    protected function convertArrayToSnakeCase(array $input):array
165
+    protected function convertArrayToSnakeCase( array $input ):array
166 166
     {
167
-        $converted = [];
167
+        $converted = [ ];
168 168
 
169
-        foreach ($input as $key => $value) {
170
-            $converted[snake_case($key)] = $value;
169
+        foreach ( $input as $key => $value ) {
170
+            $converted[ snake_case( $key ) ] = $value;
171 171
         }
172 172
 
173 173
         return $converted;
Please login to merge, or discard this patch.
src/Console/MakeTransformer.php 1 patch
Spacing   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -43,7 +43,7 @@  discard block
 block discarded – undo
43 43
      *
44 44
      * @param  Filesystem $files
45 45
      */
46
-    public function __construct(Filesystem $files)
46
+    public function __construct( Filesystem $files )
47 47
     {
48 48
         parent::__construct();
49 49
 
@@ -67,21 +67,21 @@  discard block
 block discarded – undo
67 67
      */
68 68
     protected function generateTransformer()
69 69
     {
70
-        $name = (string) $this->argument('name');
70
+        $name = (string) $this->argument( 'name' );
71 71
         $path = $this->laravel->basePath() . '/app/Transformers/' . $name . '.php';
72 72
 
73
-        if ($this->files->exists($path)) {
74
-            return $this->error($name . ' already exists!');
73
+        if ( $this->files->exists( $path ) ) {
74
+            return $this->error( $name . ' already exists!' );
75 75
         }
76 76
 
77
-        $this->makeDirectory($path);
77
+        $this->makeDirectory( $path );
78 78
 
79
-        $stubPath = $this->option('pivot') ? 'resources/stubs/transformer.pivot.stub' : 'resources/stubs/transformer.stub';
80
-        $stub = $this->files->get(__DIR__ . '/../../' . $stubPath);
79
+        $stubPath = $this->option( 'pivot' ) ? 'resources/stubs/transformer.pivot.stub' : 'resources/stubs/transformer.stub';
80
+        $stub = $this->files->get( __DIR__ . '/../../' . $stubPath );
81 81
 
82
-        $this->files->put($path, $this->makeTransformer($name, $stub));
82
+        $this->files->put( $path, $this->makeTransformer( $name, $stub ) );
83 83
 
84
-        $this->info('Transformer created successfully.');
84
+        $this->info( 'Transformer created successfully.' );
85 85
     }
86 86
 
87 87
     /**
@@ -90,10 +90,10 @@  discard block
 block discarded – undo
90 90
      * @param  string $path
91 91
      * @return void
92 92
      */
93
-    protected function makeDirectory(string $path)
93
+    protected function makeDirectory( string $path )
94 94
     {
95
-        if (! $this->files->isDirectory(dirname($path))) {
96
-            $this->files->makeDirectory(dirname($path), 0777, true, true);
95
+        if ( ! $this->files->isDirectory( dirname( $path ) ) ) {
96
+            $this->files->makeDirectory( dirname( $path ), 0777, true, true );
97 97
         }
98 98
     }
99 99
 
@@ -104,11 +104,11 @@  discard block
 block discarded – undo
104 104
      * @param  string $stub
105 105
      * @return string
106 106
      */
107
-    protected function makeTransformer(string $name, string $stub):string
107
+    protected function makeTransformer( string $name, string $stub ):string
108 108
     {
109
-        $stub = $this->replaceNamespace($stub);
110
-        $stub = $this->replaceClass($stub, $name);
111
-        $stub = $this->replaceModel($stub, $name);
109
+        $stub = $this->replaceNamespace( $stub );
110
+        $stub = $this->replaceClass( $stub, $name );
111
+        $stub = $this->replaceModel( $stub, $name );
112 112
 
113 113
         return $stub;
114 114
     }
@@ -119,15 +119,15 @@  discard block
 block discarded – undo
119 119
      * @param  string $stub
120 120
      * @return string
121 121
      */
122
-    protected function replaceNamespace(string $stub):string
122
+    protected function replaceNamespace( string $stub ):string
123 123
     {
124
-        if (method_exists($this->laravel, 'getNameSpace')) {
124
+        if ( method_exists( $this->laravel, 'getNameSpace' ) ) {
125 125
             $namespace = $this->laravel->getNamespace() . 'Transformers';
126 126
         } else {
127 127
             $namespace = 'App\Transformers';
128 128
         }
129 129
 
130
-        $stub = str_replace('DummyNamespace', $namespace, $stub);
130
+        $stub = str_replace( 'DummyNamespace', $namespace, $stub );
131 131
 
132 132
         return $stub;
133 133
     }
@@ -139,9 +139,9 @@  discard block
 block discarded – undo
139 139
      * @param  string $name
140 140
      * @return string
141 141
      */
142
-    protected function replaceClass(string $stub, string $name):string
142
+    protected function replaceClass( string $stub, string $name ):string
143 143
     {
144
-        $stub = str_replace('DummyClass', $name, $stub);
144
+        $stub = str_replace( 'DummyClass', $name, $stub );
145 145
 
146 146
         return $stub;
147 147
     }
@@ -153,14 +153,14 @@  discard block
 block discarded – undo
153 153
      * @param  string $name
154 154
      * @return string
155 155
      */
156
-    protected function replaceModel(string $stub, string $name):string
156
+    protected function replaceModel( string $stub, string $name ):string
157 157
     {
158
-        $model = $this->getModelNamespace($name);
159
-        $class = $this->getClassFromNamespace($model);
158
+        $model = $this->getModelNamespace( $name );
159
+        $class = $this->getClassFromNamespace( $model );
160 160
 
161
-        $stub = str_replace('DummyModelNamespace', $model, $stub);
162
-        $stub = str_replace('DummyModelClass', $class, $stub);
163
-        $stub = str_replace('DummyModelVariable', camel_case($class), $stub);
161
+        $stub = str_replace( 'DummyModelNamespace', $model, $stub );
162
+        $stub = str_replace( 'DummyModelClass', $class, $stub );
163
+        $stub = str_replace( 'DummyModelVariable', camel_case( $class ), $stub );
164 164
 
165 165
         return $stub;
166 166
     }
@@ -171,13 +171,13 @@  discard block
 block discarded – undo
171 171
      * @param  string $name
172 172
      * @return string
173 173
      */
174
-    protected function getModelNamespace(string $name):string
174
+    protected function getModelNamespace( string $name ):string
175 175
     {
176
-        if ($this->option('model')) {
177
-            return $this->option('model');
176
+        if ( $this->option( 'model' ) ) {
177
+            return $this->option( 'model' );
178 178
         }
179 179
 
180
-        return 'App\\' . str_replace('Transformer', '', $name);
180
+        return 'App\\' . str_replace( 'Transformer', '', $name );
181 181
     }
182 182
 
183 183
     /**
@@ -186,8 +186,8 @@  discard block
 block discarded – undo
186 186
      * @param  string $namespace
187 187
      * @return string
188 188
      */
189
-    protected function getClassFromNamespace(string $namespace):string
189
+    protected function getClassFromNamespace( string $namespace ):string
190 190
     {
191
-        return last(explode('\\', $namespace));
191
+        return last( explode( '\\', $namespace ) );
192 192
     }
193 193
 }
194 194
\ No newline at end of file
Please login to merge, or discard this patch.
src/Exceptions/InvalidSerializerException.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -19,6 +19,6 @@
 block discarded – undo
19 19
      */
20 20
     public function __construct()
21 21
     {
22
-        parent::__construct('Given serializer is not an instance of [' . SerializerAbstract::class . '].');
22
+        parent::__construct( 'Given serializer is not an instance of [' . SerializerAbstract::class . '].' );
23 23
     }
24 24
 }
25 25
\ No newline at end of file
Please login to merge, or discard this patch.
src/Exceptions/InvalidTransformerException.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -19,8 +19,8 @@
 block discarded – undo
19 19
      *
20 20
      * @param Model $model
21 21
      */
22
-    public function __construct(Model $model)
22
+    public function __construct( Model $model )
23 23
     {
24
-        parent::__construct('The given transformer does not exist for model [' . get_class($model) . '].');
24
+        parent::__construct( 'The given transformer does not exist for model [' . get_class( $model ) . '].' );
25 25
     }
26 26
 }
27 27
\ No newline at end of file
Please login to merge, or discard this patch.
src/Exceptions/Handler.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -18,14 +18,14 @@
 block discarded – undo
18 18
      * @param  Exception                $exception
19 19
      * @return \Illuminate\Http\Response|\Illuminate\Http\JsonResponse
20 20
      */
21
-    public function render($request, Exception $exception)
21
+    public function render( $request, Exception $exception )
22 22
     {
23
-        $this->transformException($exception);
23
+        $this->transformException( $exception );
24 24
 
25
-        if ($exception instanceof ApiException) {
26
-            return $this->renderApiError($exception);
25
+        if ( $exception instanceof ApiException ) {
26
+            return $this->renderApiError( $exception );
27 27
         }
28 28
 
29
-        return parent::render($request, $exception);
29
+        return parent::render( $request, $exception );
30 30
     }
31 31
 }
32 32
\ No newline at end of file
Please login to merge, or discard this patch.
src/Traits/RespondsWithJson.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -24,9 +24,9 @@  discard block
 block discarded – undo
24 24
      * @param  mixed       $message
25 25
      * @return JsonResponse
26 26
      */
27
-    public function errorResponse(string $errorCode = null, int $statusCode = null, $message = null):JsonResponse
27
+    public function errorResponse( string $errorCode = null, int $statusCode = null, $message = null ):JsonResponse
28 28
     {
29
-        return app(Responder::class)->error($errorCode, $statusCode, $message);
29
+        return app( Responder::class )->error( $errorCode, $statusCode, $message );
30 30
     }
31 31
 
32 32
     /**
@@ -37,9 +37,9 @@  discard block
 block discarded – undo
37 37
      * @param  array      $meta
38 38
      * @return \Illuminate\Http\JsonResponse
39 39
      */
40
-    public function successResponse($data = null, $statusCode = null, array $meta = []):JsonResponse
40
+    public function successResponse( $data = null, $statusCode = null, array $meta = [ ] ):JsonResponse
41 41
     {
42
-        return app(Responder::class)->success($data, $statusCode, $meta);
42
+        return app( Responder::class )->success( $data, $statusCode, $meta );
43 43
     }
44 44
 
45 45
     /**
@@ -49,8 +49,8 @@  discard block
 block discarded – undo
49 49
      * @param  callable|string|null $transformer
50 50
      * @return \Flugg\Responder\Http\SuccessResponse
51 51
      */
52
-    public function transform($data = null, $transformer = null):SuccessResponseBuilder
52
+    public function transform( $data = null, $transformer = null ):SuccessResponseBuilder
53 53
     {
54
-        return app(Responder::class)->transform($data, $transformer);
54
+        return app( Responder::class )->transform( $data, $transformer );
55 55
     }
56 56
 }
57 57
\ No newline at end of file
Please login to merge, or discard this patch.
src/Http/SuccessResponseBuilder.php 3 patches
Unused Use Statements   -2 removed lines patch added patch discarded remove patch
@@ -6,8 +6,6 @@
 block discarded – undo
6 6
 use Flugg\Responder\Exceptions\InvalidSerializerException;
7 7
 use Flugg\Responder\Exceptions\InvalidTransformerException;
8 8
 use Flugg\Responder\ResourceFactory;
9
-use Flugg\Responder\ResourceResolver;
10
-use Flugg\Responder\Transformation;
11 9
 use Flugg\Responder\Transformer;
12 10
 use Illuminate\Contracts\Routing\ResponseFactory;
13 11
 use Illuminate\Database\Eloquent\Model;
Please login to merge, or discard this patch.
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -70,7 +70,7 @@
 block discarded – undo
70 70
     /**
71 71
      * SuccessResponseBuilder constructor.
72 72
      *
73
-     * @param \Illuminate\Contracts\Routing\ResponseFactory|\Laravel\Lumen\Http\ResponseFactory $responseFactory
73
+     * @param \Illuminate\Contracts\Routing\ResponseFactory $responseFactory
74 74
      * @param \Flugg\Responder\ResourceFactory                                                  $resourceFactory
75 75
      * @param \League\Fractal\Manager                                                           $manager
76 76
      */
Please login to merge, or discard this patch.
Spacing   +68 added lines, -68 removed lines patch added patch discarded remove patch
@@ -37,14 +37,14 @@  discard block
 block discarded – undo
37 37
      *
38 38
      * @var array
39 39
      */
40
-    protected $meta = [];
40
+    protected $meta = [ ];
41 41
 
42 42
     /**
43 43
      * The included relations.
44 44
      *
45 45
      * @var array
46 46
      */
47
-    protected $relations = [];
47
+    protected $relations = [ ];
48 48
 
49 49
     /**
50 50
      * The Fractal resource instance containing the data and transformer.
@@ -74,13 +74,13 @@  discard block
 block discarded – undo
74 74
      * @param \Flugg\Responder\ResourceFactory                                                  $resourceFactory
75 75
      * @param \League\Fractal\Manager                                                           $manager
76 76
      */
77
-    public function __construct($responseFactory, ResourceFactory $resourceFactory, Manager $manager)
77
+    public function __construct( $responseFactory, ResourceFactory $resourceFactory, Manager $manager )
78 78
     {
79 79
         $this->resourceFactory = $resourceFactory;
80 80
         $this->manager = $manager;
81 81
         $this->resource = $this->resourceFactory->make();
82 82
 
83
-        parent::__construct($responseFactory);
83
+        parent::__construct( $responseFactory );
84 84
     }
85 85
 
86 86
     /**
@@ -89,9 +89,9 @@  discard block
 block discarded – undo
89 89
      * @param  array $data
90 90
      * @return self
91 91
      */
92
-    public function addMeta(array $data):SuccessResponseBuilder
92
+    public function addMeta( array $data ):SuccessResponseBuilder
93 93
     {
94
-        $this->meta = array_merge($this->meta, $data);
94
+        $this->meta = array_merge( $this->meta, $data );
95 95
 
96 96
         return $this;
97 97
     }
@@ -104,11 +104,11 @@  discard block
 block discarded – undo
104 104
      */
105 105
     public function include($relations):SuccessResponseBuilder
106 106
     {
107
-        if (is_string($relations)) {
108
-            $relations = explode(',', $relations);
107
+        if ( is_string( $relations ) ) {
108
+            $relations = explode( ',', $relations );
109 109
         }
110 110
 
111
-        $this->relations = array_merge($this->relations, (array) $relations);
111
+        $this->relations = array_merge( $this->relations, (array) $relations );
112 112
 
113 113
         return $this;
114 114
     }
@@ -119,9 +119,9 @@  discard block
 block discarded – undo
119 119
      * @param  \League\Fractal\Serializer\SerializerAbstract|string $serializer
120 120
      * @return self
121 121
      */
122
-    public function serializer($serializer):SuccessResponseBuilder
122
+    public function serializer( $serializer ):SuccessResponseBuilder
123 123
     {
124
-        $this->manager->setSerializer($this->resolveSerializer($serializer));
124
+        $this->manager->setSerializer( $this->resolveSerializer( $serializer ) );
125 125
 
126 126
         return $this;
127 127
     }
@@ -133,13 +133,13 @@  discard block
 block discarded – undo
133 133
      * @return self
134 134
      * @throws \InvalidArgumentException
135 135
      */
136
-    public function setStatus(int $statusCode):ResponseBuilder
136
+    public function setStatus( int $statusCode ):ResponseBuilder
137 137
     {
138
-        if ($statusCode < 100 || $statusCode >= 400) {
139
-            throw new InvalidArgumentException("{$statusCode} is not a valid success HTTP status code.");
138
+        if ( $statusCode < 100 || $statusCode >= 400 ) {
139
+            throw new InvalidArgumentException( "{$statusCode} is not a valid success HTTP status code." );
140 140
         }
141 141
 
142
-        return parent::setStatus($statusCode);
142
+        return parent::setStatus( $statusCode );
143 143
     }
144 144
 
145 145
     /**
@@ -151,25 +151,25 @@  discard block
 block discarded – undo
151 151
      * @param  string|null          $resourceKey
152 152
      * @return self
153 153
      */
154
-    public function transform($data = null, $transformer = null, string $resourceKey = null):SuccessResponseBuilder
154
+    public function transform( $data = null, $transformer = null, string $resourceKey = null ):SuccessResponseBuilder
155 155
     {
156
-        $resource = $this->resourceFactory->make($data);
156
+        $resource = $this->resourceFactory->make( $data );
157 157
 
158
-        if (! is_null($resource->getData())) {
159
-            $model = $this->resolveModel($resource->getData());
160
-            $transformer = $this->resolveTransformer($model, $transformer);
161
-            $resourceKey = $this->resolveResourceKey($model, $resourceKey);
158
+        if ( ! is_null( $resource->getData() ) ) {
159
+            $model = $this->resolveModel( $resource->getData() );
160
+            $transformer = $this->resolveTransformer( $model, $transformer );
161
+            $resourceKey = $this->resolveResourceKey( $model, $resourceKey );
162 162
         }
163 163
 
164
-        if ($transformer instanceof Transformer) {
165
-            $this->include($relations = $this->resolveNestedRelations($resource->getData()));
164
+        if ( $transformer instanceof Transformer ) {
165
+            $this->include( $relations = $this->resolveNestedRelations( $resource->getData() ) );
166 166
 
167
-            if ($transformer->allRelationsAllowed()) {
168
-                $transformer->setRelations($relations);
167
+            if ( $transformer->allRelationsAllowed() ) {
168
+                $transformer->setRelations( $relations );
169 169
             }
170 170
         }
171 171
 
172
-        $this->resource = $resource->setTransformer($transformer)->setResourceKey($resourceKey);
172
+        $this->resource = $resource->setTransformer( $transformer )->setResourceKey( $resourceKey );
173 173
 
174 174
         return $this;
175 175
     }
@@ -181,7 +181,7 @@  discard block
 block discarded – undo
181 181
      */
182 182
     public function toArray():array
183 183
     {
184
-        return $this->serialize($this->getResource());
184
+        return $this->serialize( $this->getResource() );
185 185
     }
186 186
 
187 187
     /**
@@ -191,14 +191,14 @@  discard block
 block discarded – undo
191 191
      */
192 192
     public function getResource():ResourceInterface
193 193
     {
194
-        $this->manager->parseIncludes($this->relations);
194
+        $this->manager->parseIncludes( $this->relations );
195 195
         $transformer = $this->resource->getTransformer();
196 196
 
197
-        if ($transformer instanceof Transformer && $transformer->allRelationsAllowed()) {
198
-            $this->resource->setTransformer($transformer->setRelations($this->manager->getRequestedIncludes()));
197
+        if ( $transformer instanceof Transformer && $transformer->allRelationsAllowed() ) {
198
+            $this->resource->setTransformer( $transformer->setRelations( $this->manager->getRequestedIncludes() ) );
199 199
         }
200 200
 
201
-        return $this->resource->setMeta($this->meta);
201
+        return $this->resource->setMeta( $this->meta );
202 202
     }
203 203
 
204 204
     /**
@@ -218,13 +218,13 @@  discard block
 block discarded – undo
218 218
      * @return \League\Fractal\Serializer\SerializerAbstract
219 219
      * @throws \Flugg\Responder\Exceptions\InvalidSerializerException
220 220
      */
221
-    protected function resolveSerializer($serializer):SerializerAbstract
221
+    protected function resolveSerializer( $serializer ):SerializerAbstract
222 222
     {
223
-        if (is_string($serializer)) {
223
+        if ( is_string( $serializer ) ) {
224 224
             $serializer = new $serializer;
225 225
         }
226 226
 
227
-        if (! $serializer instanceof SerializerAbstract) {
227
+        if ( ! $serializer instanceof SerializerAbstract ) {
228 228
             throw new InvalidSerializerException();
229 229
         }
230 230
 
@@ -238,15 +238,15 @@  discard block
 block discarded – undo
238 238
      * @return \Illuminate\Database\Eloquent\Model
239 239
      * @throws \InvalidArgumentException
240 240
      */
241
-    protected function resolveModel($data):Model
241
+    protected function resolveModel( $data ):Model
242 242
     {
243
-        if ($data instanceof Model) {
243
+        if ( $data instanceof Model ) {
244 244
             return $data;
245 245
         }
246 246
 
247
-        $model = array_values($data)[0];
248
-        if (! $model instanceof Model) {
249
-            throw new InvalidArgumentException('You can only transform data containing Eloquent models.');
247
+        $model = array_values( $data )[ 0 ];
248
+        if ( ! $model instanceof Model ) {
249
+            throw new InvalidArgumentException( 'You can only transform data containing Eloquent models.' );
250 250
         }
251 251
 
252 252
         return $model;
@@ -259,15 +259,15 @@  discard block
 block discarded – undo
259 259
      * @param  \Flugg\Responder\Transformer|callable|null $transformer
260 260
      * @return \Flugg\Responder\Transformer|callable
261 261
      */
262
-    protected function resolveTransformer(Model $model, $transformer = null)
262
+    protected function resolveTransformer( Model $model, $transformer = null )
263 263
     {
264
-        $transformer = $transformer ?: $this->resolveTransformerFromModel($model);
264
+        $transformer = $transformer ?: $this->resolveTransformerFromModel( $model );
265 265
 
266
-        if (is_string($transformer)) {
266
+        if ( is_string( $transformer ) ) {
267 267
             $transformer = new $transformer;
268 268
         }
269 269
 
270
-        return $this->parseTransformer($transformer, $model);
270
+        return $this->parseTransformer( $transformer, $model );
271 271
     }
272 272
 
273 273
     /**
@@ -277,10 +277,10 @@  discard block
 block discarded – undo
277 277
      * @param  \Illuminate\Database\ELoquent\Model $model
278 278
      * @return \Flugg\Responder\Transformer|callable
279 279
      */
280
-    protected function resolveTransformerFromModel(Model $model)
280
+    protected function resolveTransformerFromModel( Model $model )
281 281
     {
282
-        if (! $model instanceof Transformable) {
283
-            return function ($model) {
282
+        if ( ! $model instanceof Transformable ) {
283
+            return function ( $model ) {
284 284
                 return $model->toArray();
285 285
             };
286 286
         }
@@ -296,14 +296,14 @@  discard block
 block discarded – undo
296 296
      * @return \Flugg\Responder\Transformer|callable
297 297
      * @throws \InvalidTransformerException
298 298
      */
299
-    protected function parseTransformer($transformer, Model $model)
299
+    protected function parseTransformer( $transformer, Model $model )
300 300
     {
301
-        if ($transformer instanceof Transformer) {
302
-            $relations = $transformer->allRelationsAllowed() ? $this->resolveRelations($model) : $transformer->getRelations();
303
-            $transformer = $transformer->setRelations($relations);
301
+        if ( $transformer instanceof Transformer ) {
302
+            $relations = $transformer->allRelationsAllowed() ? $this->resolveRelations( $model ) : $transformer->getRelations();
303
+            $transformer = $transformer->setRelations( $relations );
304 304
 
305
-        } elseif (! is_callable($transformer)) {
306
-            throw new InvalidTransformerException($model);
305
+        } elseif ( ! is_callable( $transformer ) ) {
306
+            throw new InvalidTransformerException( $model );
307 307
         }
308 308
 
309 309
         return $transformer;
@@ -315,9 +315,9 @@  discard block
 block discarded – undo
315 315
      * @param  \Illuminate\Database\Eloquent\Model $model
316 316
      * @return array
317 317
      */
318
-    protected function resolveRelations(Model $model):array
318
+    protected function resolveRelations( Model $model ):array
319 319
     {
320
-        return array_keys($model->getRelations());
320
+        return array_keys( $model->getRelations() );
321 321
     }
322 322
 
323 323
     /**
@@ -326,22 +326,22 @@  discard block
 block discarded – undo
326 326
      * @param  \Illuminate\Support\Collection|\Illuminate\Database\Eloquent\Model $data
327 327
      * @return array
328 328
      */
329
-    protected function resolveNestedRelations($data):array
329
+    protected function resolveNestedRelations( $data ):array
330 330
     {
331
-        if (is_null($data)) {
332
-            return [];
331
+        if ( is_null( $data ) ) {
332
+            return [ ];
333 333
         }
334 334
 
335
-        $data = $data instanceof Model ? [$data] : $data;
335
+        $data = $data instanceof Model ? [ $data ] : $data;
336 336
 
337
-        return collect($data)->flatMap(function ($model) {
338
-            $relations = collect($model->getRelations());
337
+        return collect( $data )->flatMap( function ( $model ) {
338
+            $relations = collect( $model->getRelations() );
339 339
 
340
-            return $relations->keys()->merge($relations->flatMap(function ($relation, $key) {
341
-                return collect($this->resolveNestedRelations($relation))->map(function ($nestedRelation) use ($key) {
340
+            return $relations->keys()->merge( $relations->flatMap( function ( $relation, $key ) {
341
+                return collect( $this->resolveNestedRelations( $relation ) )->map( function ( $nestedRelation ) use ($key) {
342 342
                     return $key . '.' . $nestedRelation;
343 343
                 });
344
-            }));
344
+            }) );
345 345
         })->unique()->toArray();
346 346
     }
347 347
 
@@ -352,13 +352,13 @@  discard block
 block discarded – undo
352 352
      * @param  string|null                         $resourceKey
353 353
      * @return string
354 354
      */
355
-    protected function resolveResourceKey(Model $model, string $resourceKey = null):string
355
+    protected function resolveResourceKey( Model $model, string $resourceKey = null ):string
356 356
     {
357
-        if (! is_null($resourceKey)) {
357
+        if ( ! is_null( $resourceKey ) ) {
358 358
             return $resourceKey;
359 359
         }
360 360
 
361
-        if (method_exists($model, 'getResourceKey')) {
361
+        if ( method_exists( $model, 'getResourceKey' ) ) {
362 362
             return $model->getResourceKey();
363 363
         }
364 364
 
@@ -371,8 +371,8 @@  discard block
 block discarded – undo
371 371
      * @param  ResourceInterface $resource
372 372
      * @return array
373 373
      */
374
-    protected function serialize(ResourceInterface $resource):array
374
+    protected function serialize( ResourceInterface $resource ):array
375 375
     {
376
-        return $this->manager->createData($resource)->toArray();
376
+        return $this->manager->createData( $resource )->toArray();
377 377
     }
378 378
 }
Please login to merge, or discard this patch.
src/Http/ErrorResponseBuilder.php 2 patches
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -20,7 +20,7 @@  discard block
 block discarded – undo
20 20
      *
21 21
      * @var array
22 22
      */
23
-    protected $data = [];
23
+    protected $data = [ ];
24 24
 
25 25
     /**
26 26
      * The error code used to identify the error.
@@ -41,7 +41,7 @@  discard block
 block discarded – undo
41 41
      *
42 42
      * @var array
43 43
      */
44
-    protected $parameters = [];
44
+    protected $parameters = [ ];
45 45
 
46 46
     /**
47 47
      * The HTTP status code for the response.
@@ -63,11 +63,11 @@  discard block
 block discarded – undo
63 63
      * @param \Illuminate\Contracts\Routing\ResponseFactory|\Laravel\Lumen\Http\ResponseFactory $responseFactory
64 64
      * @param \Symfony\Component\Translation\TranslatorInterface                                $translator
65 65
      */
66
-    public function __construct($responseFactory, TranslatorInterface $translator)
66
+    public function __construct( $responseFactory, TranslatorInterface $translator )
67 67
     {
68 68
         $this->translator = $translator;
69 69
 
70
-        parent::__construct($responseFactory);
70
+        parent::__construct( $responseFactory );
71 71
     }
72 72
 
73 73
     /**
@@ -76,9 +76,9 @@  discard block
 block discarded – undo
76 76
      * @param  array $data
77 77
      * @return self
78 78
      */
79
-    public function addData(array $data):ErrorResponseBuilder
79
+    public function addData( array $data ):ErrorResponseBuilder
80 80
     {
81
-        $this->data = array_merge($this->data, $data);
81
+        $this->data = array_merge( $this->data, $data );
82 82
 
83 83
         return $this;
84 84
     }
@@ -90,11 +90,11 @@  discard block
 block discarded – undo
90 90
      * @param  string|array|null $message
91 91
      * @return self
92 92
      */
93
-    public function setError(string $errorCode = null, $message = null):ErrorResponseBuilder
93
+    public function setError( string $errorCode = null, $message = null ):ErrorResponseBuilder
94 94
     {
95 95
         $this->errorCode = $errorCode;
96 96
 
97
-        if (is_array($message)) {
97
+        if ( is_array( $message ) ) {
98 98
             $this->parameters = $message;
99 99
         } else {
100 100
             $this->message = $message;
@@ -110,13 +110,13 @@  discard block
 block discarded – undo
110 110
      * @return self
111 111
      * @throws \InvalidArgumentException
112 112
      */
113
-    public function setStatus(int $statusCode):ResponseBuilder
113
+    public function setStatus( int $statusCode ):ResponseBuilder
114 114
     {
115
-        if ($statusCode < 400 || $statusCode >= 600) {
116
-            throw new InvalidArgumentException("{$statusCode} is not a valid error HTTP status code.");
115
+        if ( $statusCode < 400 || $statusCode >= 600 ) {
116
+            throw new InvalidArgumentException( "{$statusCode} is not a valid error HTTP status code." );
117 117
         }
118 118
 
119
-        return parent::setStatus($statusCode);
119
+        return parent::setStatus( $statusCode );
120 120
     }
121 121
 
122 122
     /**
@@ -139,7 +139,7 @@  discard block
 block discarded – undo
139 139
      */
140 140
     protected function buildErrorData()
141 141
     {
142
-        if (is_null($this->errorCode)) {
142
+        if ( is_null( $this->errorCode ) ) {
143 143
             return null;
144 144
         }
145 145
 
@@ -148,7 +148,7 @@  discard block
 block discarded – undo
148 148
             'message' => $this->message ?: $this->resolveMessage()
149 149
         ];
150 150
 
151
-        return array_merge($data, $this->data);
151
+        return array_merge( $data, $this->data );
152 152
     }
153 153
 
154 154
     /**
@@ -158,10 +158,10 @@  discard block
 block discarded – undo
158 158
      */
159 159
     protected function resolveMessage()
160 160
     {
161
-        if (! $this->translator->has($code = "errors.$this->errorCode")) {
161
+        if ( ! $this->translator->has( $code = "errors.$this->errorCode" ) ) {
162 162
             return null;
163 163
         }
164 164
 
165
-        return $this->translator->trans($code, $this->parameters);
165
+        return $this->translator->trans( $code, $this->parameters );
166 166
     }
167 167
 }
168 168
\ No newline at end of file
Please login to merge, or discard this patch.
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -70,7 +70,7 @@
 block discarded – undo
70 70
     /**
71 71
      * SuccessResponseBuilder constructor.
72 72
      *
73
-     * @param \Illuminate\Contracts\Routing\ResponseFactory|\Laravel\Lumen\Http\ResponseFactory $responseFactory
73
+     * @param \Illuminate\Contracts\Routing\ResponseFactory $responseFactory
74 74
      * @param \Flugg\Responder\ResourceFactory                                                  $resourceFactory
75 75
      * @param \League\Fractal\Manager                                                           $manager
76 76
      */
Please login to merge, or discard this patch.
src/Http/ResponseBuilder.php 1 patch
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -44,7 +44,7 @@  discard block
 block discarded – undo
44 44
      *
45 45
      * @param \Illuminate\Contracts\Routing\ResponseFactory|\Laravel\Lumen\Http\ResponseFactory $responseFactory
46 46
      */
47
-    public function __construct($responseFactory)
47
+    public function __construct( $responseFactory )
48 48
     {
49 49
         $this->responseFactory = $responseFactory;
50 50
     }
@@ -56,15 +56,15 @@  discard block
 block discarded – undo
56 56
      * @param  array    $headers
57 57
      * @return \Illuminate\Http\JsonResponse
58 58
      */
59
-    public function respond(int $statusCode = null, array $headers = []):JsonResponse
59
+    public function respond( int $statusCode = null, array $headers = [ ] ):JsonResponse
60 60
     {
61
-        if (! is_null($statusCode)) {
62
-            $this->setStatus($statusCode);
61
+        if ( ! is_null( $statusCode ) ) {
62
+            $this->setStatus( $statusCode );
63 63
         }
64 64
 
65
-        $data = $this->includeStatusCode($this->toArray());
65
+        $data = $this->includeStatusCode( $this->toArray() );
66 66
 
67
-        return $this->responseFactory->json($data, $this->statusCode, $headers);
67
+        return $this->responseFactory->json( $data, $this->statusCode, $headers );
68 68
     }
69 69
 
70 70
     /**
@@ -73,7 +73,7 @@  discard block
 block discarded – undo
73 73
      * @param  int $statusCode
74 74
      * @return self
75 75
      */
76
-    public function setStatus(int $statusCode):ResponseBuilder
76
+    public function setStatus( int $statusCode ):ResponseBuilder
77 77
     {
78 78
         $this->statusCode = $statusCode;
79 79
 
@@ -86,7 +86,7 @@  discard block
 block discarded – undo
86 86
      * @param  bool $includeStatusCode
87 87
      * @return self
88 88
      */
89
-    public function setIncludeStatusCode(bool $includeStatusCode):ResponseBuilder
89
+    public function setIncludeStatusCode( bool $includeStatusCode ):ResponseBuilder
90 90
     {
91 91
         $this->includeStatusCode = $includeStatusCode;
92 92
 
@@ -100,7 +100,7 @@  discard block
 block discarded – undo
100 100
      */
101 101
     public function toCollection():Collection
102 102
     {
103
-        return new Collection($this->toArray());
103
+        return new Collection( $this->toArray() );
104 104
     }
105 105
 
106 106
     /**
@@ -109,9 +109,9 @@  discard block
 block discarded – undo
109 109
      * @param  int $options
110 110
      * @return string
111 111
      */
112
-    public function toJson($options = 0)
112
+    public function toJson( $options = 0 )
113 113
     {
114
-        return json_encode($this->jsonSerialize(), $options);
114
+        return json_encode( $this->jsonSerialize(), $options );
115 115
     }
116 116
 
117 117
     /**
@@ -137,12 +137,12 @@  discard block
 block discarded – undo
137 137
      * @param  array $data
138 138
      * @return array
139 139
      */
140
-    protected function includeStatusCode(array $data):array
140
+    protected function includeStatusCode( array $data ):array
141 141
     {
142
-        if (! $this->includeStatusCode) {
142
+        if ( ! $this->includeStatusCode ) {
143 143
             return $data;
144 144
         }
145 145
 
146
-        return array_merge(['status' => $this->statusCode], $data);
146
+        return array_merge( [ 'status' => $this->statusCode ], $data );
147 147
     }
148 148
 }
149 149
\ No newline at end of file
Please login to merge, or discard this patch.