Passed
Push — v2 ( b247ab...8c624d )
by Alexander
02:21
created
src/Transformers/TransformerResolver.php 2 patches
Doc Comments   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -110,8 +110,8 @@  discard block
 block discarded – undo
110 110
     /**
111 111
      * Resolve a transformer from the transformable element.
112 112
      *
113
-     * @param  mixed $transformable
114
-     * @return \Flugg\Responder\Contracts\Transformable|callable|null
113
+     * @param  Transformable|null $transformable
114
+     * @return callable
115 115
      */
116 116
     protected function resolveTransformer($transformable)
117 117
     {
@@ -129,7 +129,7 @@  discard block
 block discarded – undo
129 129
     /**
130 130
      * Resolve a fallback closure transformer just returning the data directly.
131 131
      *
132
-     * @return callable
132
+     * @return \Closure
133 133
      */
134 134
     protected function resolveFallbackTransformer()
135 135
     {
Please login to merge, or discard this patch.
Spacing   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -30,14 +30,14 @@  discard block
 block discarded – undo
30 30
      *
31 31
      * @var array
32 32
      */
33
-    protected $bindings = [];
33
+    protected $bindings = [ ];
34 34
 
35 35
     /**
36 36
      * Construct the resolver class.
37 37
      *
38 38
      * @param \Illuminate\Contracts\Container\Container $container
39 39
      */
40
-    public function __construct(Container $container)
40
+    public function __construct( Container $container )
41 41
     {
42 42
         $this->container = $container;
43 43
     }
@@ -49,11 +49,11 @@  discard block
 block discarded – undo
49 49
      * @param  string|callback|null $transformer
50 50
      * @return void
51 51
      */
52
-    public function bind($transformable, $transformer = null)
52
+    public function bind( $transformable, $transformer = null )
53 53
     {
54
-        $this->bindings = array_merge($this->bindings, is_array($transformable) ? $transformable : [
54
+        $this->bindings = array_merge( $this->bindings, is_array( $transformable ) ? $transformable : [
55 55
             $transformable => $transformer,
56
-        ]);
56
+        ] );
57 57
     }
58 58
 
59 59
     /**
@@ -63,13 +63,13 @@  discard block
 block discarded – undo
63 63
      * @return \Flugg\Responder\Transformers\Transformer|callable
64 64
      * @throws \Flugg\Responder\Exceptions\InvalidTransformerException
65 65
      */
66
-    public function resolve($transformer)
66
+    public function resolve( $transformer )
67 67
     {
68
-        if (is_string($transformer)) {
69
-            return $this->container->make($transformer);
68
+        if ( is_string( $transformer ) ) {
69
+            return $this->container->make( $transformer );
70 70
         }
71 71
 
72
-        if (! is_callable($transformer) && ! $transformer instanceof Transformer) {
72
+        if ( ! is_callable( $transformer ) && ! $transformer instanceof Transformer ) {
73 73
             throw new InvalidTransformerException;
74 74
         }
75 75
 
@@ -82,12 +82,12 @@  discard block
 block discarded – undo
82 82
      * @param  mixed $data
83 83
      * @return \Flugg\Responder\Transformers\Transformer|callable|null
84 84
      */
85
-    public function resolveFromData($data)
85
+    public function resolveFromData( $data )
86 86
     {
87
-        $transformable = $this->resolveTransformable($data);
88
-        $transformer = $this->resolveTransformer($transformable);
87
+        $transformable = $this->resolveTransformable( $data );
88
+        $transformer = $this->resolveTransformer( $transformable );
89 89
 
90
-        return $this->resolve($transformer);
90
+        return $this->resolve( $transformer );
91 91
     }
92 92
 
93 93
     /**
@@ -96,10 +96,10 @@  discard block
 block discarded – undo
96 96
      * @param  mixed $data
97 97
      * @return \Flugg\Responder\Contracts\Transformable|null
98 98
      */
99
-    protected function resolveTransformable($data)
99
+    protected function resolveTransformable( $data )
100 100
     {
101
-        if (is_array($data) || $data instanceof Traversable) {
102
-            foreach ($data as $item) {
101
+        if ( is_array( $data ) || $data instanceof Traversable ) {
102
+            foreach ( $data as $item ) {
103 103
                 return $item;
104 104
             }
105 105
         }
@@ -113,13 +113,13 @@  discard block
 block discarded – undo
113 113
      * @param  mixed $transformable
114 114
      * @return \Flugg\Responder\Contracts\Transformable|callable|null
115 115
      */
116
-    protected function resolveTransformer($transformable)
116
+    protected function resolveTransformer( $transformable )
117 117
     {
118
-        if (is_object($transformable) && key_exists(get_class($transformable), $this->bindings)) {
119
-            return $this->bindings[get_class($transformable)];
118
+        if ( is_object( $transformable ) && key_exists( get_class( $transformable ), $this->bindings ) ) {
119
+            return $this->bindings[ get_class( $transformable ) ];
120 120
         }
121 121
 
122
-        if ($transformable instanceof Transformable) {
122
+        if ( $transformable instanceof Transformable ) {
123 123
             return $transformable->transformer();
124 124
         }
125 125
 
@@ -133,7 +133,7 @@  discard block
 block discarded – undo
133 133
      */
134 134
     protected function resolveFallbackTransformer()
135 135
     {
136
-        return function ($data) {
136
+        return function ( $data ) {
137 137
             return $data instanceof Arrayable ? $data->toArray() : $data;
138 138
         };
139 139
     }
Please login to merge, or discard this patch.
src/TransformBuilder.php 1 patch
Spacing   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -65,21 +65,21 @@  discard block
 block discarded – undo
65 65
      *
66 66
      * @var array
67 67
      */
68
-    protected $with = [];
68
+    protected $with = [ ];
69 69
 
70 70
     /**
71 71
      * A list of excluded relations.
72 72
      *
73 73
      * @var array
74 74
      */
75
-    protected $without = [];
75
+    protected $without = [ ];
76 76
 
77 77
     /**
78 78
      * A list of sparse fieldsets.
79 79
      *
80 80
      * @var array
81 81
      */
82
-    protected $only = [];
82
+    protected $only = [ ];
83 83
 
84 84
     /**
85 85
      * Construct the builder class.
@@ -88,7 +88,7 @@  discard block
 block discarded – undo
88 88
      * @param \Flugg\Responder\Contracts\TransformFactory            $transformFactory
89 89
      * @param \Flugg\Responder\Contracts\Pagination\PaginatorFactory $paginatorFactory
90 90
      */
91
-    public function __construct(ResourceFactory $resourceFactory, TransformFactory $transformFactory, PaginatorFactory $paginatorFactory)
91
+    public function __construct( ResourceFactory $resourceFactory, TransformFactory $transformFactory, PaginatorFactory $paginatorFactory )
92 92
     {
93 93
         $this->resourceFactory = $resourceFactory;
94 94
         $this->transformFactory = $transformFactory;
@@ -103,14 +103,14 @@  discard block
 block discarded – undo
103 103
      * @param  string|null                                                    $resourceKey
104 104
      * @return $this
105 105
      */
106
-    public function resource($data = null, $transformer = null, string $resourceKey = null)
106
+    public function resource( $data = null, $transformer = null, string $resourceKey = null )
107 107
     {
108
-        $this->resource = $this->resourceFactory->make($data, $transformer, $resourceKey);
108
+        $this->resource = $this->resourceFactory->make( $data, $transformer, $resourceKey );
109 109
 
110
-        if ($data instanceof CursorPaginator) {
111
-            $this->cursor($this->paginatorFactory->makeCursor($data));
112
-        } elseif ($data instanceof LengthAwarePaginator) {
113
-            $this->paginator($this->paginatorFactory->make($data));
110
+        if ( $data instanceof CursorPaginator ) {
111
+            $this->cursor( $this->paginatorFactory->makeCursor( $data ) );
112
+        } elseif ( $data instanceof LengthAwarePaginator ) {
113
+            $this->paginator( $this->paginatorFactory->make( $data ) );
114 114
         }
115 115
 
116 116
         return $this;
@@ -122,9 +122,9 @@  discard block
 block discarded – undo
122 122
      * @param  \League\Fractal\Pagination\Cursor $cursor
123 123
      * @return $this
124 124
      */
125
-    public function cursor(Cursor $cursor)
125
+    public function cursor( Cursor $cursor )
126 126
     {
127
-        $this->resource->setCursor($cursor);
127
+        $this->resource->setCursor( $cursor );
128 128
 
129 129
         return $this;
130 130
     }
@@ -135,9 +135,9 @@  discard block
 block discarded – undo
135 135
      * @param  \League\Fractal\Pagination\IlluminatePaginatorAdapter $paginator
136 136
      * @return $this
137 137
      */
138
-    public function paginator(IlluminatePaginatorAdapter $paginator)
138
+    public function paginator( IlluminatePaginatorAdapter $paginator )
139 139
     {
140
-        $this->resource->setPaginator($paginator);
140
+        $this->resource->setPaginator( $paginator );
141 141
 
142 142
         return $this;
143 143
     }
@@ -148,9 +148,9 @@  discard block
 block discarded – undo
148 148
      * @param  array $data
149 149
      * @return $this
150 150
      */
151
-    public function meta(array $data)
151
+    public function meta( array $data )
152 152
     {
153
-        $this->resource->setMeta($data);
153
+        $this->resource->setMeta( $data );
154 154
 
155 155
         return $this;
156 156
     }
@@ -161,9 +161,9 @@  discard block
 block discarded – undo
161 161
      * @param  string[]|string $relations
162 162
      * @return $this
163 163
      */
164
-    public function with($relations)
164
+    public function with( $relations )
165 165
     {
166
-        $this->with = array_merge($this->with, is_array($relations) ? $relations : func_get_args());
166
+        $this->with = array_merge( $this->with, is_array( $relations ) ? $relations : func_get_args() );
167 167
 
168 168
         return $this;
169 169
     }
@@ -174,9 +174,9 @@  discard block
 block discarded – undo
174 174
      * @param  string[]|string $relations
175 175
      * @return $this
176 176
      */
177
-    public function without($relations)
177
+    public function without( $relations )
178 178
     {
179
-        $this->without = array_merge($this->without, is_array($relations) ? $relations : func_get_args());
179
+        $this->without = array_merge( $this->without, is_array( $relations ) ? $relations : func_get_args() );
180 180
 
181 181
         return $this;
182 182
     }
@@ -187,9 +187,9 @@  discard block
 block discarded – undo
187 187
      * @param  string[]|string $fields
188 188
      * @return $this
189 189
      */
190
-    public function only($fields)
190
+    public function only( $fields )
191 191
     {
192
-        $this->only = array_merge($this->only, is_array($fields) ? $fields : func_get_args());
192
+        $this->only = array_merge( $this->only, is_array( $fields ) ? $fields : func_get_args() );
193 193
 
194 194
         return $this;
195 195
     }
@@ -201,13 +201,13 @@  discard block
 block discarded – undo
201 201
      * @return $this
202 202
      * @throws \Flugg\Responder\Exceptions\InvalidSerializerException
203 203
      */
204
-    public function serializer($serializer)
204
+    public function serializer( $serializer )
205 205
     {
206
-        if (is_string($serializer)) {
206
+        if ( is_string( $serializer ) ) {
207 207
             $serializer = new $serializer;
208 208
         }
209 209
 
210
-        if (! $serializer instanceof SerializerAbstract) {
210
+        if ( ! $serializer instanceof SerializerAbstract ) {
211 211
             throw new InvalidSerializerException;
212 212
         }
213 213
 
@@ -223,13 +223,13 @@  discard block
 block discarded – undo
223 223
      */
224 224
     public function transform(): array
225 225
     {
226
-        $this->prepareRelations($this->resource->getData(), $this->resource->getTransformer());
226
+        $this->prepareRelations( $this->resource->getData(), $this->resource->getTransformer() );
227 227
 
228
-        return $this->transformFactory->make($this->resource ?: new NullResource, $this->serializer, [
228
+        return $this->transformFactory->make( $this->resource ?: new NullResource, $this->serializer, [
229 229
             'includes' => $this->with,
230 230
             'excludes' => $this->without,
231 231
             'fieldsets' => $this->only,
232
-        ]);
232
+        ] );
233 233
     }
234 234
 
235 235
     /**
@@ -239,18 +239,18 @@  discard block
 block discarded – undo
239 239
      * @param  \Flugg\Responder\Transformers\Transformer|callable|string|null $transformer
240 240
      * @return void
241 241
      */
242
-    protected function prepareRelations($data, $transformer)
242
+    protected function prepareRelations( $data, $transformer )
243 243
     {
244
-        if ($transformer instanceof Transformer) {
245
-            $this->with($transformer->extractDefaultRelations());
244
+        if ( $transformer instanceof Transformer ) {
245
+            $this->with( $transformer->extractDefaultRelations() );
246 246
         }
247 247
 
248
-        if ($data instanceof Model || $data instanceof Collection) {
249
-            $data->load($this->with);
248
+        if ( $data instanceof Model || $data instanceof Collection ) {
249
+            $data->load( $this->with );
250 250
         }
251 251
 
252
-        $this->with = collect($this->with)->map(function ($value, $key) {
253
-            return is_numeric($key) ? $value : $key;
252
+        $this->with = collect( $this->with )->map( function ( $value, $key ) {
253
+            return is_numeric( $key ) ? $value : $key;
254 254
         })->values()->all();
255 255
     }
256 256
 }
257 257
\ No newline at end of file
Please login to merge, or discard this patch.