Passed
Push — master ( 4315d5...4a61dc )
by Alexander
48s
created
src/ResponderServiceProvider.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -108,7 +108,7 @@
 block discarded – undo
108 108
     /**
109 109
      * Get the services provided by the provider.
110 110
      *
111
-     * @return array
111
+     * @return string[]
112 112
      */
113 113
     public function provides()
114 114
     {
Please login to merge, or discard this patch.
Unused Use Statements   -1 removed lines patch added patch discarded remove patch
@@ -3,7 +3,6 @@
 block discarded – undo
3 3
 namespace Flugg\Responder;
4 4
 
5 5
 use Flugg\Responder\Console\MakeTransformer;
6
-use Flugg\Responder\Contracts\Manager as ManagerContract;
7 6
 use Flugg\Responder\Http\ErrorResponseBuilder;
8 7
 use Flugg\Responder\Http\SuccessResponseBuilder;
9 8
 use Illuminate\Foundation\Application as Laravel;
Please login to merge, or discard this patch.
Spacing   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -43,18 +43,18 @@  discard block
 block discarded – undo
43 43
      */
44 44
     public function boot()
45 45
     {
46
-        if ($this->app instanceof Laravel && $this->app->runningInConsole()) {
46
+        if ( $this->app instanceof Laravel && $this->app->runningInConsole() ) {
47 47
             $this->bootLaravelApplication();
48 48
 
49
-        } elseif ($this->app instanceof Lumen) {
49
+        } elseif ( $this->app instanceof Lumen ) {
50 50
             $this->bootLumenApplication();
51 51
         }
52 52
 
53
-        $this->mergeConfigFrom(__DIR__ . '/../resources/config/responder.php', 'responder');
53
+        $this->mergeConfigFrom( __DIR__ . '/../resources/config/responder.php', 'responder' );
54 54
 
55
-        $this->commands([
55
+        $this->commands( [
56 56
             MakeTransformer::class
57
-        ]);
57
+        ] );
58 58
 
59 59
         include __DIR__ . '/helpers.php';
60 60
     }
@@ -69,8 +69,8 @@  discard block
 block discarded – undo
69 69
         $this->registerFractal();
70 70
         $this->registerResponseBuilders();
71 71
 
72
-        $this->app->bind(Responder::class, function ($app) {
73
-            return new Responder($app[SuccessResponseBuilder::class], $app[ErrorResponseBuilder::class]);
72
+        $this->app->bind( Responder::class, function ( $app ) {
73
+            return new Responder( $app[ SuccessResponseBuilder::class ], $app[ ErrorResponseBuilder::class ] );
74 74
         });
75 75
 
76 76
         $this->registerAliases();
@@ -83,7 +83,7 @@  discard block
 block discarded – undo
83 83
      */
84 84
     public function provides()
85 85
     {
86
-        return ['responder', 'responder.success', 'responder.error', 'responder.manager', 'responder.serializer'];
86
+        return [ 'responder', 'responder.success', 'responder.error', 'responder.manager', 'responder.serializer' ];
87 87
     }
88 88
 
89 89
     /**
@@ -94,17 +94,17 @@  discard block
 block discarded – undo
94 94
      */
95 95
     protected function registerFractal()
96 96
     {
97
-        $this->app->bind(SerializerAbstract::class, function ($app) {
98
-            $serializer = $app->config->get('responder.serializer');
97
+        $this->app->bind( SerializerAbstract::class, function ( $app ) {
98
+            $serializer = $app->config->get( 'responder.serializer' );
99 99
 
100 100
             return new $serializer;
101 101
         });
102 102
 
103
-        $this->app->bind(Manager::class, function ($app) {
104
-            return (new Manager())->setSerializer($app[SerializerAbstract::class]);
103
+        $this->app->bind( Manager::class, function ( $app ) {
104
+            return (new Manager())->setSerializer( $app[ SerializerAbstract::class ] );
105 105
         });
106 106
 
107
-        $this->app->bind(ResourceFactory::class, function () {
107
+        $this->app->bind( ResourceFactory::class, function () {
108 108
             return new ResourceFactory();
109 109
         });
110 110
     }
@@ -116,22 +116,22 @@  discard block
 block discarded – undo
116 116
      */
117 117
     protected function registerResponseBuilders()
118 118
     {
119
-        $this->app->bind(SuccessResponseBuilder::class, function ($app) {
120
-            $builder = new SuccessResponseBuilder(response(), $app[ResourceFactory::class], $app[Manager::class]);
119
+        $this->app->bind( SuccessResponseBuilder::class, function ( $app ) {
120
+            $builder = new SuccessResponseBuilder( response(), $app[ ResourceFactory::class ], $app[ Manager::class ] );
121 121
 
122
-            if ($parameter = $app->config->get('responder.load_relations_from_parameter')) {
123
-                $builder->include($this->app[Request::class]->input($parameter, []));
122
+            if ( $parameter = $app->config->get( 'responder.load_relations_from_parameter' ) ) {
123
+                $builder->include( $this->app[ Request::class ]->input( $parameter, [ ] ) );
124 124
             }
125 125
 
126
-            $builder->setIncludeSuccessFlag($app->config->get('responder.include_success_flag'));
127
-            return $builder->setIncludeStatusCode($app->config->get('responder.include_status_code'));
126
+            $builder->setIncludeSuccessFlag( $app->config->get( 'responder.include_success_flag' ) );
127
+            return $builder->setIncludeStatusCode( $app->config->get( 'responder.include_status_code' ) );
128 128
         });
129 129
 
130
-        $this->app->bind(ErrorResponseBuilder::class, function ($app) {
131
-            $builder = new ErrorResponseBuilder(response(), $app['translator']);
130
+        $this->app->bind( ErrorResponseBuilder::class, function ( $app ) {
131
+            $builder = new ErrorResponseBuilder( response(), $app[ 'translator' ] );
132 132
 
133
-            $builder->setIncludeSuccessFlag($app->config->get('responder.include_success_flag'));
134
-            return $builder->setIncludeStatusCode($app->config->get('responder.include_status_code'));
133
+            $builder->setIncludeSuccessFlag( $app->config->get( 'responder.include_success_flag' ) );
134
+            return $builder->setIncludeStatusCode( $app->config->get( 'responder.include_status_code' ) );
135 135
         });
136 136
     }
137 137
 
@@ -142,11 +142,11 @@  discard block
 block discarded – undo
142 142
      */
143 143
     protected function registerAliases()
144 144
     {
145
-        $this->app->alias(Responder::class, 'responder');
146
-        $this->app->alias(SuccessResponseBuilder::class, 'responder.success');
147
-        $this->app->alias(ErrorResponseBuilder::class, 'responder.error');
148
-        $this->app->alias(Manager::class, 'responder.manager');
149
-        $this->app->alias(Manager::class, 'responder.serializer');
145
+        $this->app->alias( Responder::class, 'responder' );
146
+        $this->app->alias( SuccessResponseBuilder::class, 'responder.success' );
147
+        $this->app->alias( ErrorResponseBuilder::class, 'responder.error' );
148
+        $this->app->alias( Manager::class, 'responder.manager' );
149
+        $this->app->alias( Manager::class, 'responder.serializer' );
150 150
     }
151 151
 
152 152
     /**
@@ -156,13 +156,13 @@  discard block
 block discarded – undo
156 156
      */
157 157
     protected function bootLaravelApplication()
158 158
     {
159
-        $this->publishes([
160
-            __DIR__ . '/../resources/config/responder.php' => config_path('responder.php')
161
-        ], 'config');
159
+        $this->publishes( [
160
+            __DIR__ . '/../resources/config/responder.php' => config_path( 'responder.php' )
161
+        ], 'config' );
162 162
 
163
-        $this->publishes([
164
-            __DIR__ . '/../resources/lang/en/errors.php' => base_path('resources/lang/en/errors.php')
165
-        ], 'lang');
163
+        $this->publishes( [
164
+            __DIR__ . '/../resources/lang/en/errors.php' => base_path( 'resources/lang/en/errors.php' )
165
+        ], 'lang' );
166 166
     }
167 167
 
168 168
     /**
@@ -172,6 +172,6 @@  discard block
 block discarded – undo
172 172
      */
173 173
     protected function bootLumenApplication()
174 174
     {
175
-        $this->app->configure('responder');
175
+        $this->app->configure( 'responder' );
176 176
     }
177 177
 }
Please login to merge, or discard this patch.
src/Responder.php 2 patches
Unused Use Statements   -2 removed lines patch added patch discarded remove patch
@@ -2,10 +2,8 @@
 block discarded – undo
2 2
 
3 3
 namespace Flugg\Responder;
4 4
 
5
-use Flugg\Responder\ErrorResponse;
6 5
 use Flugg\Responder\Http\ErrorResponseBuilder;
7 6
 use Flugg\Responder\Http\SuccessResponseBuilder;
8
-use Flugg\Responder\SuccessResponse;
9 7
 use Illuminate\Http\JsonResponse;
10 8
 
11 9
 /**
Please login to merge, or discard this patch.
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
      * @param \Flugg\Responder\Http\ErrorResponseBuilder   $errorResponse
38 38
      * @param \Flugg\Responder\Http\SuccessResponseBuilder $successResponse
39 39
      */
40
-    public function __construct(SuccessResponseBuilder $successResponse, ErrorResponseBuilder $errorResponse)
40
+    public function __construct( SuccessResponseBuilder $successResponse, ErrorResponseBuilder $errorResponse )
41 41
     {
42 42
         $this->successResponse = $successResponse;
43 43
         $this->errorResponse = $errorResponse;
@@ -51,15 +51,15 @@  discard block
 block discarded – undo
51 51
      * @param  mixed       $message
52 52
      * @return \Illuminate\Http\JsonResponse
53 53
      */
54
-    public function error($errorCode = null, int $statusCode = null, $message = null):JsonResponse
54
+    public function error( $errorCode = null, int $statusCode = null, $message = null ):JsonResponse
55 55
     {
56
-        if ($exception = config("responder.exceptions.$errorCode")) {
57
-            if (class_exists($exception)) {
56
+        if ( $exception = config( "responder.exceptions.$errorCode" ) ) {
57
+            if ( class_exists( $exception ) ) {
58 58
                 throw new $exception();
59 59
             }
60 60
         }
61 61
 
62
-        return $this->errorResponse->setError($errorCode, $message)->respond($statusCode);
62
+        return $this->errorResponse->setError( $errorCode, $message )->respond( $statusCode );
63 63
     }
64 64
 
65 65
     /**
@@ -70,17 +70,17 @@  discard block
 block discarded – undo
70 70
      * @param  array      $meta
71 71
      * @return \Illuminate\Http\JsonResponse
72 72
      */
73
-    public function success($data = null, $statusCode = null, array $meta = []):JsonResponse
73
+    public function success( $data = null, $statusCode = null, array $meta = [ ] ):JsonResponse
74 74
     {
75
-        if (is_integer($data)) {
76
-            list($data, $statusCode, $meta) = [null, $data, is_array($statusCode) ? $statusCode : []];
75
+        if ( is_integer( $data ) ) {
76
+            list($data, $statusCode, $meta) = [ null, $data, is_array( $statusCode ) ? $statusCode : [ ] ];
77 77
         }
78 78
 
79
-        if (is_array($statusCode)) {
80
-            list($statusCode, $meta) = [200, $statusCode];
79
+        if ( is_array( $statusCode ) ) {
80
+            list($statusCode, $meta) = [ 200, $statusCode ];
81 81
         }
82 82
 
83
-        return $this->successResponse->transform($data)->addMeta($meta)->respond($statusCode);
83
+        return $this->successResponse->transform( $data )->addMeta( $meta )->respond( $statusCode );
84 84
     }
85 85
 
86 86
     /**
@@ -90,8 +90,8 @@  discard block
 block discarded – undo
90 90
      * @param  callable|string|null $transformer
91 91
      * @return \Flugg\Responder\Http\SuccessResponseBuilder
92 92
      */
93
-    public function transform($data = null, $transformer = null):SuccessResponseBuilder
93
+    public function transform( $data = null, $transformer = null ):SuccessResponseBuilder
94 94
     {
95
-        return $this->successResponse->transform($data, $transformer);
95
+        return $this->successResponse->transform( $data, $transformer );
96 96
     }
97 97
 }
Please login to merge, or discard this patch.
src/helpers.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -2,7 +2,7 @@  discard block
 block discarded – undo
2 2
 
3 3
 use Flugg\Responder\Responder;
4 4
 
5
-if (! function_exists('responder')) {
5
+if ( ! function_exists( 'responder' ) ) {
6 6
 
7 7
     /**
8 8
      * A helper method to quickly resolve the responder out of the service container.
@@ -11,6 +11,6 @@  discard block
 block discarded – undo
11 11
      */
12 12
     function responder()
13 13
     {
14
-        return app(Responder::class);
14
+        return app( Responder::class );
15 15
     }
16 16
 }
17 17
\ No newline at end of file
Please login to merge, or discard this patch.
src/Exceptions/Http/ValidationFailedException.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -39,7 +39,7 @@  discard block
 block discarded – undo
39 39
      *
40 40
      * @param Validator $validator
41 41
      */
42
-    public function __construct(Validator $validator)
42
+    public function __construct( Validator $validator )
43 43
     {
44 44
         $this->validator = $validator;
45 45
 
@@ -53,6 +53,6 @@  discard block
 block discarded – undo
53 53
      */
54 54
     public function getData()
55 55
     {
56
-        return ['fields' => $this->validator->getMessageBag()->toArray()];
56
+        return [ 'fields' => $this->validator->getMessageBag()->toArray() ];
57 57
     }
58 58
 }
59 59
\ No newline at end of file
Please login to merge, or discard this patch.
src/Contracts/Transformable.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -38,7 +38,7 @@
 block discarded – undo
38 38
      * @param  string $key
39 39
      * @return bool
40 40
      */
41
-    public function relationLoaded($key);
41
+    public function relationLoaded( $key );
42 42
 
43 43
     /**
44 44
      * Convert the model instance to an array.
Please login to merge, or discard this patch.
src/Traits/ThrowsApiErrors.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -25,9 +25,9 @@
 block discarded – undo
25 25
      * @return void
26 26
      * @throws ValidationFailedException
27 27
      */
28
-    protected function failedValidation(Validator $validator)
28
+    protected function failedValidation( Validator $validator )
29 29
     {
30
-        throw new ValidationFailedException($validator);
30
+        throw new ValidationFailedException( $validator );
31 31
     }
32 32
 
33 33
     /**
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.