Passed
Push — v2 ( e7bb8d...182303 )
by Alexander
02:36
created
src/Transformers/Concerns/MakesResources.php 2 patches
Unused Use Statements   -2 removed lines patch added patch discarded remove patch
@@ -3,8 +3,6 @@
 block discarded – undo
3 3
 namespace Flugg\Responder\Transformers\Concerns;
4 4
 
5 5
 use Closure;
6
-use Illuminate\Database\Eloquent\Model;
7
-use League\Fractal\ParamBag;
8 6
 
9 7
 /**
10 8
  * A trait to be used by a transformer to make resources for relations
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -20,7 +20,7 @@  discard block
 block discarded – undo
20 20
      *
21 21
      * @var \League\Fractal\ResourceInterface[]
22 22
      */
23
-    protected $resources = [];
23
+    protected $resources = [ ];
24 24
 
25 25
     /**
26 26
      * The resource builder resolver callback.
@@ -37,9 +37,9 @@  discard block
 block discarded – undo
37 37
      * @param  string|null                                                    $resourceKey
38 38
      * @return void
39 39
      */
40
-    public function resource($data = null, $transformer = null, string $resourceKey = null)
40
+    public function resource( $data = null, $transformer = null, string $resourceKey = null )
41 41
     {
42
-        return static::resolveResourceBuilder()->make($data, $transformer)->withResourceKey($resourceKey)->get();
42
+        return static::resolveResourceBuilder()->make( $data, $transformer )->withResourceKey( $resourceKey )->get();
43 43
     }
44 44
 
45 45
     /**
@@ -48,7 +48,7 @@  discard block
 block discarded – undo
48 48
      * @param  \Closure $resolver
49 49
      * @return void
50 50
      */
51
-    public static function resourceBuilderResolver(Closure $resolver)
51
+    public static function resourceBuilderResolver( Closure $resolver )
52 52
     {
53 53
         static::$resourceBuilderResolver = $resolver;
54 54
     }
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
      */
61 61
     protected static function resolveResourceBuilder()
62 62
     {
63
-        return call_user_func(static::$currentCursorResolver, $name);
63
+        return call_user_func( static::$currentCursorResolver, $name );
64 64
     }
65 65
 
66 66
     /**
@@ -69,12 +69,12 @@  discard block
 block discarded – undo
69 69
      * @param  string                  $relation
70 70
      * @return \League\Fractal\Resource\ResourceInterface|false
71 71
      */
72
-    protected function makeResource(string $relation, $data)
72
+    protected function makeResource( string $relation, $data )
73 73
     {
74
-        if (key_exists($relation, $this->resources)) {
75
-            return $this->resources[$relation]->setData($data);
74
+        if ( key_exists( $relation, $this->resources ) ) {
75
+            return $this->resources[ $relation ]->setData( $data );
76 76
         }
77 77
 
78
-        return $this->resource($data);
78
+        return $this->resource( $data );
79 79
     }
80 80
 }
81 81
\ No newline at end of file
Please login to merge, or discard this patch.
src/Exceptions/ConvertsExceptions.php 1 patch
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -32,7 +32,7 @@  discard block
 block discarded – undo
32 32
      *
33 33
      * @var array
34 34
      */
35
-    protected $dontConvert = [];
35
+    protected $dontConvert = [ ];
36 36
 
37 37
     /**
38 38
      * Convert an exception to another exception
@@ -41,12 +41,12 @@  discard block
 block discarded – undo
41 41
      * @param  array      $convert
42 42
      * @return void
43 43
      */
44
-    protected function convert(Exception $exception, array $convert)
44
+    protected function convert( Exception $exception, array $convert )
45 45
     {
46
-        foreach ($convert as $source => $target) {
47
-            if ($exception instanceof $source) {
48
-                if (is_callable($target)) {
49
-                    $target($exception);
46
+        foreach ( $convert as $source => $target ) {
47
+            if ( $exception instanceof $source ) {
48
+                if ( is_callable( $target ) ) {
49
+                    $target( $exception );
50 50
                 }
51 51
 
52 52
                 throw new $target;
@@ -60,18 +60,18 @@  discard block
 block discarded – undo
60 60
      * @param  \Exception $exception
61 61
      * @return void
62 62
      */
63
-    protected function convertDefaultException(Exception $exception)
63
+    protected function convertDefaultException( Exception $exception )
64 64
     {
65
-        $this->convert($exception, array_diff_key([
65
+        $this->convert( $exception, array_diff_key( [
66 66
             AuthenticationException::class => UnauthenticatedException::class,
67 67
             AuthorizationException::class => UnauthorizedException::class,
68 68
             NotFoundHttpException::class => PageNotFoundException::class,
69 69
             ModelNotFoundException::class => PageNotFoundException::class,
70 70
             BaseRelationNotFoundException::class => RelationNotFoundException::class,
71
-            ValidationException::class => function ($exception) {
72
-                throw new ValidationFailedException($exception->validator);
71
+            ValidationException::class => function ( $exception ) {
72
+                throw new ValidationFailedException( $exception->validator );
73 73
             },
74
-        ], array_flip($this->dontConvert)));
74
+        ], array_flip( $this->dontConvert ) ) );
75 75
     }
76 76
 
77 77
     /**
@@ -80,11 +80,11 @@  discard block
 block discarded – undo
80 80
      * @param  \Flugg\Responder\Exceptions\Http\HttpException $exception
81 81
      * @return \Illuminate\Http\JsonResponse
82 82
      */
83
-    protected function renderResponse(HttpException $exception): JsonResponse
83
+    protected function renderResponse( HttpException $exception ): JsonResponse
84 84
     {
85
-        return $this->container->make(Responder::class)
86
-            ->error($exception->errorCode(), $exception->message())
87
-            ->data($exception->data())
88
-            ->respond($exception->statusCode());
85
+        return $this->container->make( Responder::class )
86
+            ->error( $exception->errorCode(), $exception->message() )
87
+            ->data( $exception->data() )
88
+            ->respond( $exception->statusCode() );
89 89
     }
90 90
 }
91 91
\ 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
@@ -24,14 +24,14 @@
 block discarded – undo
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->convertDefaultException($exception);
29
+        $this->convertDefaultException( $exception );
30 30
 
31
-        if ($exception instanceof HttpException) {
32
-            return $this->renderResponse($exception);
31
+        if ( $exception instanceof HttpException ) {
32
+            return $this->renderResponse( $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
Please login to merge, or discard this patch.
src/Exceptions/Http/HttpException.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -46,7 +46,7 @@  discard block
 block discarded – undo
46 46
      *
47 47
      * @var array
48 48
      */
49
-    protected $headers = [];
49
+    protected $headers = [ ];
50 50
 
51 51
     /**
52 52
      * Construct the exception class.
@@ -54,9 +54,9 @@  discard block
 block discarded – undo
54 54
      * @param string|null $message
55 55
      * @param array|null  $headers
56 56
      */
57
-    public function __construct(string $message = null, array $headers = null)
57
+    public function __construct( string $message = null, array $headers = null )
58 58
     {
59
-        parent::__construct($this->status, $message ?? $this->message, null, $headers ?? $this->headers);
59
+        parent::__construct( $this->status, $message ?? $this->message, null, $headers ?? $this->headers );
60 60
     }
61 61
 
62 62
     /**
Please login to merge, or discard this patch.
src/Transformers/Concerns/OverridesFractal.php 1 patch
Spacing   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -23,7 +23,7 @@  discard block
 block discarded – undo
23 23
      */
24 24
     public function getAvailableIncludes()
25 25
     {
26
-        return $this->availableIncludes ?: [];
26
+        return $this->availableIncludes ?: [ ];
27 27
     }
28 28
 
29 29
     /**
@@ -33,7 +33,7 @@  discard block
 block discarded – undo
33 33
      */
34 34
     public function getDefaultIncludes()
35 35
     {
36
-        return array_keys($this->load ?: []);
36
+        return array_keys( $this->load ?: [ ] );
37 37
     }
38 38
 
39 39
     /**
@@ -45,17 +45,17 @@  discard block
 block discarded – undo
45 45
      * @return \League\Fractal\Resource\ResourceInterface
46 46
      * @throws \LogicException
47 47
      */
48
-    protected function callIncludeMethod(Scope $scope, $relation, $data)
48
+    protected function callIncludeMethod( Scope $scope, $relation, $data )
49 49
     {
50
-        $parameters = $this->getScopedParameters($scope, $relation);
50
+        $parameters = $this->getScopedParameters( $scope, $relation );
51 51
 
52
-        if ($method = $this->getIncludeMethod($relation)) {
53
-            return $this->$method($this->filterData($data, $relation), $parameters);
54
-        } elseif ($data instanceof Model) {
55
-            return $this->makeResource($relation, $this->filterData($data->$relation, $relation));
52
+        if ( $method = $this->getIncludeMethod( $relation ) ) {
53
+            return $this->$method( $this->filterData( $data, $relation ), $parameters );
54
+        } elseif ( $data instanceof Model ) {
55
+            return $this->makeResource( $relation, $this->filterData( $data->$relation, $relation ) );
56 56
         }
57 57
 
58
-        throw new LogicException('Cannot resolve relation [' . $relation . '] in [' . self::class . ']');
58
+        throw new LogicException( 'Cannot resolve relation [' . $relation . '] in [' . self::class . ']' );
59 59
     }
60 60
 
61 61
     /**
@@ -65,9 +65,9 @@  discard block
 block discarded – undo
65 65
      * @param  string                $relation
66 66
      * @return \League\Fractal\ParamBag
67 67
      */
68
-    protected function getScopedParameters(Scope $scope, string $relation): ParamBag
68
+    protected function getScopedParameters( Scope $scope, string $relation ): ParamBag
69 69
     {
70
-        return $scope->getManager()->getIncludeParams($scope->getIdentifier($relation));
70
+        return $scope->getManager()->getIncludeParams( $scope->getIdentifier( $relation ) );
71 71
     }
72 72
 
73 73
     /**
@@ -76,9 +76,9 @@  discard block
 block discarded – undo
76 76
      * @param  string $relation
77 77
      * @return string|null
78 78
      */
79
-    protected function getIncludeMethod(string $relation)
79
+    protected function getIncludeMethod( string $relation )
80 80
     {
81
-        return method_exists($this, $method = 'include' . ucfirst($relation)) ? $method : null;
81
+        return method_exists( $this, $method = 'include' . ucfirst( $relation ) ) ? $method : null;
82 82
     }
83 83
 
84 84
     /**
@@ -88,13 +88,13 @@  discard block
 block discarded – undo
88 88
      * @param  string $relation
89 89
      * @return mixed
90 90
      */
91
-    protected function filterData($data, string $relation)
91
+    protected function filterData( $data, string $relation )
92 92
     {
93
-        if (! $method = $this->getFilterMethod($relation)) {
93
+        if ( ! $method = $this->getFilterMethod( $relation ) ) {
94 94
             return $data;
95 95
         }
96 96
 
97
-        return $method($data);
97
+        return $method( $data );
98 98
 
99 99
     }
100 100
 
@@ -104,9 +104,9 @@  discard block
 block discarded – undo
104 104
      * @param  string $relation
105 105
      * @return string|null
106 106
      */
107
-    protected function getFilterMethod(string $relation)
107
+    protected function getFilterMethod( string $relation )
108 108
     {
109
-        return method_exists($this, $method = 'filter' . ucfirst($relation)) ? $method : null;
109
+        return method_exists( $this, $method = 'filter' . ucfirst( $relation ) ) ? $method : null;
110 110
     }
111 111
 
112 112
     /**
@@ -116,5 +116,5 @@  discard block
 block discarded – undo
116 116
      * @param  mixed  $data
117 117
      * @return \League\Fractal\Resource\ResourceInterface|false
118 118
      */
119
-    protected abstract function makeResource(string $relation, $data);
119
+    protected abstract function makeResource( string $relation, $data );
120 120
 }
121 121
\ No newline at end of file
Please login to merge, or discard this patch.
src/Transformers/Concerns/HasRelationships.php 1 patch
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -18,14 +18,14 @@  discard block
 block discarded – undo
18 18
      *
19 19
      * @var string[]
20 20
      */
21
-    protected $relations = ['*'];
21
+    protected $relations = [ '*' ];
22 22
 
23 23
     /**
24 24
      * A list of autoloaded default relations.
25 25
      *
26 26
      * @var array
27 27
      */
28
-    protected $load = [];
28
+    protected $load = [ ];
29 29
 
30 30
     /**
31 31
      * Indicates if the transformer has whitelisted all relations.
@@ -34,7 +34,7 @@  discard block
 block discarded – undo
34 34
      */
35 35
     public function allRelationsAllowed(): bool
36 36
     {
37
-        return $this->relations == ['*'];
37
+        return $this->relations == [ '*' ];
38 38
     }
39 39
 
40 40
     /**
@@ -44,7 +44,7 @@  discard block
 block discarded – undo
44 44
      */
45 45
     public function getRelations(): array
46 46
     {
47
-        return array_filter($this->relations, function ($relation) {
47
+        return array_filter( $this->relations, function ( $relation ) {
48 48
             return $relation !== '*';
49 49
         });
50 50
     }
@@ -56,9 +56,9 @@  discard block
 block discarded – undo
56 56
      */
57 57
     public function getDefaultRelations(): array
58 58
     {
59
-        return collect($this->load)->keys()->mapWithKeys(function ($relation) {
60
-            if (method_exists($this, $method = 'load' . ucfirst($relation))) {
61
-                return [$relation => $this->makeEagerLoadCallback($method)];
59
+        return collect( $this->load )->keys()->mapWithKeys( function ( $relation ) {
60
+            if ( method_exists( $this, $method = 'load' . ucfirst( $relation ) ) ) {
61
+                return [ $relation => $this->makeEagerLoadCallback( $method ) ];
62 62
             }
63 63
 
64 64
             return $relation;
@@ -72,13 +72,13 @@  discard block
 block discarded – undo
72 72
      */
73 73
     public function extractDefaultRelations(): array
74 74
     {
75
-        return collect($this->getDefaultRelations())->merge($this->load->map(function ($transformer, $relation) {
76
-            return collect($this->resolveTransformer($transformer)->extractDefaultRelations())
75
+        return collect( $this->getDefaultRelations() )->merge( $this->load->map( function ( $transformer, $relation ) {
76
+            return collect( $this->resolveTransformer( $transformer )->extractDefaultRelations() )
77 77
                 ->keys()
78
-                ->map(function ($nestedRelation) use ($relation) {
78
+                ->map( function ( $nestedRelation ) use ($relation) {
79 79
                     return "$relation.$nestedRelation";
80 80
                 });
81
-        }))->all();
81
+        }) )->all();
82 82
     }
83 83
 
84 84
     /**
@@ -87,10 +87,10 @@  discard block
 block discarded – undo
87 87
      * @param  string $method
88 88
      * @return \Closure
89 89
      */
90
-    public function makeEagerLoadCallback(string $method): Closure
90
+    public function makeEagerLoadCallback( string $method ): Closure
91 91
     {
92
-        return function ($query) use ($method) {
93
-            return $this->$method($query);
92
+        return function ( $query ) use ($method) {
93
+            return $this->$method( $query );
94 94
         };
95 95
     }
96 96
 }
97 97
\ No newline at end of file
Please login to merge, or discard this patch.