Completed
Pull Request — master (#369)
by
unknown
01:41
created
src/Commands/GenerateDocumentation.php 1 patch
Spacing   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -58,7 +58,7 @@  discard block
 block discarded – undo
58 58
 
59 59
         $parsedRoutes = $this->processRoutes($generator, $routes);
60 60
         $parsedRoutes = collect($parsedRoutes)->groupBy('resource')
61
-            ->sort(function ($a, $b) {
61
+            ->sort(function($a, $b) {
62 62
                 return strcmp($a->first()['resource'], $b->first()['resource']);
63 63
             });
64 64
 
@@ -73,17 +73,17 @@  discard block
 block discarded – undo
73 73
     private function writeMarkdown($parsedRoutes)
74 74
     {
75 75
         $outputPath = config('apidoc.output');
76
-        $targetFile = $outputPath.DIRECTORY_SEPARATOR.'source'.DIRECTORY_SEPARATOR.'index.md';
77
-        $compareFile = $outputPath.DIRECTORY_SEPARATOR.'source'.DIRECTORY_SEPARATOR.'.compare.md';
78
-        $prependFile = $outputPath.DIRECTORY_SEPARATOR.'source'.DIRECTORY_SEPARATOR.'prepend.md';
79
-        $appendFile = $outputPath.DIRECTORY_SEPARATOR.'source'.DIRECTORY_SEPARATOR.'append.md';
76
+        $targetFile = $outputPath . DIRECTORY_SEPARATOR . 'source' . DIRECTORY_SEPARATOR . 'index.md';
77
+        $compareFile = $outputPath . DIRECTORY_SEPARATOR . 'source' . DIRECTORY_SEPARATOR . '.compare.md';
78
+        $prependFile = $outputPath . DIRECTORY_SEPARATOR . 'source' . DIRECTORY_SEPARATOR . 'prepend.md';
79
+        $appendFile = $outputPath . DIRECTORY_SEPARATOR . 'source' . DIRECTORY_SEPARATOR . 'append.md';
80 80
 
81 81
         $infoText = view('apidoc::partials.info')
82 82
             ->with('outputPath', ltrim($outputPath, 'public/'))
83 83
             ->with('showPostmanCollectionButton', config('apidoc.postman'));
84 84
 
85
-        $parsedRouteOutput = $parsedRoutes->map(function ($routeGroup) {
86
-            return $routeGroup->map(function ($route) {
85
+        $parsedRouteOutput = $parsedRoutes->map(function($routeGroup) {
86
+            return $routeGroup->map(function($route) {
87 87
                 $route['output'] = (string) view('apidoc::partials.route')->with('route', $route)->render();
88 88
 
89 89
                 return $route;
@@ -103,16 +103,16 @@  discard block
 block discarded – undo
103 103
                 $frontmatter = trim($generatedFrontmatter[1], "\n");
104 104
             }
105 105
 
106
-            $parsedRouteOutput->transform(function ($routeGroup) use ($generatedDocumentation, $compareDocumentation) {
107
-                return $routeGroup->transform(function ($route) use ($generatedDocumentation, $compareDocumentation) {
108
-                    if (preg_match('/<!-- START_'.$route['id'].' -->(.*)<!-- END_'.$route['id'].' -->/is', $generatedDocumentation, $existingRouteDoc)) {
109
-                        $routeDocumentationChanged = (preg_match('/<!-- START_'.$route['id'].' -->(.*)<!-- END_'.$route['id'].' -->/is', $compareDocumentation, $lastDocWeGeneratedForThisRoute) && $lastDocWeGeneratedForThisRoute[1] !== $existingRouteDoc[1]);
106
+            $parsedRouteOutput->transform(function($routeGroup) use ($generatedDocumentation, $compareDocumentation) {
107
+                return $routeGroup->transform(function($route) use ($generatedDocumentation, $compareDocumentation) {
108
+                    if (preg_match('/<!-- START_' . $route['id'] . ' -->(.*)<!-- END_' . $route['id'] . ' -->/is', $generatedDocumentation, $existingRouteDoc)) {
109
+                        $routeDocumentationChanged = (preg_match('/<!-- START_' . $route['id'] . ' -->(.*)<!-- END_' . $route['id'] . ' -->/is', $compareDocumentation, $lastDocWeGeneratedForThisRoute) && $lastDocWeGeneratedForThisRoute[1] !== $existingRouteDoc[1]);
110 110
                         if ($routeDocumentationChanged === false || $this->option('force')) {
111 111
                             if ($routeDocumentationChanged) {
112
-                                $this->warn('Discarded manual changes for route ['.implode(',', $route['methods']).'] '.$route['uri']);
112
+                                $this->warn('Discarded manual changes for route [' . implode(',', $route['methods']) . '] ' . $route['uri']);
113 113
                             }
114 114
                         } else {
115
-                            $this->warn('Skipping modified route ['.implode(',', $route['methods']).'] '.$route['uri']);
115
+                            $this->warn('Skipping modified route [' . implode(',', $route['methods']) . '] ' . $route['uri']);
116 116
                             $route['modified_output'] = $existingRouteDoc[0];
117 117
                         }
118 118
                     }
@@ -123,9 +123,9 @@  discard block
 block discarded – undo
123 123
         }
124 124
 
125 125
         $prependFileContents = file_exists($prependFile)
126
-            ? file_get_contents($prependFile)."\n" : '';
126
+            ? file_get_contents($prependFile) . "\n" : '';
127 127
         $appendFileContents = file_exists($appendFile)
128
-            ? "\n".file_get_contents($appendFile) : '';
128
+            ? "\n" . file_get_contents($appendFile) : '';
129 129
 
130 130
         $documentarian = new Documentarian();
131 131
 
@@ -139,7 +139,7 @@  discard block
 block discarded – undo
139 139
             ->with('showPostmanCollectionButton', config('apidoc.postman'))
140 140
             ->with('parsedRoutes', $parsedRouteOutput);
141 141
 
142
-        if (! is_dir($outputPath)) {
142
+        if (!is_dir($outputPath)) {
143 143
             $documentarian->create($outputPath);
144 144
         }
145 145
 
@@ -159,18 +159,18 @@  discard block
 block discarded – undo
159 159
 
160 160
         file_put_contents($compareFile, $compareMarkdown);
161 161
 
162
-        $this->info('Wrote index.md to: '.$outputPath);
162
+        $this->info('Wrote index.md to: ' . $outputPath);
163 163
 
164 164
         $this->info('Generating API HTML code');
165 165
 
166 166
         $documentarian->generate($outputPath);
167 167
 
168
-        $this->info('Wrote HTML documentation to: '.$outputPath.'/index.html');
168
+        $this->info('Wrote HTML documentation to: ' . $outputPath . '/index.html');
169 169
 
170 170
         if (config('apidoc.postman')) {
171 171
             $this->info('Generating Postman collection');
172 172
 
173
-            file_put_contents($outputPath.DIRECTORY_SEPARATOR.'collection.json', $this->generatePostmanCollection($parsedRoutes));
173
+            file_put_contents($outputPath . DIRECTORY_SEPARATOR . 'collection.json', $this->generatePostmanCollection($parsedRoutes));
174 174
         }
175 175
     }
176 176
 
@@ -188,9 +188,9 @@  discard block
 block discarded – undo
188 188
             /** @var Route $route */
189 189
             if ($this->isValidRoute($route) && $this->isRouteVisibleForDocumentation($route->getAction()['uses'])) {
190 190
                 $parsedRoutes[] = $generator->processRoute($route) + $routeItem['apply'];
191
-                $this->info('Processed route: ['.implode(',', $generator->getMethods($route)).'] '.$generator->getUri($route));
191
+                $this->info('Processed route: [' . implode(',', $generator->getMethods($route)) . '] ' . $generator->getUri($route));
192 192
             } else {
193
-                $this->warn('Skipping route: ['.implode(',', $generator->getMethods($route)).'] '.$generator->getUri($route));
193
+                $this->warn('Skipping route: [' . implode(',', $generator->getMethods($route)) . '] ' . $generator->getUri($route));
194 194
             }
195 195
         }
196 196
 
@@ -204,7 +204,7 @@  discard block
 block discarded – undo
204 204
      */
205 205
     private function isValidRoute(Route $route)
206 206
     {
207
-        return ! is_callable($route->getAction()['uses']) && ! is_null($route->getAction()['uses']);
207
+        return !is_callable($route->getAction()['uses']) && !is_null($route->getAction()['uses']);
208 208
     }
209 209
 
210 210
     /**
@@ -221,7 +221,7 @@  discard block
 block discarded – undo
221 221
             $phpdoc = new DocBlock($comment);
222 222
 
223 223
             return collect($phpdoc->getTags())
224
-                ->filter(function ($tag) use ($route) {
224
+                ->filter(function($tag) use ($route) {
225 225
                     return $tag->getName() === 'hideFromAPIDocumentation';
226 226
                 })
227 227
                 ->isEmpty();
Please login to merge, or discard this patch.
src/Generators/AbstractGenerator.php 1 patch
Spacing   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -58,7 +58,7 @@  discard block
 block discarded – undo
58 58
         $content = $this->getResponse($docBlock['tags']);
59 59
 
60 60
         return [
61
-            'id' => md5($this->getUri($route).':'.implode($this->getMethods($route))),
61
+            'id' => md5($this->getUri($route) . ':' . implode($this->getMethods($route))),
62 62
             'resource' => $routeGroup,
63 63
             'title' => $docBlock['short'],
64 64
             'description' => $docBlock['long'],
@@ -67,7 +67,7 @@  discard block
 block discarded – undo
67 67
             'parameters' => $this->getParametersFromDocBlock($docBlock['tags']),
68 68
             'authenticated' => $this->getAuthStatusFromDocBlock($docBlock['tags']),
69 69
             'response' => $content,
70
-            'showresponse' => ! empty($content),
70
+            'showresponse' => !empty($content),
71 71
         ];
72 72
     }
73 73
 
@@ -89,7 +89,7 @@  discard block
 block discarded – undo
89 89
      */
90 90
     protected function getDocblockResponse($tags)
91 91
     {
92
-        $responseTags = array_filter($tags, function ($tag) {
92
+        $responseTags = array_filter($tags, function($tag) {
93 93
             return $tag instanceof Tag && \strtolower($tag->getName()) == 'response';
94 94
         });
95 95
         if (empty($responseTags)) {
@@ -108,10 +108,10 @@  discard block
 block discarded – undo
108 108
     protected function getParametersFromDocBlock(array $tags)
109 109
     {
110 110
         $parameters = collect($tags)
111
-            ->filter(function ($tag) {
111
+            ->filter(function($tag) {
112 112
                 return $tag instanceof Tag && $tag->getName() === 'bodyParam';
113 113
             })
114
-            ->mapWithKeys(function ($tag) {
114
+            ->mapWithKeys(function($tag) {
115 115
                 preg_match('/(.+?)\s+(.+?)\s+(required\s+)?(.*)/', $tag->getContent(), $content);
116 116
                 if (empty($content)) {
117 117
                     // this means only name and type were supplied
@@ -145,7 +145,7 @@  discard block
 block discarded – undo
145 145
     protected function getAuthStatusFromDocBlock(array $tags)
146 146
     {
147 147
         $authTag = collect($tags)
148
-            ->first(function ($tag) {
148
+            ->first(function($tag) {
149 149
                 return $tag instanceof Tag && strtolower($tag->getName()) === 'authenticated';
150 150
             });
151 151
         return (bool) $authTag;
@@ -165,7 +165,7 @@  discard block
 block discarded – undo
165 165
         $methods = $this->getMethods($route);
166 166
 
167 167
         // Split headers into key - value pairs
168
-        $headers = collect($headers)->map(function ($value) {
168
+        $headers = collect($headers)->map(function($value) {
169 169
             $split = explode(':', $value); // explode to get key + values
170 170
             $key = array_shift($split); // extract the key and keep the values in the array
171 171
             $value = implode(':', $split); // implode values into string again
@@ -189,8 +189,8 @@  discard block
 block discarded – undo
189 189
     {
190 190
         $uri = $this->getUri($route);
191 191
         foreach ($bindings as $model => $id) {
192
-            $uri = str_replace('{'.$model.'}', $id, $uri);
193
-            $uri = str_replace('{'.$model.'?}', $id, $uri);
192
+            $uri = str_replace('{' . $model . '}', $id, $uri);
193
+            $uri = str_replace('{' . $model . '?}', $id, $uri);
194 194
         }
195 195
 
196 196
         return $uri;
@@ -269,8 +269,8 @@  discard block
 block discarded – undo
269 269
         foreach ($headers as $name => $value) {
270 270
             $name = strtr(strtoupper($name), '-', '_');
271 271
 
272
-            if (! Str::startsWith($name, $prefix) && $name !== 'CONTENT_TYPE') {
273
-                $name = $prefix.$name;
272
+            if (!Str::startsWith($name, $prefix) && $name !== 'CONTENT_TYPE') {
273
+                $name = $prefix . $name;
274 274
             }
275 275
 
276 276
             $server[$name] = $value;
@@ -308,8 +308,8 @@  discard block
 block discarded – undo
308 308
     protected function getTransformerResponse($tags)
309 309
     {
310 310
         try {
311
-            $transFormerTags = array_filter($tags, function ($tag) {
312
-                if (! ($tag instanceof Tag)) {
311
+            $transFormerTags = array_filter($tags, function($tag) {
312
+                if (!($tag instanceof Tag)) {
313 313
                     return false;
314 314
                 }
315 315
 
@@ -320,8 +320,8 @@  discard block
 block discarded – undo
320 320
                 return false;
321 321
             }
322 322
 
323
-            $modelTag = array_first(array_filter($tags, function ($tag) {
324
-                if (! ($tag instanceof Tag)) {
323
+            $modelTag = array_first(array_filter($tags, function($tag) {
324
+                if (!($tag instanceof Tag)) {
325 325
                     return false;
326 326
                 }
327 327
 
@@ -329,7 +329,7 @@  discard block
 block discarded – undo
329 329
             }));
330 330
             $tag = \array_first($transFormerTags);
331 331
             $transformer = $tag->getContent();
332
-            if (! \class_exists($transformer)) {
332
+            if (!\class_exists($transformer)) {
333 333
                 // if we can't find the transformer we can't generate a response
334 334
                 return;
335 335
             }
@@ -344,7 +344,7 @@  discard block
 block discarded – undo
344 344
             }
345 345
             if (\is_null($type)) {
346 346
                 if ($parameter->hasType() &&
347
-                    ! $parameter->getType()->isBuiltin() &&
347
+                    !$parameter->getType()->isBuiltin() &&
348 348
                     \class_exists((string) $parameter->getType())) {
349 349
                     //we have a type
350 350
                     $type = (string) $parameter->getType();
@@ -397,7 +397,7 @@  discard block
 block discarded – undo
397 397
             // we have a response from the docblock ( @response )
398 398
             $response = $docblockResponse;
399 399
         }
400
-        if (! $response && ($transformerResponse = $this->getTransformerResponse($annotationTags))) {
400
+        if (!$response && ($transformerResponse = $this->getTransformerResponse($annotationTags))) {
401 401
             // we have a transformer response from the docblock ( @transformer || @transformercollection )
402 402
             $response = $transformerResponse;
403 403
         }
@@ -422,25 +422,25 @@  discard block
 block discarded – undo
422 422
     {
423 423
         $faker = Factory::create();
424 424
         $fakes = [
425
-            'integer' => function () {
425
+            'integer' => function() {
426 426
                 return rand(1, 20);
427 427
             },
428
-            'number' => function () use ($faker) {
428
+            'number' => function() use ($faker) {
429 429
                 return $faker->randomFloat();
430 430
             },
431
-            'float' => function () use ($faker) {
431
+            'float' => function() use ($faker) {
432 432
                 return $faker->randomFloat();
433 433
             },
434
-            'boolean' => function () use ($faker) {
434
+            'boolean' => function() use ($faker) {
435 435
                 return $faker->boolean();
436 436
             },
437
-            'string' => function () use ($faker) {
437
+            'string' => function() use ($faker) {
438 438
                 return str_random();
439 439
             },
440
-            'array' => function () {
440
+            'array' => function() {
441 441
                 return '[]';
442 442
             },
443
-            'object' => function () {
443
+            'object' => function() {
444 444
                 return '{}';
445 445
             },
446 446
         ];
Please login to merge, or discard this patch.