Completed
Pull Request — master (#326)
by
unknown
01:39
created
src/Mpociot/ApiDoc/Generators/AbstractGenerator.php 2 patches
Doc Comments   +7 added lines, -8 removed lines patch added patch discarded remove patch
@@ -22,7 +22,7 @@  discard block
 block discarded – undo
22 22
     /**
23 23
      * @param Route $route
24 24
      *
25
-     * @return mixed
25
+     * @return string|null
26 26
      */
27 27
     public function getDomain(Route $route)
28 28
     {
@@ -32,7 +32,7 @@  discard block
 block discarded – undo
32 32
     /**
33 33
      * @param Route $route
34 34
      *
35
-     * @return mixed
35
+     * @return string
36 36
      */
37 37
     public function getUri(Route $route)
38 38
     {
@@ -109,7 +109,6 @@  discard block
 block discarded – undo
109 109
     /**
110 110
      * Prepares / Disables route middlewares.
111 111
      *
112
-     * @param  bool $disable
113 112
      *
114 113
      * @return  void
115 114
      */
@@ -120,7 +119,7 @@  discard block
 block discarded – undo
120 119
      *
121 120
      * @param array $tags
122 121
      *
123
-     * @return mixed
122
+     * @return null|\Symfony\Component\HttpFoundation\Response
124 123
      */
125 124
     protected function getDocblockResponse($tags)
126 125
     {
@@ -193,7 +192,7 @@  discard block
 block discarded – undo
193 192
     }
194 193
 
195 194
     /**
196
-     * @param  $route
195
+     * @param  Route $route
197 196
      * @param  $bindings
198 197
      * @param  $headers
199 198
      *
@@ -224,7 +223,7 @@  discard block
 block discarded – undo
224 223
      * @param $route
225 224
      * @param array $bindings
226 225
      *
227
-     * @return mixed
226
+     * @return string
228 227
      */
229 228
     protected function addRouteModelBindings($route, $bindings)
230 229
     {
@@ -643,7 +642,7 @@  discard block
 block discarded – undo
643 642
      * @param  string  $rule
644 643
      * @param  string  $parameter
645 644
      *
646
-     * @return array
645
+     * @return string
647 646
      */
648 647
     protected function parseParameters($rule, $parameter)
649 648
     {
@@ -674,7 +673,7 @@  discard block
 block discarded – undo
674 673
     }
675 674
 
676 675
     /**
677
-     * @param $response
676
+     * @param null|\Symfony\Component\HttpFoundation\Response $response
678 677
      *
679 678
      * @return mixed
680 679
      */
Please login to merge, or discard this 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
 
@@ -183,9 +183,9 @@  discard block
 block discarded – undo
183 183
         }
184 184
 
185 185
         $values = collect($simplifiedRules)
186
-            ->filter(function ($values) {
186
+            ->filter(function($values) {
187 187
                 return in_array('array', $values);
188
-            })->map(function ($val, $key) {
188
+            })->map(function($val, $key) {
189 189
                 return [''];
190 190
             })->all();
191 191
 
@@ -206,7 +206,7 @@  discard block
 block discarded – undo
206 206
         $methods = $this->getMethods($route);
207 207
 
208 208
         // Split headers into key - value pairs
209
-        $headers = collect($headers)->map(function ($value) {
209
+        $headers = collect($headers)->map(function($value) {
210 210
             $split = explode(':', $value); // explode to get key + values
211 211
             $key = array_shift($split); // extract the key and keep the values in the array
212 212
             $value = implode(':', $split); // implode values into string again
@@ -230,8 +230,8 @@  discard block
 block discarded – undo
230 230
     {
231 231
         $uri = $this->getUri($route);
232 232
         foreach ($bindings as $model => $id) {
233
-            $uri = str_replace('{'.$model.'}', $id, $uri);
234
-            $uri = str_replace('{'.$model.'?}', $id, $uri);
233
+            $uri = str_replace('{' . $model . '}', $id, $uri);
234
+            $uri = str_replace('{' . $model . '?}', $id, $uri);
235 235
         }
236 236
 
237 237
         return $uri;
@@ -295,7 +295,7 @@  discard block
 block discarded – undo
295 295
 
296 296
         foreach ($reflectionMethod->getParameters() as $parameter) {
297 297
             $parameterType = $parameter->getClass();
298
-            if (! is_null($parameterType) && class_exists($parameterType->name)) {
298
+            if (!is_null($parameterType) && class_exists($parameterType->name)) {
299 299
                 $className = $parameterType->name;
300 300
 
301 301
                 if (is_subclass_of($className, FormRequest::class)) {
@@ -331,8 +331,8 @@  discard block
 block discarded – undo
331 331
      */
332 332
     protected function fancyImplode($arr, $first, $last)
333 333
     {
334
-        $arr = array_map(function ($value) {
335
-            return '`'.$value.'`';
334
+        $arr = array_map(function($value) {
335
+            return '`' . $value . '`';
336 336
         }, $arr);
337 337
         array_push($arr, implode($last, array_splice($arr, -2)));
338 338
 
@@ -342,8 +342,8 @@  discard block
 block discarded – undo
342 342
     protected function splitValuePairs($parameters, $first = 'is ', $last = 'or ')
343 343
     {
344 344
         $attribute = '';
345
-        collect($parameters)->map(function ($item, $key) use (&$attribute, $first, $last) {
346
-            $attribute .= '`'.$item.'` ';
345
+        collect($parameters)->map(function($item, $key) use (&$attribute, $first, $last) {
346
+            $attribute .= '`' . $item . '` ';
347 347
             if (($key + 1) % 2 === 0) {
348 348
                 $attribute .= $last;
349 349
             } else {
@@ -426,7 +426,7 @@  discard block
 block discarded – undo
426 426
                 }
427 427
                 break;
428 428
             case 'between':
429
-                if (! isset($attributeData['type'])) {
429
+                if (!isset($attributeData['type'])) {
430 430
                     $attributeData['type'] = 'numeric';
431 431
                 }
432 432
                 $attributeData['description'][] = Description::parse($rule)->with($parameters)->getDescription();
@@ -604,8 +604,8 @@  discard block
 block discarded – undo
604 604
         foreach ($headers as $name => $value) {
605 605
             $name = strtr(strtoupper($name), '-', '_');
606 606
 
607
-            if (! Str::startsWith($name, $prefix) && $name !== 'CONTENT_TYPE') {
608
-                $name = $prefix.$name;
607
+            if (!Str::startsWith($name, $prefix) && $name !== 'CONTENT_TYPE') {
608
+                $name = $prefix . $name;
609 609
             }
610 610
 
611 611
             $server[$name] = $value;
@@ -702,8 +702,8 @@  discard block
 block discarded – undo
702 702
     protected function getTransformerResponse($tags)
703 703
     {
704 704
         try {
705
-            $transFormerTags = array_filter($tags, function ($tag) {
706
-                if (! ($tag instanceof Tag)) {
705
+            $transFormerTags = array_filter($tags, function($tag) {
706
+                if (!($tag instanceof Tag)) {
707 707
                     return false;
708 708
                 }
709 709
 
@@ -714,8 +714,8 @@  discard block
 block discarded – undo
714 714
                 return false;
715 715
             }
716 716
 
717
-            $modelTag = array_first(array_filter($tags, function ($tag) {
718
-                if (! ($tag instanceof Tag)) {
717
+            $modelTag = array_first(array_filter($tags, function($tag) {
718
+                if (!($tag instanceof Tag)) {
719 719
                     return false;
720 720
                 }
721 721
 
@@ -723,7 +723,7 @@  discard block
 block discarded – undo
723 723
             }));
724 724
             $tag = \array_first($transFormerTags);
725 725
             $transformer = $tag->getContent();
726
-            if (! \class_exists($transformer)) {
726
+            if (!\class_exists($transformer)) {
727 727
                 // if we can't find the transformer we can't generate a response
728 728
                 return;
729 729
             }
@@ -739,7 +739,7 @@  discard block
 block discarded – undo
739 739
             if (version_compare(PHP_VERSION, '7.0.0') >= 0 && \is_null($type)) {
740 740
                 // we can only get the type with reflection for PHP 7
741 741
                 if ($parameter->hasType() &&
742
-                    ! $parameter->getType()->isBuiltin() &&
742
+                    !$parameter->getType()->isBuiltin() &&
743 743
                     \class_exists((string) $parameter->getType())) {
744 744
                     //we have a type
745 745
                     $type = (string) $parameter->getType();
Please login to merge, or discard this patch.
src/Mpociot/ApiDoc/Generators/LaravelGenerator.php 1 patch
Doc Comments   -1 removed lines patch added patch discarded remove patch
@@ -41,7 +41,6 @@
 block discarded – undo
41 41
     /**
42 42
      * Prepares / Disables route middlewares.
43 43
      *
44
-     * @param  bool $disable
45 44
      *
46 45
      * @return  void
47 46
      */
Please login to merge, or discard this patch.
src/Mpociot/ApiDoc/Commands/GenerateDocumentation.php 2 patches
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -278,7 +278,7 @@
 block discarded – undo
278 278
                 || (str_is($routeDomain, $generator->getDomain($route))
279 279
                     && str_is($routePrefix, $generator->getUri($route)))
280 280
                 || in_array($middleware, $route->middleware())
281
-               ) {
281
+                ) {
282 282
                 if ($this->isValidRoute($route) && $this->isRouteVisibleForDocumentation($route->getAction()['uses'])) {
283 283
                     $parsedRoutes[] = $generator->processRoute($route, $bindings, $this->option('header'), $withResponse && in_array('GET', $generator->getMethods($route)));
284 284
                     $this->info('Processed route: ['.implode(',', $generator->getMethods($route)).'] '.$generator->getUri($route));
Please login to merge, or discard this 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;
@@ -102,7 +102,7 @@  discard block
 block discarded – undo
102 102
                 }
103 103
             }
104 104
         }
105
-        $parsedRoutes = collect($parsedRoutes)->groupBy('resource')->sort(function ($a, $b) {
105
+        $parsedRoutes = collect($parsedRoutes)->groupBy('resource')->sort(function($a, $b) {
106 106
             return strcmp($a->first()['resource'], $b->first()['resource']);
107 107
         });
108 108
 
@@ -117,15 +117,15 @@  discard block
 block discarded – undo
117 117
     private function writeMarkdown($parsedRoutes)
118 118
     {
119 119
         $outputPath = $this->option('output');
120
-        $targetFile = $outputPath.DIRECTORY_SEPARATOR.'source'.DIRECTORY_SEPARATOR.'index.md';
121
-        $compareFile = $outputPath.DIRECTORY_SEPARATOR.'source'.DIRECTORY_SEPARATOR.'.compare.md';
120
+        $targetFile = $outputPath . DIRECTORY_SEPARATOR . 'source' . DIRECTORY_SEPARATOR . 'index.md';
121
+        $compareFile = $outputPath . DIRECTORY_SEPARATOR . 'source' . DIRECTORY_SEPARATOR . '.compare.md';
122 122
 
123 123
         $infoText = view('apidoc::partials.info')
124 124
             ->with('outputPath', ltrim($outputPath, 'public/'))
125
-            ->with('showPostmanCollectionButton', ! $this->option('noPostmanCollection'));
125
+            ->with('showPostmanCollectionButton', !$this->option('noPostmanCollection'));
126 126
 
127
-        $parsedRouteOutput = $parsedRoutes->map(function ($routeGroup) {
128
-            return $routeGroup->map(function ($route) {
127
+        $parsedRouteOutput = $parsedRoutes->map(function($routeGroup) {
128
+            return $routeGroup->map(function($route) {
129 129
                 $route['output'] = (string) view('apidoc::partials.route')->with('parsedRoute', $route)->render();
130 130
 
131 131
                 return $route;
@@ -145,16 +145,16 @@  discard block
 block discarded – undo
145 145
                 $frontmatter = trim($generatedFrontmatter[1], "\n");
146 146
             }
147 147
 
148
-            $parsedRouteOutput->transform(function ($routeGroup) use ($generatedDocumentation, $compareDocumentation) {
149
-                return $routeGroup->transform(function ($route) use ($generatedDocumentation, $compareDocumentation) {
150
-                    if (preg_match('/<!-- START_'.$route['id'].' -->(.*)<!-- END_'.$route['id'].' -->/is', $generatedDocumentation, $routeMatch)) {
151
-                        $routeDocumentationChanged = (preg_match('/<!-- START_'.$route['id'].' -->(.*)<!-- END_'.$route['id'].' -->/is', $compareDocumentation, $compareMatch) && $compareMatch[1] !== $routeMatch[1]);
148
+            $parsedRouteOutput->transform(function($routeGroup) use ($generatedDocumentation, $compareDocumentation) {
149
+                return $routeGroup->transform(function($route) use ($generatedDocumentation, $compareDocumentation) {
150
+                    if (preg_match('/<!-- START_' . $route['id'] . ' -->(.*)<!-- END_' . $route['id'] . ' -->/is', $generatedDocumentation, $routeMatch)) {
151
+                        $routeDocumentationChanged = (preg_match('/<!-- START_' . $route['id'] . ' -->(.*)<!-- END_' . $route['id'] . ' -->/is', $compareDocumentation, $compareMatch) && $compareMatch[1] !== $routeMatch[1]);
152 152
                         if ($routeDocumentationChanged === false || $this->option('force')) {
153 153
                             if ($routeDocumentationChanged) {
154
-                                $this->warn('Discarded manual changes for route ['.implode(',', $route['methods']).'] '.$route['uri']);
154
+                                $this->warn('Discarded manual changes for route [' . implode(',', $route['methods']) . '] ' . $route['uri']);
155 155
                             }
156 156
                         } else {
157
-                            $this->warn('Skipping modified route ['.implode(',', $route['methods']).'] '.$route['uri']);
157
+                            $this->warn('Skipping modified route [' . implode(',', $route['methods']) . '] ' . $route['uri']);
158 158
                             $route['modified_output'] = $routeMatch[0];
159 159
                         }
160 160
                     }
@@ -171,10 +171,10 @@  discard block
 block discarded – undo
171 171
             ->with('frontmatter', $frontmatter)
172 172
             ->with('infoText', $infoText)
173 173
             ->with('outputPath', $this->option('output'))
174
-            ->with('showPostmanCollectionButton', ! $this->option('noPostmanCollection'))
174
+            ->with('showPostmanCollectionButton', !$this->option('noPostmanCollection'))
175 175
             ->with('parsedRoutes', $parsedRouteOutput);
176 176
 
177
-        if (! is_dir($outputPath)) {
177
+        if (!is_dir($outputPath)) {
178 178
             $documentarian->create($outputPath);
179 179
         }
180 180
 
@@ -187,23 +187,23 @@  discard block
 block discarded – undo
187 187
             ->with('frontmatter', $frontmatter)
188 188
             ->with('infoText', $infoText)
189 189
             ->with('outputPath', $this->option('output'))
190
-            ->with('showPostmanCollectionButton', ! $this->option('noPostmanCollection'))
190
+            ->with('showPostmanCollectionButton', !$this->option('noPostmanCollection'))
191 191
             ->with('parsedRoutes', $parsedRouteOutput);
192 192
 
193 193
         file_put_contents($compareFile, $compareMarkdown);
194 194
 
195
-        $this->info('Wrote index.md to: '.$outputPath);
195
+        $this->info('Wrote index.md to: ' . $outputPath);
196 196
 
197 197
         $this->info('Generating API HTML code');
198 198
 
199 199
         $documentarian->generate($outputPath);
200 200
 
201
-        $this->info('Wrote HTML documentation to: '.$outputPath.'/index.html');
201
+        $this->info('Wrote HTML documentation to: ' . $outputPath . '/index.html');
202 202
 
203 203
         if ($this->option('noPostmanCollection') !== true) {
204 204
             $this->info('Generating Postman collection');
205 205
 
206
-            file_put_contents($outputPath.DIRECTORY_SEPARATOR.'collection.json', $this->generatePostmanCollection($parsedRoutes));
206
+            file_put_contents($outputPath . DIRECTORY_SEPARATOR . 'collection.json', $this->generatePostmanCollection($parsedRoutes));
207 207
         }
208 208
     }
209 209
 
@@ -232,7 +232,7 @@  discard block
 block discarded – undo
232 232
      */
233 233
     private function setUserToBeImpersonated($actAs)
234 234
     {
235
-        if (! empty($actAs)) {
235
+        if (!empty($actAs)) {
236 236
             if (version_compare($this->laravel->version(), '5.2.0', '<')) {
237 237
                 $userModel = config('auth.model');
238 238
                 $user = $userModel::find($actAs);
@@ -281,9 +281,9 @@  discard block
 block discarded – undo
281 281
                ) {
282 282
                 if ($this->isValidRoute($route) && $this->isRouteVisibleForDocumentation($route->getAction()['uses'])) {
283 283
                     $parsedRoutes[] = $generator->processRoute($route, $bindings, $this->option('header'), $withResponse && in_array('GET', $generator->getMethods($route)));
284
-                    $this->info('Processed route: ['.implode(',', $generator->getMethods($route)).'] '.$generator->getUri($route));
284
+                    $this->info('Processed route: [' . implode(',', $generator->getMethods($route)) . '] ' . $generator->getUri($route));
285 285
                 } else {
286
-                    $this->warn('Skipping route: ['.implode(',', $generator->getMethods($route)).'] '.$generator->getUri($route));
286
+                    $this->warn('Skipping route: [' . implode(',', $generator->getMethods($route)) . '] ' . $generator->getUri($route));
287 287
                 }
288 288
             }
289 289
         }
@@ -298,7 +298,7 @@  discard block
 block discarded – undo
298 298
      */
299 299
     private function isValidRoute(Route $route)
300 300
     {
301
-        return ! is_callable($route->getAction()['uses']) && ! is_null($route->getAction()['uses']);
301
+        return !is_callable($route->getAction()['uses']) && !is_null($route->getAction()['uses']);
302 302
     }
303 303
 
304 304
     /**
@@ -315,7 +315,7 @@  discard block
 block discarded – undo
315 315
             $phpdoc = new DocBlock($comment);
316 316
 
317 317
             return collect($phpdoc->getTags())
318
-                ->filter(function ($tag) use ($route) {
318
+                ->filter(function($tag) use ($route) {
319 319
                     return $tag->getName() === 'hideFromAPIDocumentation';
320 320
                 })
321 321
                 ->isEmpty();
Please login to merge, or discard this patch.