Completed
Pull Request — master (#327)
by
unknown
01:50
created
src/Mpociot/ApiDoc/Commands/GenerateDocumentation.php 1 patch
Spacing   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -76,7 +76,7 @@  discard block
 block discarded – undo
76 76
 
77 77
         $this->setUserToBeImpersonated($this->option('actAsUserId'));
78 78
 
79
-        if ($routePrefix === null && $routeDomain === null && ! count($allowedRoutes) && $middleware === null) {
79
+        if ($routePrefix === null && $routeDomain === null && !count($allowedRoutes) && $middleware === null) {
80 80
             $this->error('You must provide either a route prefix, a route domain, a route or a middleware to generate the documentation.');
81 81
 
82 82
             return false;
@@ -94,7 +94,7 @@  discard block
 block discarded – undo
94 94
                 $parsedRoutes += $this->processRoutes($generator, $allowedRoutes, $routeDomain, $routePrefix, $middleware);
95 95
             }
96 96
         }
97
-        $parsedRoutes = collect($parsedRoutes)->groupBy('resource')->sort(function ($a, $b) {
97
+        $parsedRoutes = collect($parsedRoutes)->groupBy('resource')->sort(function($a, $b) {
98 98
             return strcmp($a->first()['resource'], $b->first()['resource']);
99 99
         });
100 100
 
@@ -109,15 +109,15 @@  discard block
 block discarded – undo
109 109
     private function writeMarkdown($parsedRoutes)
110 110
     {
111 111
         $outputPath = $this->option('output');
112
-        $targetFile = $outputPath.DIRECTORY_SEPARATOR.'source'.DIRECTORY_SEPARATOR.'index.md';
113
-        $compareFile = $outputPath.DIRECTORY_SEPARATOR.'source'.DIRECTORY_SEPARATOR.'.compare.md';
112
+        $targetFile = $outputPath . DIRECTORY_SEPARATOR . 'source' . DIRECTORY_SEPARATOR . 'index.md';
113
+        $compareFile = $outputPath . DIRECTORY_SEPARATOR . 'source' . DIRECTORY_SEPARATOR . '.compare.md';
114 114
 
115 115
         $infoText = view('apidoc::partials.info')
116 116
             ->with('outputPath', ltrim($outputPath, 'public/'))
117
-            ->with('showPostmanCollectionButton', ! $this->option('noPostmanCollection'));
117
+            ->with('showPostmanCollectionButton', !$this->option('noPostmanCollection'));
118 118
 
119
-        $parsedRouteOutput = $parsedRoutes->map(function ($routeGroup) {
120
-            return $routeGroup->map(function ($route) {
119
+        $parsedRouteOutput = $parsedRoutes->map(function($routeGroup) {
120
+            return $routeGroup->map(function($route) {
121 121
                 $route['output'] = (string) view('apidoc::partials.route')->with('parsedRoute', $route)->render();
122 122
 
123 123
                 return $route;
@@ -137,16 +137,16 @@  discard block
 block discarded – undo
137 137
                 $frontmatter = trim($generatedFrontmatter[1], "\n");
138 138
             }
139 139
 
140
-            $parsedRouteOutput->transform(function ($routeGroup) use ($generatedDocumentation, $compareDocumentation) {
141
-                return $routeGroup->transform(function ($route) use ($generatedDocumentation, $compareDocumentation) {
142
-                    if (preg_match('/<!-- START_'.$route['id'].' -->(.*)<!-- END_'.$route['id'].' -->/is', $generatedDocumentation, $routeMatch)) {
143
-                        $routeDocumentationChanged = (preg_match('/<!-- START_'.$route['id'].' -->(.*)<!-- END_'.$route['id'].' -->/is', $compareDocumentation, $compareMatch) && $compareMatch[1] !== $routeMatch[1]);
140
+            $parsedRouteOutput->transform(function($routeGroup) use ($generatedDocumentation, $compareDocumentation) {
141
+                return $routeGroup->transform(function($route) use ($generatedDocumentation, $compareDocumentation) {
142
+                    if (preg_match('/<!-- START_' . $route['id'] . ' -->(.*)<!-- END_' . $route['id'] . ' -->/is', $generatedDocumentation, $routeMatch)) {
143
+                        $routeDocumentationChanged = (preg_match('/<!-- START_' . $route['id'] . ' -->(.*)<!-- END_' . $route['id'] . ' -->/is', $compareDocumentation, $compareMatch) && $compareMatch[1] !== $routeMatch[1]);
144 144
                         if ($routeDocumentationChanged === false || $this->option('force')) {
145 145
                             if ($routeDocumentationChanged) {
146
-                                $this->warn('Discarded manual changes for route ['.implode(',', $route['methods']).'] '.$route['uri']);
146
+                                $this->warn('Discarded manual changes for route [' . implode(',', $route['methods']) . '] ' . $route['uri']);
147 147
                             }
148 148
                         } else {
149
-                            $this->warn('Skipping modified route ['.implode(',', $route['methods']).'] '.$route['uri']);
149
+                            $this->warn('Skipping modified route [' . implode(',', $route['methods']) . '] ' . $route['uri']);
150 150
                             $route['modified_output'] = $routeMatch[0];
151 151
                         }
152 152
                     }
@@ -163,10 +163,10 @@  discard block
 block discarded – undo
163 163
             ->with('frontmatter', $frontmatter)
164 164
             ->with('infoText', $infoText)
165 165
             ->with('outputPath', $this->option('output'))
166
-            ->with('showPostmanCollectionButton', ! $this->option('noPostmanCollection'))
166
+            ->with('showPostmanCollectionButton', !$this->option('noPostmanCollection'))
167 167
             ->with('parsedRoutes', $parsedRouteOutput);
168 168
 
169
-        if (! is_dir($outputPath)) {
169
+        if (!is_dir($outputPath)) {
170 170
             $documentarian->create($outputPath);
171 171
         }
172 172
 
@@ -179,23 +179,23 @@  discard block
 block discarded – undo
179 179
             ->with('frontmatter', $frontmatter)
180 180
             ->with('infoText', $infoText)
181 181
             ->with('outputPath', $this->option('output'))
182
-            ->with('showPostmanCollectionButton', ! $this->option('noPostmanCollection'))
182
+            ->with('showPostmanCollectionButton', !$this->option('noPostmanCollection'))
183 183
             ->with('parsedRoutes', $parsedRouteOutput);
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->option('noPostmanCollection') !== true) {
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
 
@@ -224,7 +224,7 @@  discard block
 block discarded – undo
224 224
      */
225 225
     private function setUserToBeImpersonated($actAs)
226 226
     {
227
-        if (! empty($actAs)) {
227
+        if (!empty($actAs)) {
228 228
             if (version_compare($this->laravel->version(), '5.2.0', '<')) {
229 229
                 $userModel = config('auth.model');
230 230
                 $user = $userModel::find($actAs);
@@ -273,9 +273,9 @@  discard block
 block discarded – undo
273 273
                ) {
274 274
                 if ($this->isValidRoute($route) && $this->isRouteVisibleForDocumentation($route->getAction()['uses'])) {
275 275
                     $parsedRoutes[] = $generator->processRoute($route, $bindings, $this->option('header'), $withResponse && in_array('GET', $generator->getMethods($route)));
276
-                    $this->info('Processed route: ['.implode(',', $generator->getMethods($route)).'] '.$generator->getUri($route));
276
+                    $this->info('Processed route: [' . implode(',', $generator->getMethods($route)) . '] ' . $generator->getUri($route));
277 277
                 } else {
278
-                    $this->warn('Skipping route: ['.implode(',', $generator->getMethods($route)).'] '.$generator->getUri($route));
278
+                    $this->warn('Skipping route: [' . implode(',', $generator->getMethods($route)) . '] ' . $generator->getUri($route));
279 279
                 }
280 280
             }
281 281
         }
@@ -290,7 +290,7 @@  discard block
 block discarded – undo
290 290
      */
291 291
     private function isValidRoute(Route $route)
292 292
     {
293
-        return ! is_callable($route->getAction()['uses']) && ! is_null($route->getAction()['uses']);
293
+        return !is_callable($route->getAction()['uses']) && !is_null($route->getAction()['uses']);
294 294
     }
295 295
 
296 296
     /**
@@ -307,7 +307,7 @@  discard block
 block discarded – undo
307 307
             $phpdoc = new DocBlock($comment);
308 308
 
309 309
             return collect($phpdoc->getTags())
310
-                ->filter(function ($tag) use ($route) {
310
+                ->filter(function($tag) use ($route) {
311 311
                     return $tag->getName() === 'hideFromAPIDocumentation';
312 312
                 })
313 313
                 ->isEmpty();
Please login to merge, or discard this patch.
src/Mpociot/ApiDoc/Generators/AbstractGenerator.php 1 patch
Spacing   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -75,7 +75,7 @@  discard block
 block discarded – undo
75 75
             $response = $docblockResponse;
76 76
             $showresponse = true;
77 77
         }
78
-        if (! $response) {
78
+        if (!$response) {
79 79
             $transformerResponse = $this->getTransformerResponse($routeDescription['tags']);
80 80
             if ($transformerResponse) {
81 81
                 // we have a transformer response from the docblock ( @transformer || @transformercollection )
@@ -83,18 +83,18 @@  discard block
 block discarded – undo
83 83
                 $showresponse = true;
84 84
             }
85 85
         }
86
-        if (! $response && $withResponse) {
86
+        if (!$response && $withResponse) {
87 87
             try {
88 88
                 $response = $this->getRouteResponse($route, $bindings, $headers);
89 89
             } catch (\Exception $e) {
90
-                echo "Couldn't get response for route: ".implode(',', $this->getMethods($route)).$route->uri().']: '.$e->getMessage()."\n";
90
+                echo "Couldn't get response for route: " . implode(',', $this->getMethods($route)) . $route->uri() . ']: ' . $e->getMessage() . "\n";
91 91
             }
92 92
         }
93 93
 
94 94
         $content = $this->getResponseContent($response);
95 95
 
96 96
         return $this->getParameters([
97
-            'id' => md5($this->getUri($route).':'.implode($this->getMethods($route))),
97
+            'id' => md5($this->getUri($route) . ':' . implode($this->getMethods($route))),
98 98
             'resource' => $routeGroup,
99 99
             'title' => $routeDescription['short'],
100 100
             'description' => $routeDescription['long'],
@@ -124,8 +124,8 @@  discard block
 block discarded – undo
124 124
      */
125 125
     protected function getDocblockResponse($tags)
126 126
     {
127
-        $responseTags = array_filter($tags, function ($tag) {
128
-            if (! ($tag instanceof Tag)) {
127
+        $responseTags = array_filter($tags, function($tag) {
128
+            if (!($tag instanceof Tag)) {
129 129
                 return false;
130 130
             }
131 131
 
@@ -187,9 +187,9 @@  discard block
 block discarded – undo
187 187
         // Laravel will ignore the nested array rules unless the key referenced exists and is an array
188 188
         // So we'll to create an empty array for each array attribute
189 189
         $values = collect($rules)
190
-            ->filter(function ($values) {
190
+            ->filter(function($values) {
191 191
                 return in_array('array', $values);
192
-            })->map(function ($val, $key) {
192
+            })->map(function($val, $key) {
193 193
                 return [''];
194 194
             })->all();
195 195
 
@@ -212,7 +212,7 @@  discard block
 block discarded – undo
212 212
         $methods = $this->getMethods($route);
213 213
 
214 214
         // Split headers into key - value pairs
215
-        $headers = collect($headers)->map(function ($value) {
215
+        $headers = collect($headers)->map(function($value) {
216 216
             $split = explode(':', $value); // explode to get key + values
217 217
             $key = array_shift($split); // extract the key and keep the values in the array
218 218
             $value = implode(':', $split); // implode values into string again
@@ -236,8 +236,8 @@  discard block
 block discarded – undo
236 236
     {
237 237
         $uri = $this->getUri($route);
238 238
         foreach ($bindings as $model => $id) {
239
-            $uri = str_replace('{'.$model.'}', $id, $uri);
240
-            $uri = str_replace('{'.$model.'?}', $id, $uri);
239
+            $uri = str_replace('{' . $model . '}', $id, $uri);
240
+            $uri = str_replace('{' . $model . '?}', $id, $uri);
241 241
         }
242 242
 
243 243
         return $uri;
@@ -301,7 +301,7 @@  discard block
 block discarded – undo
301 301
 
302 302
         foreach ($reflectionMethod->getParameters() as $parameter) {
303 303
             $parameterType = $parameter->getClass();
304
-            if (! is_null($parameterType) && class_exists($parameterType->name)) {
304
+            if (!is_null($parameterType) && class_exists($parameterType->name)) {
305 305
                 $className = $parameterType->name;
306 306
 
307 307
                 if (is_subclass_of($className, FormRequest::class)) {
@@ -337,8 +337,8 @@  discard block
 block discarded – undo
337 337
      */
338 338
     protected function fancyImplode($arr, $first, $last)
339 339
     {
340
-        $arr = array_map(function ($value) {
341
-            return '`'.$value.'`';
340
+        $arr = array_map(function($value) {
341
+            return '`' . $value . '`';
342 342
         }, $arr);
343 343
         array_push($arr, implode($last, array_splice($arr, -2)));
344 344
 
@@ -348,8 +348,8 @@  discard block
 block discarded – undo
348 348
     protected function splitValuePairs($parameters, $first = 'is ', $last = 'or ')
349 349
     {
350 350
         $attribute = '';
351
-        collect($parameters)->map(function ($item, $key) use (&$attribute, $first, $last) {
352
-            $attribute .= '`'.$item.'` ';
351
+        collect($parameters)->map(function($item, $key) use (&$attribute, $first, $last) {
352
+            $attribute .= '`' . $item . '` ';
353 353
             if (($key + 1) % 2 === 0) {
354 354
                 $attribute .= $last;
355 355
             } else {
@@ -432,7 +432,7 @@  discard block
 block discarded – undo
432 432
                 }
433 433
                 break;
434 434
             case 'between':
435
-                if (! isset($attributeData['type'])) {
435
+                if (!isset($attributeData['type'])) {
436 436
                     $attributeData['type'] = 'numeric';
437 437
                 }
438 438
                 $attributeData['description'][] = Description::parse($rule)->with($parameters)->getDescription();
@@ -610,8 +610,8 @@  discard block
 block discarded – undo
610 610
         foreach ($headers as $name => $value) {
611 611
             $name = strtr(strtoupper($name), '-', '_');
612 612
 
613
-            if (! Str::startsWith($name, $prefix) && $name !== 'CONTENT_TYPE') {
614
-                $name = $prefix.$name;
613
+            if (!Str::startsWith($name, $prefix) && $name !== 'CONTENT_TYPE') {
614
+                $name = $prefix . $name;
615 615
             }
616 616
 
617 617
             $server[$name] = $value;
@@ -708,8 +708,8 @@  discard block
 block discarded – undo
708 708
     protected function getTransformerResponse($tags)
709 709
     {
710 710
         try {
711
-            $transFormerTags = array_filter($tags, function ($tag) {
712
-                if (! ($tag instanceof Tag)) {
711
+            $transFormerTags = array_filter($tags, function($tag) {
712
+                if (!($tag instanceof Tag)) {
713 713
                     return false;
714 714
                 }
715 715
 
@@ -720,8 +720,8 @@  discard block
 block discarded – undo
720 720
                 return false;
721 721
             }
722 722
 
723
-            $modelTag = array_first(array_filter($tags, function ($tag) {
724
-                if (! ($tag instanceof Tag)) {
723
+            $modelTag = array_first(array_filter($tags, function($tag) {
724
+                if (!($tag instanceof Tag)) {
725 725
                     return false;
726 726
                 }
727 727
 
@@ -729,7 +729,7 @@  discard block
 block discarded – undo
729 729
             }));
730 730
             $tag = \array_first($transFormerTags);
731 731
             $transformer = $tag->getContent();
732
-            if (! \class_exists($transformer)) {
732
+            if (!\class_exists($transformer)) {
733 733
                 // if we can't find the transformer we can't generate a response
734 734
                 return;
735 735
             }
@@ -745,7 +745,7 @@  discard block
 block discarded – undo
745 745
             if (version_compare(PHP_VERSION, '7.0.0') >= 0 && \is_null($type)) {
746 746
                 // we can only get the type with reflection for PHP 7
747 747
                 if ($parameter->hasType() &&
748
-                    ! $parameter->getType()->isBuiltin() &&
748
+                    !$parameter->getType()->isBuiltin() &&
749 749
                     \class_exists((string) $parameter->getType())) {
750 750
                     //we have a type
751 751
                     $type = (string) $parameter->getType();
Please login to merge, or discard this patch.