Completed
Pull Request — master (#572)
by Sang
07:45
created
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/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/Tools/DocumentationConfig.php 1 patch
Doc Comments   +4 added lines patch added patch discarded remove patch
@@ -11,6 +11,10 @@
 block discarded – undo
11 11
         $this->data = $config;
12 12
     }
13 13
 
14
+    /**
15
+     * @param string $key
16
+     * @param boolean $default
17
+     */
14 18
     public function get($key, $default = null)
15 19
     {
16 20
         return data_get($this->data, $key, $default);
Please login to merge, or discard this patch.
src/Tools/Utils.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -68,7 +68,7 @@
 block discarded – undo
68 68
 
69 69
     public static function deleteDirectoryAndContents($dir)
70 70
     {
71
-        $adapter = new Local(realpath(__DIR__.'/../../'));
71
+        $adapter = new Local(realpath(__DIR__ . '/../../'));
72 72
         $fs = new Filesystem($adapter);
73 73
         $fs->deleteDir($dir);
74 74
     }
Please login to merge, or discard this patch.
src/Postman/CollectionWriter.php 1 patch
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -41,32 +41,32 @@  discard block
 block discarded – undo
41 41
         $collection = [
42 42
             'variables' => [],
43 43
             'info' => [
44
-                'name' => config('apidoc.postman.name') ?: config('app.name').' API',
44
+                'name' => config('apidoc.postman.name') ?: config('app.name') . ' API',
45 45
                 '_postman_id' => Uuid::uuid4()->toString(),
46 46
                 'description' => config('apidoc.postman.description') ?: '',
47 47
                 'schema' => 'https://schema.getpostman.com/json/collection/v2.0.0/collection.json',
48 48
             ],
49
-            'item' => $this->routeGroups->map(function ($routes, $groupName) {
49
+            'item' => $this->routeGroups->map(function($routes, $groupName) {
50 50
                 return [
51 51
                     'name' => $groupName,
52 52
                     'description' => '',
53
-                    'item' => $routes->map(function ($route) {
53
+                    'item' => $routes->map(function($route) {
54 54
                         $mode = $route['methods'][0] === 'PUT' ? 'urlencoded' : 'formdata';
55 55
 
56 56
                         return [
57 57
                             'name' => $route['title'] != '' ? $route['title'] : url($route['uri']),
58 58
                             'request' => [
59
-                                'url' => url($route['uri']).(collect($route['queryParameters'])->isEmpty()
59
+                                'url' => url($route['uri']) . (collect($route['queryParameters'])->isEmpty()
60 60
                                     ? ''
61
-                                    : ('?'.implode('&', collect($route['queryParameters'])->map(function ($parameter, $key) {
62
-                                        return urlencode($key).'='.urlencode($parameter['value'] ?? '');
61
+                                    : ('?' . implode('&', collect($route['queryParameters'])->map(function($parameter, $key) {
62
+                                        return urlencode($key) . '=' . urlencode($parameter['value'] ?? '');
63 63
                                     })->all()))),
64 64
                                 'method' => $route['methods'][0],
65 65
                                 'header' => collect($route['headers'])
66 66
                                     ->union([
67 67
                                         'Accept' => 'application/json',
68 68
                                     ])
69
-                                    ->map(function ($value, $header) {
69
+                                    ->map(function($value, $header) {
70 70
                                         return [
71 71
                                             'key' => $header,
72 72
                                             'value' => $value,
@@ -75,7 +75,7 @@  discard block
 block discarded – undo
75 75
                                     ->values()->all(),
76 76
                                 'body' => [
77 77
                                     'mode' => $mode,
78
-                                    $mode => collect($route['bodyParameters'])->map(function ($parameter, $key) {
78
+                                    $mode => collect($route['bodyParameters'])->map(function($parameter, $key) {
79 79
                                         return [
80 80
                                             'key' => $key,
81 81
                                             'value' => $parameter['value'] ?? '',
Please login to merge, or discard this patch.
src/Tools/Generator.php 2 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -28,7 +28,7 @@  discard block
 block discarded – undo
28 28
     /**
29 29
      * @param Route $route
30 30
      *
31
-     * @return mixed
31
+     * @return string
32 32
      */
33 33
     public function getUri(Route $route)
34 34
     {
@@ -163,7 +163,7 @@  discard block
 block discarded – undo
163 163
      * @param ReflectionMethod $method
164 164
      * @param array $tags
165 165
      *
166
-     * @return array
166
+     * @return Route
167 167
      */
168 168
     protected function getQueryParameters(ReflectionMethod $method, array $tags)
169 169
     {
Please login to merge, or discard this patch.
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
         ]);
70 70
 
71 71
         $parsedRoute = [
72
-            'id' => md5($this->getUri($route).':'.implode($this->getMethods($route))),
72
+            'id' => md5($this->getUri($route) . ':' . implode($this->getMethods($route))),
73 73
             'groupName' => $routeGroupName,
74 74
             'groupDescription' => $routeGroupDescription,
75 75
             'title' => $routeTitle ?: $docBlock['short'],
@@ -83,7 +83,7 @@  discard block
 block discarded – undo
83 83
             'cleanQueryParameters' => $this->cleanParams($queryParameters),
84 84
             'authenticated' => $this->getAuthStatusFromDocBlock($docBlock['tags']),
85 85
             'response' => $content,
86
-            'showresponse' => ! empty($content),
86
+            'showresponse' => !empty($content),
87 87
         ];
88 88
         $parsedRoute['headers'] = $rulesToApply['headers'] ?? [];
89 89
 
@@ -129,10 +129,10 @@  discard block
 block discarded – undo
129 129
     protected function getBodyParametersFromDocBlock(array $tags)
130 130
     {
131 131
         $parameters = collect($tags)
132
-            ->filter(function ($tag) {
132
+            ->filter(function($tag) {
133 133
                 return $tag instanceof Tag && $tag->getName() === 'bodyParam';
134 134
             })
135
-            ->mapWithKeys(function ($tag) {
135
+            ->mapWithKeys(function($tag) {
136 136
                 preg_match('/(.+?)\s+(.+?)\s+(required\s+)?(.*)/', $tag->getContent(), $content);
137 137
                 $content = preg_replace('/\s?No-example.?/', '', $content);
138 138
                 if (empty($content)) {
@@ -152,7 +152,7 @@  discard block
 block discarded – undo
152 152
 
153 153
                 $type = $this->normalizeParameterType($type);
154 154
                 list($description, $example) = $this->parseDescription($description, $type);
155
-                $value = is_null($example) && ! $this->shouldExcludeExample($tag) ? $this->generateDummyValue($type) : $example;
155
+                $value = is_null($example) && !$this->shouldExcludeExample($tag) ? $this->generateDummyValue($type) : $example;
156 156
 
157 157
                 return [$name => compact('type', 'description', 'required', 'value')];
158 158
             })->toArray();
@@ -205,10 +205,10 @@  discard block
 block discarded – undo
205 205
     protected function getQueryParametersFromDocBlock(array $tags)
206 206
     {
207 207
         $parameters = collect($tags)
208
-            ->filter(function ($tag) {
208
+            ->filter(function($tag) {
209 209
                 return $tag instanceof Tag && $tag->getName() === 'queryParam';
210 210
             })
211
-            ->mapWithKeys(function ($tag) {
211
+            ->mapWithKeys(function($tag) {
212 212
                 preg_match('/(.+?)\s+(required\s+)?(.*)/', $tag->getContent(), $content);
213 213
                 $content = preg_replace('/\s?No-example.?/', '', $content);
214 214
                 if (empty($content)) {
@@ -227,7 +227,7 @@  discard block
 block discarded – undo
227 227
                 }
228 228
 
229 229
                 list($description, $value) = $this->parseDescription($description, 'string');
230
-                if (is_null($value) && ! $this->shouldExcludeExample($tag)) {
230
+                if (is_null($value) && !$this->shouldExcludeExample($tag)) {
231 231
                     $value = Str::contains($description, ['number', 'count', 'page'])
232 232
                         ? $this->generateDummyValue('integer')
233 233
                         : $this->generateDummyValue('string');
@@ -247,7 +247,7 @@  discard block
 block discarded – undo
247 247
     protected function getAuthStatusFromDocBlock(array $tags)
248 248
     {
249 249
         $authTag = collect($tags)
250
-            ->first(function ($tag) {
250
+            ->first(function($tag) {
251 251
                 return $tag instanceof Tag && strtolower($tag->getName()) === 'authenticated';
252 252
             });
253 253
 
@@ -280,7 +280,7 @@  discard block
 block discarded – undo
280 280
     protected function getRouteGroup(ReflectionClass $controller, array $methodDocBlock)
281 281
     {
282 282
         // @group tag on the method overrides that on the controller
283
-        if (! empty($methodDocBlock['tags'])) {
283
+        if (!empty($methodDocBlock['tags'])) {
284 284
             foreach ($methodDocBlock['tags'] as $tag) {
285 285
                 if ($tag->getName() === 'group') {
286 286
                     $routeGroupParts = explode("\n", trim($tag->getContent()));
@@ -347,25 +347,25 @@  discard block
 block discarded – undo
347 347
             $faker->seed($this->config->get('faker_seed'));
348 348
         }
349 349
         $fakeFactories = [
350
-            'integer' => function () use ($faker) {
350
+            'integer' => function() use ($faker) {
351 351
                 return $faker->numberBetween(1, 20);
352 352
             },
353
-            'number' => function () use ($faker) {
353
+            'number' => function() use ($faker) {
354 354
                 return $faker->randomFloat();
355 355
             },
356
-            'float' => function () use ($faker) {
356
+            'float' => function() use ($faker) {
357 357
                 return $faker->randomFloat();
358 358
             },
359
-            'boolean' => function () use ($faker) {
359
+            'boolean' => function() use ($faker) {
360 360
                 return $faker->boolean();
361 361
             },
362
-            'string' => function () use ($faker) {
362
+            'string' => function() use ($faker) {
363 363
                 return $faker->word;
364 364
             },
365
-            'array' => function () {
365
+            'array' => function() {
366 366
                 return [];
367 367
             },
368
-            'object' => function () {
368
+            'object' => function() {
369 369
                 return new \stdClass;
370 370
             },
371 371
         ];
Please login to merge, or discard this patch.
src/Tools/ResponseStrategies/ResponseCallStrategy.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -27,7 +27,7 @@  discard block
 block discarded – undo
27 27
     public function __invoke(Route $route, array $tags, array $routeProps)
28 28
     {
29 29
         $rulesToApply = $routeProps['rules']['response_calls'] ?? [];
30
-        if (! $this->shouldMakeApiCall($route, $rulesToApply)) {
30
+        if (!$this->shouldMakeApiCall($route, $rulesToApply)) {
31 31
             return null;
32 32
         }
33 33
 
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
         try {
38 38
             $response = [$this->makeApiCall($request)];
39 39
         } catch (\Exception $e) {
40
-            echo 'Exception thrown during response call for ['.implode(',', $route->methods)."] {$route->uri}.\n";
40
+            echo 'Exception thrown during response call for [' . implode(',', $route->methods) . "] {$route->uri}.\n";
41 41
             if (Flags::$shouldBeVerbose) {
42 42
                 Utils::dumpException($e);
43 43
             } else {
@@ -174,14 +174,14 @@  discard block
 block discarded – undo
174 174
         // set URL and query parameters
175 175
         $uri = $request->getRequestUri();
176 176
         $query = $request->getQueryString();
177
-        if (! empty($query)) {
177
+        if (!empty($query)) {
178 178
             $uri .= "?$query";
179 179
         }
180 180
         $response = call_user_func_array([$dispatcher, strtolower($request->method())], [$uri]);
181 181
 
182 182
         // the response from the Dingo dispatcher is the 'raw' response from the controller,
183 183
         // so we have to ensure it's JSON first
184
-        if (! $response instanceof Response) {
184
+        if (!$response instanceof Response) {
185 185
             $response = response()->json($response);
186 186
         }
187 187
 
@@ -330,8 +330,8 @@  discard block
 block discarded – undo
330 330
         $prefix = 'HTTP_';
331 331
         foreach ($headers as $name => $value) {
332 332
             $name = strtr(strtoupper($name), '-', '_');
333
-            if (! starts_with($name, $prefix) && $name !== 'CONTENT_TYPE') {
334
-                $name = $prefix.$name;
333
+            if (!starts_with($name, $prefix) && $name !== 'CONTENT_TYPE') {
334
+                $name = $prefix . $name;
335 335
             }
336 336
             $server[$name] = $value;
337 337
         }
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 null;
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.