Completed
Pull Request — master (#548)
by Guilherme
01:56
created
src/Tools/RouteMatcher.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -50,14 +50,14 @@  discard block
 block discarded – undo
50 50
 
51 51
     private function getAllRoutes(bool $usingDingoRouter, array $versions = [])
52 52
     {
53
-        if (! $usingDingoRouter) {
53
+        if (!$usingDingoRouter) {
54 54
             return RouteFacade::getRoutes();
55 55
         }
56 56
 
57 57
         $allRouteCollections = app(\Dingo\Api\Routing\Router::class)->getRoutes();
58 58
 
59 59
         return collect($allRouteCollections)
60
-            ->flatMap(function (RouteCollection $collection) {
60
+            ->flatMap(function(RouteCollection $collection) {
61 61
                 return $collection->getRoutes();
62 62
             })->toArray();
63 63
     }
@@ -65,7 +65,7 @@  discard block
 block discarded – undo
65 65
     private function shouldIncludeRoute(Route $route, array $routeRule, array $mustIncludes, bool $usingDingoRouter)
66 66
     {
67 67
         $matchesVersion = $usingDingoRouter
68
-            ? ! empty(array_intersect($route->versions(), $routeRule['match']['versions'] ?? []))
68
+            ? !empty(array_intersect($route->versions(), $routeRule['match']['versions'] ?? []))
69 69
             : true;
70 70
 
71 71
         return str_is($mustIncludes, $route->getName())
Please login to merge, or discard this patch.
src/Tools/ResponseResolver.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -48,8 +48,8 @@
 block discarded – undo
48 48
             /** @var Response[]|null $response */
49 49
             $responses = $strategy($this->route, $tags, $routeProps);
50 50
 
51
-            if (! is_null($responses)) {
52
-                return array_map(function (Response $response) {
51
+            if (!is_null($responses)) {
52
+                return array_map(function(Response $response) {
53 53
                     return ['status' => $response->getStatusCode(), 'content' => $this->getResponseContent($response)];
54 54
                 }, $responses);
55 55
             }
Please login to merge, or discard this patch.
src/Tools/ResponseStrategies/ResponseTagStrategy.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -33,7 +33,7 @@  discard block
 block discarded – undo
33 33
     protected function getDocBlockResponses(array $tags)
34 34
     {
35 35
         $responseTags = array_values(
36
-            array_filter($tags, function ($tag) {
36
+            array_filter($tags, function($tag) {
37 37
                 return $tag instanceof Tag && strtolower($tag->getName()) === 'response';
38 38
             })
39 39
         );
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
42 42
             return;
43 43
         }
44 44
 
45
-        return array_map(function (Tag $responseTag) {
45
+        return array_map(function(Tag $responseTag) {
46 46
             preg_match('/^(\d{3})?\s?([\s\S]*)$/', $responseTag->getContent(), $result);
47 47
 
48 48
             $status = $result[1] ?: 200;
Please login to merge, or discard this patch.
src/Tools/ResponseStrategies/ResponseFileStrategy.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -34,7 +34,7 @@  discard block
 block discarded – undo
34 34
     {
35 35
         // avoid "holes" in the keys of the filtered array, by using array_values on the filtered array
36 36
         $responseFileTags = array_values(
37
-            array_filter($tags, function ($tag) {
37
+            array_filter($tags, function($tag) {
38 38
                 return $tag instanceof Tag && strtolower($tag->getName()) === 'responsefile';
39 39
             })
40 40
         );
@@ -43,11 +43,11 @@  discard block
 block discarded – undo
43 43
             return;
44 44
         }
45 45
 
46
-        return array_map(function (Tag $responseFileTag) {
46
+        return array_map(function(Tag $responseFileTag) {
47 47
             preg_match('/^(\d{3})?\s?([\S]*[\s]*?)(\{.*\})?$/', $responseFileTag->getContent(), $result);
48 48
             $status = $result[1] ?: 200;
49 49
             $content = $result[2] ? file_get_contents(storage_path(trim($result[2])), true) : '{}';
50
-            $json = ! empty($result[3]) ? str_replace("'", '"', $result[3]) : '{}';
50
+            $json = !empty($result[3]) ? str_replace("'", '"', $result[3]) : '{}';
51 51
             $merged = array_merge(json_decode($content, true), json_decode($json, true));
52 52
 
53 53
             return new JsonResponse($merged, (int) $status);
Please login to merge, or discard this patch.
src/Tools/ResponseStrategies/TransformerTagsStrategy.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -47,7 +47,7 @@  discard block
 block discarded – undo
47 47
 
48 48
             $fractal = new Manager();
49 49
  
50
-            if (! is_null(config('apidoc.fractal.serializer'))) {
50
+            if (!is_null(config('apidoc.fractal.serializer'))) {
51 51
                 $fractal->setSerializer(app(config('apidoc.fractal.serializer')));
52 52
             }
53 53
 
@@ -79,7 +79,7 @@  discard block
 block discarded – undo
79 79
      */
80 80
     private function getClassToBeTransformed(array $tags, ReflectionMethod $transformerMethod)
81 81
     {
82
-        $modelTag = array_first(array_filter($tags, function ($tag) {
82
+        $modelTag = array_first(array_filter($tags, function($tag) {
83 83
             return ($tag instanceof Tag) && strtolower($tag->getName()) == 'transformermodel';
84 84
         }));
85 85
 
@@ -88,7 +88,7 @@  discard block
 block discarded – undo
88 88
             $type = $modelTag->getContent();
89 89
         } else {
90 90
             $parameter = array_first($transformerMethod->getParameters());
91
-            if ($parameter->hasType() && ! $parameter->getType()->isBuiltin() && class_exists((string) $parameter->getType())) {
91
+            if ($parameter->hasType() && !$parameter->getType()->isBuiltin() && class_exists((string) $parameter->getType())) {
92 92
                 // ladies and gentlemen, we have a type!
93 93
                 $type = (string) $parameter->getType();
94 94
             }
@@ -133,7 +133,7 @@  discard block
 block discarded – undo
133 133
     private function getTransformerTag(array $tags)
134 134
     {
135 135
         $transFormerTags = array_values(
136
-            array_filter($tags, function ($tag) {
136
+            array_filter($tags, function($tag) {
137 137
                 return ($tag instanceof Tag) && in_array(strtolower($tag->getName()), ['transformer', 'transformercollection']);
138 138
             })
139 139
         );
Please login to merge, or discard this patch.
src/ApiDocGeneratorServiceProvider.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -15,17 +15,17 @@
 block discarded – undo
15 15
      */
16 16
     public function boot()
17 17
     {
18
-        $this->loadViewsFrom(__DIR__.'/../resources/views/', 'apidoc');
18
+        $this->loadViewsFrom(__DIR__ . '/../resources/views/', 'apidoc');
19 19
 
20 20
         $this->publishes([
21
-            __DIR__.'/../resources/views' => app()->basePath().'/resources/views/vendor/apidoc',
21
+            __DIR__ . '/../resources/views' => app()->basePath() . '/resources/views/vendor/apidoc',
22 22
         ], 'apidoc-views');
23 23
 
24 24
         $this->publishes([
25
-            __DIR__.'/../config/apidoc.php' => app()->basePath().'/config/apidoc.php',
25
+            __DIR__ . '/../config/apidoc.php' => app()->basePath() . '/config/apidoc.php',
26 26
         ], 'apidoc-config');
27 27
 
28
-        $this->mergeConfigFrom(__DIR__.'/../config/apidoc.php', 'apidoc');
28
+        $this->mergeConfigFrom(__DIR__ . '/../config/apidoc.php', 'apidoc');
29 29
 
30 30
         if ($this->app->runningInConsole()) {
31 31
             $this->commands([
Please login to merge, or discard this patch.
src/Commands/RebuildDocumentation.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -42,15 +42,15 @@
 block discarded – undo
42 42
 
43 43
         $documentarian = new Documentarian();
44 44
 
45
-        if (! is_dir($outputPath)) {
46
-            $this->error('There is no existing documentation available at '.$outputPath.'.');
45
+        if (!is_dir($outputPath)) {
46
+            $this->error('There is no existing documentation available at ' . $outputPath . '.');
47 47
 
48 48
             return false;
49 49
         }
50
-        $this->info('Rebuilding API HTML code from '.$outputPath.'/source/index.md');
50
+        $this->info('Rebuilding API HTML code from ' . $outputPath . '/source/index.md');
51 51
 
52 52
         $documentarian->generate($outputPath);
53 53
 
54
-        $this->info('Wrote HTML documentation to: '.$outputPath.'/index.html');
54
+        $this->info('Wrote HTML documentation to: ' . $outputPath . '/index.html');
55 55
     }
56 56
 }
Please login to merge, or discard this patch.
src/Commands/GenerateDocumentation.php 1 patch
Spacing   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -73,7 +73,7 @@  discard block
 block discarded – undo
73 73
         $generator = new Generator($this->docConfig);
74 74
         $parsedRoutes = $this->processRoutes($generator, $routes);
75 75
         $parsedRoutes = collect($parsedRoutes)->groupBy('group')
76
-            ->sortBy(static function ($group) {
76
+            ->sortBy(static function($group) {
77 77
                 /* @var $group Collection */
78 78
                 return $group->first()['group'];
79 79
             }, SORT_NATURAL);
@@ -89,19 +89,19 @@  discard block
 block discarded – undo
89 89
     private function writeMarkdown($parsedRoutes)
90 90
     {
91 91
         $outputPath = $this->docConfig->get('output');
92
-        $targetFile = $outputPath.DIRECTORY_SEPARATOR.'source'.DIRECTORY_SEPARATOR.'index.md';
93
-        $compareFile = $outputPath.DIRECTORY_SEPARATOR.'source'.DIRECTORY_SEPARATOR.'.compare.md';
94
-        $prependFile = $outputPath.DIRECTORY_SEPARATOR.'source'.DIRECTORY_SEPARATOR.'prepend.md';
95
-        $appendFile = $outputPath.DIRECTORY_SEPARATOR.'source'.DIRECTORY_SEPARATOR.'append.md';
92
+        $targetFile = $outputPath . DIRECTORY_SEPARATOR . 'source' . DIRECTORY_SEPARATOR . 'index.md';
93
+        $compareFile = $outputPath . DIRECTORY_SEPARATOR . 'source' . DIRECTORY_SEPARATOR . '.compare.md';
94
+        $prependFile = $outputPath . DIRECTORY_SEPARATOR . 'source' . DIRECTORY_SEPARATOR . 'prepend.md';
95
+        $appendFile = $outputPath . DIRECTORY_SEPARATOR . 'source' . DIRECTORY_SEPARATOR . 'append.md';
96 96
 
97 97
         $infoText = view('apidoc::partials.info')
98 98
             ->with('outputPath', ltrim($outputPath, 'public/'))
99 99
             ->with('showPostmanCollectionButton', $this->shouldGeneratePostmanCollection());
100 100
 
101 101
         $settings = ['languages' => $this->docConfig->get('example_languages')];
102
-        $parsedRouteOutput = $parsedRoutes->map(function ($routeGroup) use ($settings) {
103
-            return $routeGroup->map(function ($route) use ($settings) {
104
-                if (count($route['cleanBodyParameters']) && ! isset($route['headers']['Content-Type'])) {
102
+        $parsedRouteOutput = $parsedRoutes->map(function($routeGroup) use ($settings) {
103
+            return $routeGroup->map(function($route) use ($settings) {
104
+                if (count($route['cleanBodyParameters']) && !isset($route['headers']['Content-Type'])) {
105 105
                     $route['headers']['Content-Type'] = 'application/json';
106 106
                 }
107 107
                 $route['output'] = (string) view('apidoc::partials.route')
@@ -128,16 +128,16 @@  discard block
 block discarded – undo
128 128
                 $frontmatter = trim($generatedFrontmatter[1], "\n");
129 129
             }
130 130
 
131
-            $parsedRouteOutput->transform(function ($routeGroup) use ($generatedDocumentation, $compareDocumentation) {
132
-                return $routeGroup->transform(function ($route) use ($generatedDocumentation, $compareDocumentation) {
133
-                    if (preg_match('/<!-- START_'.$route['id'].' -->(.*)<!-- END_'.$route['id'].' -->/is', $generatedDocumentation, $existingRouteDoc)) {
134
-                        $routeDocumentationChanged = (preg_match('/<!-- START_'.$route['id'].' -->(.*)<!-- END_'.$route['id'].' -->/is', $compareDocumentation, $lastDocWeGeneratedForThisRoute) && $lastDocWeGeneratedForThisRoute[1] !== $existingRouteDoc[1]);
131
+            $parsedRouteOutput->transform(function($routeGroup) use ($generatedDocumentation, $compareDocumentation) {
132
+                return $routeGroup->transform(function($route) use ($generatedDocumentation, $compareDocumentation) {
133
+                    if (preg_match('/<!-- START_' . $route['id'] . ' -->(.*)<!-- END_' . $route['id'] . ' -->/is', $generatedDocumentation, $existingRouteDoc)) {
134
+                        $routeDocumentationChanged = (preg_match('/<!-- START_' . $route['id'] . ' -->(.*)<!-- END_' . $route['id'] . ' -->/is', $compareDocumentation, $lastDocWeGeneratedForThisRoute) && $lastDocWeGeneratedForThisRoute[1] !== $existingRouteDoc[1]);
135 135
                         if ($routeDocumentationChanged === false || $this->option('force')) {
136 136
                             if ($routeDocumentationChanged) {
137
-                                $this->warn('Discarded manual changes for route ['.implode(',', $route['methods']).'] '.$route['uri']);
137
+                                $this->warn('Discarded manual changes for route [' . implode(',', $route['methods']) . '] ' . $route['uri']);
138 138
                             }
139 139
                         } else {
140
-                            $this->warn('Skipping modified route ['.implode(',', $route['methods']).'] '.$route['uri']);
140
+                            $this->warn('Skipping modified route [' . implode(',', $route['methods']) . '] ' . $route['uri']);
141 141
                             $route['modified_output'] = $existingRouteDoc[0];
142 142
                         }
143 143
                     }
@@ -148,9 +148,9 @@  discard block
 block discarded – undo
148 148
         }
149 149
 
150 150
         $prependFileContents = file_exists($prependFile)
151
-            ? file_get_contents($prependFile)."\n" : '';
151
+            ? file_get_contents($prependFile) . "\n" : '';
152 152
         $appendFileContents = file_exists($appendFile)
153
-            ? "\n".file_get_contents($appendFile) : '';
153
+            ? "\n" . file_get_contents($appendFile) : '';
154 154
 
155 155
         $documentarian = new Documentarian();
156 156
 
@@ -164,7 +164,7 @@  discard block
 block discarded – undo
164 164
             ->with('showPostmanCollectionButton', $this->shouldGeneratePostmanCollection())
165 165
             ->with('parsedRoutes', $parsedRouteOutput);
166 166
 
167
-        if (! is_dir($outputPath)) {
167
+        if (!is_dir($outputPath)) {
168 168
             $documentarian->create($outputPath);
169 169
         }
170 170
 
@@ -184,24 +184,24 @@  discard block
 block discarded – undo
184 184
 
185 185
         file_put_contents($compareFile, $compareMarkdown);
186 186
 
187
-        $this->info('Wrote index.md to: '.$outputPath);
187
+        $this->info('Wrote index.md to: ' . $outputPath);
188 188
 
189 189
         $this->info('Generating API HTML code');
190 190
 
191 191
         $documentarian->generate($outputPath);
192 192
 
193
-        $this->info('Wrote HTML documentation to: '.$outputPath.'/index.html');
193
+        $this->info('Wrote HTML documentation to: ' . $outputPath . '/index.html');
194 194
 
195 195
         if ($this->shouldGeneratePostmanCollection()) {
196 196
             $this->info('Generating Postman collection');
197 197
 
198
-            file_put_contents($outputPath.DIRECTORY_SEPARATOR.'collection.json', $this->generatePostmanCollection($parsedRoutes));
198
+            file_put_contents($outputPath . DIRECTORY_SEPARATOR . 'collection.json', $this->generatePostmanCollection($parsedRoutes));
199 199
         }
200 200
 
201 201
         if ($logo = $this->docConfig->get('logo')) {
202 202
             copy(
203 203
                 $logo,
204
-                $outputPath.DIRECTORY_SEPARATOR.'images'.DIRECTORY_SEPARATOR.'logo.png'
204
+                $outputPath . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'logo.png'
205 205
             );
206 206
         }
207 207
     }
@@ -220,9 +220,9 @@  discard block
 block discarded – undo
220 220
             /** @var Route $route */
221 221
             if ($this->isValidRoute($route) && $this->isRouteVisibleForDocumentation($route->getAction())) {
222 222
                 $parsedRoutes[] = $generator->processRoute($route, $routeItem['apply']);
223
-                $this->info('Processed route: ['.implode(',', $generator->getMethods($route)).'] '.$generator->getUri($route));
223
+                $this->info('Processed route: [' . implode(',', $generator->getMethods($route)) . '] ' . $generator->getUri($route));
224 224
             } else {
225
-                $this->warn('Skipping route: ['.implode(',', $generator->getMethods($route)).'] '.$generator->getUri($route));
225
+                $this->warn('Skipping route: [' . implode(',', $generator->getMethods($route)) . '] ' . $generator->getUri($route));
226 226
             }
227 227
         }
228 228
 
@@ -241,7 +241,7 @@  discard block
 block discarded – undo
241 241
             $action = implode('@', $action);
242 242
         }
243 243
 
244
-        return ! is_callable($action) && ! is_null($action);
244
+        return !is_callable($action) && !is_null($action);
245 245
     }
246 246
 
247 247
     /**
@@ -256,7 +256,7 @@  discard block
 block discarded – undo
256 256
         list($class, $method) = Utils::getRouteActionUses($action);
257 257
         $reflection = new ReflectionClass($class);
258 258
 
259
-        if (! $reflection->hasMethod($method)) {
259
+        if (!$reflection->hasMethod($method)) {
260 260
             return false;
261 261
         }
262 262
 
@@ -266,7 +266,7 @@  discard block
 block discarded – undo
266 266
             $phpdoc = new DocBlock($comment);
267 267
 
268 268
             return collect($phpdoc->getTags())
269
-                ->filter(function ($tag) use ($action) {
269
+                ->filter(function($tag) use ($action) {
270 270
                     return $tag->getName() === 'hideFromAPIDocumentation';
271 271
                 })
272 272
                 ->isEmpty();
Please login to merge, or discard this patch.
src/Tools/Generator.php 1 patch
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -68,7 +68,7 @@  discard block
 block discarded – undo
68 68
         ]);
69 69
 
70 70
         $parsedRoute = [
71
-            'id' => md5($this->getUri($route).':'.implode($this->getMethods($route))),
71
+            'id' => md5($this->getUri($route) . ':' . implode($this->getMethods($route))),
72 72
             'group' => $routeGroup,
73 73
             'title' => $docBlock['short'],
74 74
             'description' => $docBlock['long'],
@@ -81,7 +81,7 @@  discard block
 block discarded – undo
81 81
             'cleanQueryParameters' => $this->cleanParams($queryParameters),
82 82
             'authenticated' => $this->getAuthStatusFromDocBlock($docBlock['tags']),
83 83
             'response' => $content,
84
-            'showresponse' => ! empty($content),
84
+            'showresponse' => !empty($content),
85 85
         ];
86 86
         $parsedRoute['headers'] = $rulesToApply['headers'] ?? [];
87 87
 
@@ -127,10 +127,10 @@  discard block
 block discarded – undo
127 127
     protected function getBodyParametersFromDocBlock(array $tags)
128 128
     {
129 129
         $parameters = collect($tags)
130
-            ->filter(function ($tag) {
130
+            ->filter(function($tag) {
131 131
                 return $tag instanceof Tag && $tag->getName() === 'bodyParam';
132 132
             })
133
-            ->mapWithKeys(function ($tag) {
133
+            ->mapWithKeys(function($tag) {
134 134
                 preg_match('/(.+?)\s+(.+?)\s+(required\s+)?(.*)/', $tag->getContent(), $content);
135 135
                 if (empty($content)) {
136 136
                     // this means only name and type were supplied
@@ -202,10 +202,10 @@  discard block
 block discarded – undo
202 202
     protected function getQueryParametersFromDocBlock(array $tags)
203 203
     {
204 204
         $parameters = collect($tags)
205
-            ->filter(function ($tag) {
205
+            ->filter(function($tag) {
206 206
                 return $tag instanceof Tag && $tag->getName() === 'queryParam';
207 207
             })
208
-            ->mapWithKeys(function ($tag) {
208
+            ->mapWithKeys(function($tag) {
209 209
                 preg_match('/(.+?)\s+(required\s+)?(.*)/', $tag->getContent(), $content);
210 210
                 if (empty($content)) {
211 211
                     // this means only name was supplied
@@ -243,7 +243,7 @@  discard block
 block discarded – undo
243 243
     protected function getAuthStatusFromDocBlock(array $tags)
244 244
     {
245 245
         $authTag = collect($tags)
246
-            ->first(function ($tag) {
246
+            ->first(function($tag) {
247 247
                 return $tag instanceof Tag && strtolower($tag->getName()) === 'authenticated';
248 248
             });
249 249
 
@@ -317,25 +317,25 @@  discard block
 block discarded – undo
317 317
             $faker->seed($this->config->get('faker_seed'));
318 318
         }
319 319
         $fakeFactories = [
320
-            'integer' => function () use ($faker) {
320
+            'integer' => function() use ($faker) {
321 321
                 return $faker->numberBetween(1, 20);
322 322
             },
323
-            'number' => function () use ($faker) {
323
+            'number' => function() use ($faker) {
324 324
                 return $faker->randomFloat();
325 325
             },
326
-            'float' => function () use ($faker) {
326
+            'float' => function() use ($faker) {
327 327
                 return $faker->randomFloat();
328 328
             },
329
-            'boolean' => function () use ($faker) {
329
+            'boolean' => function() use ($faker) {
330 330
                 return $faker->boolean();
331 331
             },
332
-            'string' => function () use ($faker) {
332
+            'string' => function() use ($faker) {
333 333
                 return $faker->word;
334 334
             },
335
-            'array' => function () {
335
+            'array' => function() {
336 336
                 return [];
337 337
             },
338
-            'object' => function () {
338
+            'object' => function() {
339 339
                 return new \stdClass;
340 340
             },
341 341
         ];
Please login to merge, or discard this patch.