Completed
Pull Request — master (#638)
by
unknown
12:52
created
src/Extracting/Strategies/Responses/UseResponseTag.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -43,7 +43,7 @@  discard block
 block discarded – undo
43 43
     protected function getDocBlockResponses(array $tags)
44 44
     {
45 45
         $responseTags = array_values(
46
-            array_filter($tags, function ($tag) {
46
+            array_filter($tags, function($tag) {
47 47
                 return $tag instanceof Tag && strtolower($tag->getName()) === 'response';
48 48
             })
49 49
         );
@@ -52,7 +52,7 @@  discard block
 block discarded – undo
52 52
             return null;
53 53
         }
54 54
 
55
-        $responses = array_map(function (Tag $responseTag) {
55
+        $responses = array_map(function(Tag $responseTag) {
56 56
             preg_match('/^(\d{3})?\s?([\s\S]*)$/', $responseTag->getContent(), $result);
57 57
 
58 58
             $status = $result[1] ?: 200;
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/Metadata/GetFromDocBlocks.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
     protected function getAuthStatusFromDocBlock(array $tags)
38 38
     {
39 39
         $authTag = collect($tags)
40
-            ->first(function ($tag) {
40
+            ->first(function($tag) {
41 41
                 return $tag instanceof Tag && strtolower($tag->getName()) === 'authenticated';
42 42
             });
43 43
 
@@ -53,7 +53,7 @@  discard block
 block discarded – undo
53 53
     protected function getRouteGroupDescriptionAndTitle(DocBlock $methodDocBlock, DocBlock $controllerDocBlock)
54 54
     {
55 55
         // @group tag on the method overrides that on the controller
56
-        if (! empty($methodDocBlock->getTags())) {
56
+        if (!empty($methodDocBlock->getTags())) {
57 57
             foreach ($methodDocBlock->getTags() as $tag) {
58 58
                 if ($tag->getName() === 'group') {
59 59
                     $routeGroupParts = explode("\n", trim($tag->getContent()));
Please login to merge, or discard this patch.
src/ApiDoc.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -9,7 +9,7 @@
 block discarded – undo
9 9
 {
10 10
     public static function routes($path = '/doc')
11 11
     {
12
-        return Route::get("$path{format?}", function (?string $format = null) {
12
+        return Route::get("$path{format?}", function(?string $format = null) {
13 13
             if ($format == '.json') {
14 14
                 return response(
15 15
                     Storage::disk('local')->get('apidoc/collection.json'),
Please login to merge, or discard this patch.
src/Tools/Utils.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -53,7 +53,7 @@  discard block
 block discarded – undo
53 53
     public static function replaceUrlParameterPlaceholdersWithValues(string $uri, array $urlParameters)
54 54
     {
55 55
         $matches = preg_match_all('/{.+?}/i', $uri, $parameterPaths);
56
-        if (! $matches) {
56
+        if (!$matches) {
57 57
             return $uri;
58 58
         }
59 59
 
@@ -88,7 +88,7 @@  discard block
 block discarded – undo
88 88
 
89 89
     public static function deleteDirectoryAndContents($dir)
90 90
     {
91
-        $adapter = new Local(realpath(__DIR__.'/../../'));
91
+        $adapter = new Local(realpath(__DIR__ . '/../../'));
92 92
         $fs = new Filesystem($adapter);
93 93
         $fs->deleteDir($dir);
94 94
     }
@@ -101,7 +101,7 @@  discard block
 block discarded – undo
101 101
         $result = '';
102 102
         $padWith = str_repeat(' ', $indentationLevel);
103 103
         foreach ($split as $index => $line) {
104
-            $result .= ($index == 0 ? '' : "\n$padWith").$line;
104
+            $result .= ($index == 0 ? '' : "\n$padWith") . $line;
105 105
         }
106 106
 
107 107
         return $result;
Please login to merge, or discard this patch.
src/Writing/PostmanCollectionWriter.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -40,32 +40,32 @@
 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 = 'raw';
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,
Please login to merge, or discard this patch.
src/Writing/Writer.php 1 patch
Spacing   +21 added lines, -21 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,19 +161,19 @@  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
                 }
175 175
 
176
-                $hasRequestOptions = ! empty($route['headers']) || ! empty($route['cleanQueryParameters']) || ! empty($route['cleanBodyParameters']);
176
+                $hasRequestOptions = !empty($route['headers']) || !empty($route['cleanQueryParameters']) || !empty($route['cleanBodyParameters']);
177 177
                 $route['output'] = (string) view('apidoc::partials.route')
178 178
                     ->with('hasRequestOptions', $hasRequestOptions)
179 179
                     ->with('route', $route)
@@ -227,9 +227,9 @@  discard block
 block discarded – undo
227 227
      */
228 228
     protected function getMarkdownToPrepend(string $sourceOutputPath): string
229 229
     {
230
-        $prependFile = $sourceOutputPath.'/source/prepend.md';
230
+        $prependFile = $sourceOutputPath . '/source/prepend.md';
231 231
         $prependFileContents = file_exists($prependFile)
232
-            ? file_get_contents($prependFile)."\n" : '';
232
+            ? file_get_contents($prependFile) . "\n" : '';
233 233
 
234 234
         return $prependFileContents;
235 235
     }
@@ -241,9 +241,9 @@  discard block
 block discarded – undo
241 241
      */
242 242
     protected function getMarkdownToAppend(string $sourceOutputPath): string
243 243
     {
244
-        $appendFile = $sourceOutputPath.'/source/append.md';
244
+        $appendFile = $sourceOutputPath . '/source/append.md';
245 245
         $appendFileContents = file_exists($appendFile)
246
-            ? "\n".file_get_contents($appendFile) : '';
246
+            ? "\n" . file_get_contents($appendFile) : '';
247 247
 
248 248
         return $appendFileContents;
249 249
     }
@@ -251,7 +251,7 @@  discard block
 block discarded – undo
251 251
     protected function copyAssetsFromSourceFolderToPublicFolder(string $sourceOutputPath, bool $isStatic = true): void
252 252
     {
253 253
         $publicPath = 'public/docs';
254
-        if (! is_dir($publicPath)) {
254
+        if (!is_dir($publicPath)) {
255 255
             mkdir($publicPath, 0777, true);
256 256
             mkdir("{$publicPath}/css");
257 257
             mkdir("{$publicPath}/js");
@@ -274,7 +274,7 @@  discard block
 block discarded – undo
274 274
             rename("{$sourceOutputPath}/index.html", "{$outputPath}/index.html");
275 275
         } else {
276 276
             // Move output to resources/views
277
-            if (! is_dir($outputPath)) {
277
+            if (!is_dir($outputPath)) {
278 278
                 mkdir($outputPath);
279 279
             }
280 280
             rename("{$sourceOutputPath}/index.html", "$outputPath/index.blade.php");
Please login to merge, or discard this patch.
src/Commands/GenerateDocumentation.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -73,7 +73,7 @@  discard block
 block discarded – undo
73 73
 
74 74
         $groupedRoutes = collect($parsedRoutes)
75 75
             ->groupBy('metadata.groupName')
76
-            ->sortBy(static function ($group) {
76
+            ->sortBy(static function($group) {
77 77
                 /* @var $group Collection */
78 78
                 return $group->first()['metadata']['groupName'];
79 79
             }, SORT_NATURAL);
@@ -102,7 +102,7 @@  discard block
 block discarded – undo
102 102
             $routeMethods = implode(',', $generator->getMethods($route));
103 103
             $routePath = $generator->getUri($route);
104 104
 
105
-            if (! $this->isValidRoute($route) || ! $this->isRouteVisibleForDocumentation($route->getAction())) {
105
+            if (!$this->isValidRoute($route) || !$this->isRouteVisibleForDocumentation($route->getAction())) {
106 106
                 $this->warn(sprintf($messageFormat, 'Skipping', $routeMethods, $routePath));
107 107
                 continue;
108 108
             }
@@ -111,7 +111,7 @@  discard block
 block discarded – undo
111 111
                 $parsedRoutes[] = $generator->processRoute($route, $routeItem['apply'] ?? []);
112 112
                 $this->info(sprintf($messageFormat, 'Processed', $routeMethods, $routePath));
113 113
             } catch (\Exception $exception) {
114
-                $this->warn(sprintf($messageFormat, 'Skipping', $routeMethods, $routePath).' - '.$exception->getMessage());
114
+                $this->warn(sprintf($messageFormat, 'Skipping', $routeMethods, $routePath) . ' - ' . $exception->getMessage());
115 115
             }
116 116
         }
117 117
 
@@ -130,7 +130,7 @@  discard block
 block discarded – undo
130 130
             $action = implode('@', $action);
131 131
         }
132 132
 
133
-        return ! is_callable($action) && ! is_null($action);
133
+        return !is_callable($action) && !is_null($action);
134 134
     }
135 135
 
136 136
     /**
@@ -145,7 +145,7 @@  discard block
 block discarded – undo
145 145
         list($class, $method) = Utils::getRouteClassAndMethodNames($action);
146 146
         $reflection = new ReflectionClass($class);
147 147
 
148
-        if (! $reflection->hasMethod($method)) {
148
+        if (!$reflection->hasMethod($method)) {
149 149
             return false;
150 150
         }
151 151
 
@@ -155,7 +155,7 @@  discard block
 block discarded – undo
155 155
             $phpdoc = new DocBlock($comment);
156 156
 
157 157
             return collect($phpdoc->getTags())
158
-                ->filter(function ($tag) {
158
+                ->filter(function($tag) {
159 159
                     return $tag->getName() === 'hideFromAPIDocumentation';
160 160
                 })
161 161
                 ->isEmpty();
Please login to merge, or discard this patch.
src/Extracting/Strategies/Responses/UseResponseFileTag.php 1 patch
Spacing   +5 added lines, -5 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,16 +53,16 @@  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
             $relativeFilePath = trim($result[2]);
59 59
             $filePath = storage_path($relativeFilePath);
60
-            if (! file_exists($filePath)) {
61
-                throw new \Exception('@responseFile '.$relativeFilePath.' does not exist');
60
+            if (!file_exists($filePath)) {
61
+                throw new \Exception('@responseFile ' . $relativeFilePath . ' does not exist');
62 62
             }
63 63
             $status = $result[1] ?: 200;
64 64
             $content = $result[2] ? file_get_contents($filePath, true) : '{}';
65
-            $json = ! empty($result[3]) ? str_replace("'", '"', $result[3]) : '{}';
65
+            $json = !empty($result[3]) ? str_replace("'", '"', $result[3]) : '{}';
66 66
             $merged = array_merge(json_decode($content, true), json_decode($json, true));
67 67
 
68 68
             return ['content' => json_encode($merged), 'status' => (int) $status];
Please login to merge, or discard this patch.