Completed
Pull Request — master (#608)
by
unknown
12:02
created
src/Writing/PostmanCollectionWriter.php 1 patch
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -40,32 +40,32 @@  discard block
 block discarded – undo
40 40
         $collection = [
41 41
             'variables' => [],
42 42
             'info' => [
43
-                'name' => config('apidoc.postman.name') ?: config('app.name').' API',
43
+                'name' => config('apidoc.postman.name') ?: config('app.name') . ' API',
44 44
                 '_postman_id' => Uuid::uuid4()->toString(),
45 45
                 'description' => config('apidoc.postman.description') ?: '',
46 46
                 'schema' => 'https://schema.getpostman.com/json/collection/v2.0.0/collection.json',
47 47
             ],
48
-            'item' => $this->routeGroups->map(function ($routes, $groupName) {
48
+            'item' => $this->routeGroups->map(function($routes, $groupName) {
49 49
                 return [
50 50
                     'name' => $groupName,
51 51
                     'description' => '',
52
-                    'item' => $routes->map(function ($route) {
52
+                    'item' => $routes->map(function($route) {
53 53
                         $mode = $route['methods'][0] === 'PUT' ? 'urlencoded' : 'formdata';
54 54
 
55 55
                         return [
56 56
                             'name' => $route['metadata']['title'] != '' ? $route['metadata']['title'] : url($route['uri']),
57 57
                             'request' => [
58
-                                'url' => url($route['uri']).(collect($route['queryParameters'])->isEmpty()
58
+                                'url' => url($route['uri']) . (collect($route['queryParameters'])->isEmpty()
59 59
                                         ? ''
60
-                                        : ('?'.implode('&', collect($route['queryParameters'])->map(function ($parameter, $key) {
61
-                                            return urlencode($key).'='.urlencode($parameter['value'] ?? '');
60
+                                        : ('?' . implode('&', collect($route['queryParameters'])->map(function($parameter, $key) {
61
+                                            return urlencode($key) . '=' . urlencode($parameter['value'] ?? '');
62 62
                                         })->all()))),
63 63
                                 'method' => $route['methods'][0],
64 64
                                 'header' => collect($route['headers'])
65 65
                                     ->union([
66 66
                                         'Accept' => 'application/json',
67 67
                                     ])
68
-                                    ->map(function ($value, $header) {
68
+                                    ->map(function($value, $header) {
69 69
                                         return [
70 70
                                             'key' => $header,
71 71
                                             'value' => $value,
@@ -74,7 +74,7 @@  discard block
 block discarded – undo
74 74
                                     ->values()->all(),
75 75
                                 'body' => [
76 76
                                     'mode' => $mode,
77
-                                    $mode => collect($route['bodyParameters'])->map(function ($parameter, $key) {
77
+                                    $mode => collect($route['bodyParameters'])->map(function($parameter, $key) {
78 78
                                         return [
79 79
                                             'key' => $key,
80 80
                                             'value' => $parameter['value'] ?? '',
Please login to merge, or discard this patch.
src/Writing/Writer.php 1 patch
Spacing   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -83,8 +83,8 @@  discard block
 block discarded – undo
83 83
      */
84 84
     public function writeMarkdownAndSourceFiles(Collection $parsedRoutes, string $sourceOutputPath)
85 85
     {
86
-        $targetFile = $sourceOutputPath.'/source/index.md';
87
-        $compareFile = $sourceOutputPath.'/source/.compare.md';
86
+        $targetFile = $sourceOutputPath . '/source/index.md';
87
+        $compareFile = $sourceOutputPath . '/source/.compare.md';
88 88
 
89 89
         $infoText = view('apidoc::partials.info')
90 90
             ->with('outputPath', 'docs')
@@ -106,16 +106,16 @@  discard block
 block discarded – undo
106 106
             $generatedDocumentation = file_get_contents($targetFile);
107 107
             $compareDocumentation = file_get_contents($compareFile);
108 108
 
109
-            $parsedRouteOutput->transform(function (Collection $routeGroup) use ($generatedDocumentation, $compareDocumentation) {
110
-                return $routeGroup->transform(function (array $route) use ($generatedDocumentation, $compareDocumentation) {
111
-                    if (preg_match('/<!-- START_'.$route['id'].' -->(.*)<!-- END_'.$route['id'].' -->/is', $generatedDocumentation, $existingRouteDoc)) {
112
-                        $routeDocumentationChanged = (preg_match('/<!-- START_'.$route['id'].' -->(.*)<!-- END_'.$route['id'].' -->/is', $compareDocumentation, $lastDocWeGeneratedForThisRoute) && $lastDocWeGeneratedForThisRoute[1] !== $existingRouteDoc[1]);
109
+            $parsedRouteOutput->transform(function(Collection $routeGroup) use ($generatedDocumentation, $compareDocumentation) {
110
+                return $routeGroup->transform(function(array $route) use ($generatedDocumentation, $compareDocumentation) {
111
+                    if (preg_match('/<!-- START_' . $route['id'] . ' -->(.*)<!-- END_' . $route['id'] . ' -->/is', $generatedDocumentation, $existingRouteDoc)) {
112
+                        $routeDocumentationChanged = (preg_match('/<!-- START_' . $route['id'] . ' -->(.*)<!-- END_' . $route['id'] . ' -->/is', $compareDocumentation, $lastDocWeGeneratedForThisRoute) && $lastDocWeGeneratedForThisRoute[1] !== $existingRouteDoc[1]);
113 113
                         if ($routeDocumentationChanged === false || $this->forceIt) {
114 114
                             if ($routeDocumentationChanged) {
115
-                                $this->output->warn('Discarded manual changes for route ['.implode(',', $route['methods']).'] '.$route['uri']);
115
+                                $this->output->warn('Discarded manual changes for route [' . implode(',', $route['methods']) . '] ' . $route['uri']);
116 116
                             }
117 117
                         } else {
118
-                            $this->output->warn('Skipping modified route ['.implode(',', $route['methods']).'] '.$route['uri']);
118
+                            $this->output->warn('Skipping modified route [' . implode(',', $route['methods']) . '] ' . $route['uri']);
119 119
                             $route['modified_output'] = $existingRouteDoc[0];
120 120
                         }
121 121
                     }
@@ -138,9 +138,9 @@  discard block
 block discarded – undo
138 138
             ->with('showPostmanCollectionButton', $this->shouldGeneratePostmanCollection)
139 139
             ->with('parsedRoutes', $parsedRouteOutput);
140 140
 
141
-        $this->output->info('Writing index.md and source files to: '.$sourceOutputPath);
141
+        $this->output->info('Writing index.md and source files to: ' . $sourceOutputPath);
142 142
 
143
-        if (! is_dir($sourceOutputPath)) {
143
+        if (!is_dir($sourceOutputPath)) {
144 144
             $documentarian = new Documentarian();
145 145
             $documentarian->create($sourceOutputPath);
146 146
         }
@@ -161,14 +161,14 @@  discard block
 block discarded – undo
161 161
 
162 162
         file_put_contents($compareFile, $compareMarkdown);
163 163
 
164
-        $this->output->info('Wrote index.md and source files to: '.$sourceOutputPath);
164
+        $this->output->info('Wrote index.md and source files to: ' . $sourceOutputPath);
165 165
     }
166 166
 
167 167
     public function generateMarkdownOutputForEachRoute(Collection $parsedRoutes, array $settings): Collection
168 168
     {
169
-        $parsedRouteOutput = $parsedRoutes->map(function (Collection $routeGroup) use ($settings) {
170
-            return $routeGroup->map(function (array $route) use ($settings) {
171
-                if (count($route['cleanBodyParameters']) && ! isset($route['headers']['Content-Type'])) {
169
+        $parsedRouteOutput = $parsedRoutes->map(function(Collection $routeGroup) use ($settings) {
170
+            return $routeGroup->map(function(array $route) use ($settings) {
171
+                if (count($route['cleanBodyParameters']) && !isset($route['headers']['Content-Type'])) {
172 172
                     // Set content type if the user forgot to set it
173 173
                     $route['headers']['Content-Type'] = 'application/json';
174 174
                 }
@@ -224,9 +224,9 @@  discard block
 block discarded – undo
224 224
      */
225 225
     protected function getMarkdownToPrepend(string $sourceOutputPath): string
226 226
     {
227
-        $prependFile = $sourceOutputPath.'/source/prepend.md';
227
+        $prependFile = $sourceOutputPath . '/source/prepend.md';
228 228
         $prependFileContents = file_exists($prependFile)
229
-            ? file_get_contents($prependFile)."\n" : '';
229
+            ? file_get_contents($prependFile) . "\n" : '';
230 230
 
231 231
         return $prependFileContents;
232 232
     }
@@ -238,9 +238,9 @@  discard block
 block discarded – undo
238 238
      */
239 239
     protected function getMarkdownToAppend(string $sourceOutputPath): string
240 240
     {
241
-        $appendFile = $sourceOutputPath.'/source/append.md';
241
+        $appendFile = $sourceOutputPath . '/source/append.md';
242 242
         $appendFileContents = file_exists($appendFile)
243
-            ? "\n".file_get_contents($appendFile) : '';
243
+            ? "\n" . file_get_contents($appendFile) : '';
244 244
 
245 245
         return $appendFileContents;
246 246
     }
@@ -248,7 +248,7 @@  discard block
 block discarded – undo
248 248
     protected function copyAssetsFromSourceFolderToPublicFolder(string $sourceOutputPath, bool $isStatic = true): void
249 249
     {
250 250
         $publicPath = 'public/docs';
251
-        if (! is_dir($publicPath)) {
251
+        if (!is_dir($publicPath)) {
252 252
             mkdir($publicPath, 0777, true);
253 253
             mkdir("{$publicPath}/css");
254 254
             mkdir("{$publicPath}/js");
@@ -271,7 +271,7 @@  discard block
 block discarded – undo
271 271
             rename("{$sourceOutputPath}/index.html", "{$outputPath}/index.html");
272 272
         } else {
273 273
             // Move output to resources/views
274
-            if (! is_dir($outputPath)) {
274
+            if (!is_dir($outputPath)) {
275 275
                 mkdir($outputPath);
276 276
             }
277 277
             rename("{$sourceOutputPath}/index.html", "$outputPath/index.blade.php");
Please login to merge, or discard this patch.
src/Matching/RouteMatcher.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -64,14 +64,14 @@  discard block
 block discarded – undo
64 64
 
65 65
     private function getAllRoutes(bool $usingDingoRouter)
66 66
     {
67
-        if (! $usingDingoRouter) {
67
+        if (!$usingDingoRouter) {
68 68
             return RouteFacade::getRoutes();
69 69
         }
70 70
 
71 71
         $allRouteCollections = app(\Dingo\Api\Routing\Router::class)->getRoutes();
72 72
 
73 73
         return collect($allRouteCollections)
74
-            ->flatMap(function (RouteCollection $collection) {
74
+            ->flatMap(function(RouteCollection $collection) {
75 75
                 return $collection->getRoutes();
76 76
             })->toArray();
77 77
     }
@@ -79,7 +79,7 @@  discard block
 block discarded – undo
79 79
     private function shouldIncludeRoute(Route $route, array $routeRule, array $mustIncludes, bool $usingDingoRouter)
80 80
     {
81 81
         $matchesVersion = $usingDingoRouter
82
-            ? ! empty(array_intersect($route->versions(), $routeRule['match']['versions'] ?? []))
82
+            ? !empty(array_intersect($route->versions(), $routeRule['match']['versions'] ?? []))
83 83
             : true;
84 84
 
85 85
         return Str::is($mustIncludes, $route->getName())
Please login to merge, or discard this patch.
src/Extracting/Generator.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -56,7 +56,7 @@  discard block
 block discarded – undo
56 56
         $method = $controller->getMethod($methodName);
57 57
 
58 58
         $parsedRoute = [
59
-            'id' => md5($this->getUri($route).':'.implode($this->getMethods($route))),
59
+            'id' => md5($this->getUri($route) . ':' . implode($this->getMethods($route))),
60 60
             'methods' => $this->getMethods($route),
61 61
             'uri' => $this->getUri($route),
62 62
         ];
@@ -78,7 +78,7 @@  discard block
 block discarded – undo
78 78
 
79 79
         $responses = $this->fetchResponses($controller, $method, $route, $routeRules, $parsedRoute);
80 80
         $parsedRoute['responses'] = $responses;
81
-        $parsedRoute['showresponse'] = ! empty($responses);
81
+        $parsedRoute['showresponse'] = !empty($responses);
82 82
 
83 83
         $parsedRoute['headers'] = $routeRules['headers'] ?? [];
84 84
 
@@ -117,7 +117,7 @@  discard block
 block discarded – undo
117 117
     {
118 118
         $responses = $this->iterateThroughStrategies('responses', $context, [$route, $controller, $method, $rulesToApply]);
119 119
         if (count($responses)) {
120
-            return array_filter($responses, function ($response) {
120
+            return array_filter($responses, function($response) {
121 121
                 return $response['content'] != null;
122 122
             });
123 123
         }
@@ -157,7 +157,7 @@  discard block
 block discarded – undo
157 157
             $strategyArgs = $arguments;
158 158
             $strategyArgs[] = $context;
159 159
             $results = $strategy(...$strategyArgs);
160
-            if (! is_null($results)) {
160
+            if (!is_null($results)) {
161 161
                 foreach ($results as $index => $item) {
162 162
                     if ($stage == 'responses') {
163 163
                         // Responses are additive
@@ -169,7 +169,7 @@  discard block
 block discarded – undo
169 169
                     // and also allows values to be overwritten
170 170
 
171 171
                     // Don't allow overwriting if an empty value is trying to replace a set one
172
-                    if (! in_array($context[$stage], [null, ''], true) && in_array($item, [null, ''], true)) {
172
+                    if (!in_array($context[$stage], [null, ''], true) && in_array($item, [null, ''], true)) {
173 173
                         continue;
174 174
                     } else {
175 175
                         $context[$stage][$index] = $item;
@@ -194,8 +194,8 @@  discard block
 block discarded – undo
194 194
         $values = [];
195 195
 
196 196
         // Remove params which have no examples.
197
-        $params = array_filter($params, function ($details) {
198
-            return ! is_null($details['value']);
197
+        $params = array_filter($params, function($details) {
198
+            return !is_null($details['value']);
199 199
         });
200 200
 
201 201
         foreach ($params as $paramName => $details) {
Please login to merge, or discard this patch.
src/Extracting/Strategies/Responses/UseTransformerTags.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -63,7 +63,7 @@  discard block
 block discarded – undo
63 63
 
64 64
             $fractal = new Manager();
65 65
 
66
-            if (! is_null(config('apidoc.fractal.serializer'))) {
66
+            if (!is_null(config('apidoc.fractal.serializer'))) {
67 67
                 $fractal->setSerializer(app(config('apidoc.fractal.serializer')));
68 68
             }
69 69
 
@@ -82,7 +82,7 @@  discard block
 block discarded – undo
82 82
                 ],
83 83
             ];
84 84
         } catch (\Exception $e) {
85
-            echo 'Exception thrown when fetching transformer response for ['.implode(',', $route->methods)."] {$route->uri}.\n";
85
+            echo 'Exception thrown when fetching transformer response for [' . implode(',', $route->methods) . "] {$route->uri}.\n";
86 86
             if (Flags::$shouldBeVerbose) {
87 87
                 Utils::dumpException($e);
88 88
             } else {
@@ -116,7 +116,7 @@  discard block
 block discarded – undo
116 116
      */
117 117
     private function getClassToBeTransformed(array $tags, ReflectionMethod $transformerMethod): string
118 118
     {
119
-        $modelTag = Arr::first(array_filter($tags, function ($tag) {
119
+        $modelTag = Arr::first(array_filter($tags, function($tag) {
120 120
             return ($tag instanceof Tag) && strtolower($tag->getName()) == 'transformermodel';
121 121
         }));
122 122
 
@@ -125,7 +125,7 @@  discard block
 block discarded – undo
125 125
             $type = $modelTag->getContent();
126 126
         } else {
127 127
             $parameter = Arr::first($transformerMethod->getParameters());
128
-            if ($parameter->hasType() && ! $parameter->getType()->isBuiltin() && class_exists((string) $parameter->getType())) {
128
+            if ($parameter->hasType() && !$parameter->getType()->isBuiltin() && class_exists((string) $parameter->getType())) {
129 129
                 // Ladies and gentlemen, we have a type!
130 130
                 $type = (string) $parameter->getType();
131 131
             }
@@ -186,7 +186,7 @@  discard block
 block discarded – undo
186 186
     private function getTransformerTag(array $tags)
187 187
     {
188 188
         $transformerTags = array_values(
189
-            array_filter($tags, function ($tag) {
189
+            array_filter($tags, function($tag) {
190 190
                 return ($tag instanceof Tag) && in_array(strtolower($tag->getName()), ['transformer', 'transformercollection']);
191 191
             })
192 192
         );
Please login to merge, or discard this patch.
src/Extracting/Strategies/Responses/UseResponseFileTag.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -44,7 +44,7 @@  discard block
 block discarded – undo
44 44
     {
45 45
         // Avoid "holes" in the keys of the filtered array, by using array_values on the filtered array
46 46
         $responseFileTags = array_values(
47
-            array_filter($tags, function ($tag) {
47
+            array_filter($tags, function($tag) {
48 48
                 return $tag instanceof Tag && strtolower($tag->getName()) === 'responsefile';
49 49
             })
50 50
         );
@@ -53,11 +53,11 @@  discard block
 block discarded – undo
53 53
             return null;
54 54
         }
55 55
 
56
-        $responses = array_map(function (Tag $responseFileTag) {
56
+        $responses = array_map(function(Tag $responseFileTag) {
57 57
             preg_match('/^(\d{3})?\s?([\S]*[\s]*?)(\{.*\})?$/', $responseFileTag->getContent(), $result);
58 58
             $status = $result[1] ?: 200;
59 59
             $content = $result[2] ? file_get_contents(storage_path(trim($result[2])), true) : '{}';
60
-            $json = ! empty($result[3]) ? str_replace("'", '"', $result[3]) : '{}';
60
+            $json = !empty($result[3]) ? str_replace("'", '"', $result[3]) : '{}';
61 61
             $merged = array_merge(json_decode($content, true), json_decode($json, true));
62 62
 
63 63
             return ['content' => json_encode($merged), 'status' => (int) $status];
Please login to merge, or discard this patch.
src/Extracting/Strategies/Responses/ResponseCalls.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -31,7 +31,7 @@  discard block
 block discarded – undo
31 31
     public function __invoke(Route $route, \ReflectionClass $controller, \ReflectionMethod $method, array $routeRules, array $context = [])
32 32
     {
33 33
         $rulesToApply = $routeRules['response_calls'] ?? [];
34
-        if (! $this->shouldMakeApiCall($route, $rulesToApply, $context)) {
34
+        if (!$this->shouldMakeApiCall($route, $rulesToApply, $context)) {
35 35
             return null;
36 36
         }
37 37
 
@@ -52,7 +52,7 @@  discard block
 block discarded – undo
52 52
                 ],
53 53
             ];
54 54
         } catch (\Exception $e) {
55
-            echo 'Exception thrown during response call for ['.implode(',', $route->methods)."] {$route->uri}.\n";
55
+            echo 'Exception thrown during response call for [' . implode(',', $route->methods) . "] {$route->uri}.\n";
56 56
             if (Flags::$shouldBeVerbose) {
57 57
                 Utils::dumpException($e);
58 58
             } else {
@@ -186,14 +186,14 @@  discard block
 block discarded – undo
186 186
         // set URL and query parameters
187 187
         $uri = $request->getRequestUri();
188 188
         $query = $request->getQueryString();
189
-        if (! empty($query)) {
189
+        if (!empty($query)) {
190 190
             $uri .= "?$query";
191 191
         }
192 192
         $response = call_user_func_array([$dispatcher, strtolower($request->method())], [$uri]);
193 193
 
194 194
         // the response from the Dingo dispatcher is the 'raw' response from the controller,
195 195
         // so we have to ensure it's JSON first
196
-        if (! $response instanceof Response) {
196
+        if (!$response instanceof Response) {
197 197
             $response = response()->json($response);
198 198
         }
199 199
 
@@ -321,7 +321,7 @@  discard block
 block discarded – undo
321 321
         }
322 322
 
323 323
         // Don't attempt a response call if there are already successful responses
324
-        $successResponses = collect($context['responses'])->filter(function ($response) {
324
+        $successResponses = collect($context['responses'])->filter(function($response) {
325 325
             return ((string) $response['status'])[0] == '2';
326 326
         })->count();
327 327
         if ($successResponses) {
@@ -357,8 +357,8 @@  discard block
 block discarded – undo
357 357
         $prefix = 'HTTP_';
358 358
         foreach ($headers as $name => $value) {
359 359
             $name = strtr(strtoupper($name), '-', '_');
360
-            if (! Str::startsWith($name, $prefix) && $name !== 'CONTENT_TYPE') {
361
-                $name = $prefix.$name;
360
+            if (!Str::startsWith($name, $prefix) && $name !== 'CONTENT_TYPE') {
361
+                $name = $prefix . $name;
362 362
             }
363 363
             $server[$name] = $value;
364 364
         }
Please login to merge, or discard this patch.
src/Extracting/Strategies/Responses/UseApiResourceTags.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -92,7 +92,7 @@  discard block
 block discarded – undo
92 92
                 ],
93 93
             ];
94 94
         } catch (\Exception $e) {
95
-            echo 'Exception thrown when fetching Eloquent API resource response for ['.implode(',', $route->methods)."] {$route->uri}.\n";
95
+            echo 'Exception thrown when fetching Eloquent API resource response for [' . implode(',', $route->methods) . "] {$route->uri}.\n";
96 96
             if (Flags::$shouldBeVerbose) {
97 97
                 Utils::dumpException($e);
98 98
             } else {
@@ -125,7 +125,7 @@  discard block
 block discarded – undo
125 125
      */
126 126
     private function getClassToBeTransformed(array $tags): string
127 127
     {
128
-        $modelTag = Arr::first(array_filter($tags, function ($tag) {
128
+        $modelTag = Arr::first(array_filter($tags, function($tag) {
129 129
             return ($tag instanceof Tag) && strtolower($tag->getName()) == 'apiresourcemodel';
130 130
         }));
131 131
 
@@ -186,7 +186,7 @@  discard block
 block discarded – undo
186 186
     private function getApiResourceTag(array $tags)
187 187
     {
188 188
         $apiResourceTags = array_values(
189
-            array_filter($tags, function ($tag) {
189
+            array_filter($tags, function($tag) {
190 190
                 return ($tag instanceof Tag) && in_array(strtolower($tag->getName()), ['apiresource', 'apiresourcecollection']);
191 191
             })
192 192
         );
Please login to merge, or discard this patch.
src/Extracting/Strategies/UrlParameters/GetFromUrlParamTag.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -55,10 +55,10 @@  discard block
 block discarded – undo
55 55
     private function getUrlParametersFromDocBlock($tags)
56 56
     {
57 57
         $parameters = collect($tags)
58
-            ->filter(function ($tag) {
58
+            ->filter(function($tag) {
59 59
                 return $tag instanceof Tag && $tag->getName() === 'urlParam';
60 60
             })
61
-            ->mapWithKeys(function (Tag $tag) {
61
+            ->mapWithKeys(function(Tag $tag) {
62 62
                 // Format:
63 63
                 // @urlParam <name> <"required" (optional)> <description>
64 64
                 // Examples:
@@ -82,7 +82,7 @@  discard block
 block discarded – undo
82 82
                 }
83 83
 
84 84
                 list($description, $value) = $this->parseParamDescription($description, 'string');
85
-                if (is_null($value) && ! $this->shouldExcludeExample($tag->getContent())) {
85
+                if (is_null($value) && !$this->shouldExcludeExample($tag->getContent())) {
86 86
                     $value = Str::contains($description, ['number', 'count', 'page'])
87 87
                         ? $this->generateDummyValue('integer')
88 88
                         : $this->generateDummyValue('string');
Please login to merge, or discard this patch.