Completed
Pull Request — master (#362)
by
unknown
08:36
created
src/Generators/AbstractGenerator.php 2 patches
Doc Comments   +3 added lines, -5 removed lines patch added patch discarded remove patch
@@ -26,7 +26,7 @@  discard block
 block discarded – undo
26 26
     /**
27 27
      * @param Route $route
28 28
      *
29
-     * @return mixed
29
+     * @return string
30 30
      */
31 31
     public function getUri(Route $route)
32 32
     {
@@ -45,7 +45,6 @@  discard block
 block discarded – undo
45 45
 
46 46
     /**
47 47
      * @param  \Illuminate\Routing\Route $route
48
-     * @param array $apply Rules to apply when generating documentation for this route
49 48
      *
50 49
      * @return array
51 50
      */
@@ -72,7 +71,6 @@  discard block
 block discarded – undo
72 71
     /**
73 72
      * Prepares / Disables route middlewares.
74 73
      *
75
-     * @param  bool $disable
76 74
      *
77 75
      * @return  void
78 76
      */
@@ -153,7 +151,7 @@  discard block
 block discarded – undo
153 151
      * @param $route
154 152
      * @param array $bindings
155 153
      *
156
-     * @return mixed
154
+     * @return string
157 155
      */
158 156
     protected function addRouteModelBindings($route, $bindings)
159 157
     {
@@ -169,7 +167,7 @@  discard block
 block discarded – undo
169 167
     /**
170 168
      * @param  \Illuminate\Routing\Route  $route
171 169
      *
172
-     * @return array
170
+     * @return Route
173 171
      */
174 172
     protected function parseDocBlock($route)
175 173
     {
Please login to merge, or discard this patch.
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -57,7 +57,7 @@  discard block
 block discarded – undo
57 57
         $content = $this->getResponse($docBlock['tags']);
58 58
 
59 59
         return [
60
-            'id' => md5($this->getUri($route).':'.implode($this->getMethods($route))),
60
+            'id' => md5($this->getUri($route) . ':' . implode($this->getMethods($route))),
61 61
             'resource' => $routeGroup,
62 62
             'title' => $docBlock['short'],
63 63
             'description' => $docBlock['long'],
@@ -65,7 +65,7 @@  discard block
 block discarded – undo
65 65
             'uri' => $this->getUri($route),
66 66
             'parameters' => $this->getParametersFromDocBlock($docBlock['tags']),
67 67
             'response' => $content,
68
-            'showresponse' => ! empty($content),
68
+            'showresponse' => !empty($content),
69 69
         ];
70 70
     }
71 71
 
@@ -87,7 +87,7 @@  discard block
 block discarded – undo
87 87
      */
88 88
     protected function getDocblockResponse($tags)
89 89
     {
90
-        $responseTags = array_filter($tags, function ($tag) {
90
+        $responseTags = array_filter($tags, function($tag) {
91 91
             return $tag instanceof Tag && \strtolower($tag->getName()) == 'response';
92 92
         });
93 93
         if (empty($responseTags)) {
@@ -106,10 +106,10 @@  discard block
 block discarded – undo
106 106
     protected function getParametersFromDocBlock($tags)
107 107
     {
108 108
         $parameters = collect($tags)
109
-            ->filter(function ($tag) {
109
+            ->filter(function($tag) {
110 110
                 return $tag instanceof Tag && $tag->getName() === 'bodyParam';
111 111
             })
112
-            ->mapWithKeys(function ($tag) {
112
+            ->mapWithKeys(function($tag) {
113 113
                 preg_match('/(.+?)\s+(.+?)\s+(required\s+)?(.+)/', $tag->getContent(), $content);
114 114
                 list($_, $name, $type, $required, $description) = $content;
115 115
                 $required = trim($required) == 'required' ? true : false;
@@ -135,7 +135,7 @@  discard block
 block discarded – undo
135 135
         $methods = $this->getMethods($route);
136 136
 
137 137
         // Split headers into key - value pairs
138
-        $headers = collect($headers)->map(function ($value) {
138
+        $headers = collect($headers)->map(function($value) {
139 139
             $split = explode(':', $value); // explode to get key + values
140 140
             $key = array_shift($split); // extract the key and keep the values in the array
141 141
             $value = implode(':', $split); // implode values into string again
@@ -159,8 +159,8 @@  discard block
 block discarded – undo
159 159
     {
160 160
         $uri = $this->getUri($route);
161 161
         foreach ($bindings as $model => $id) {
162
-            $uri = str_replace('{'.$model.'}', $id, $uri);
163
-            $uri = str_replace('{'.$model.'?}', $id, $uri);
162
+            $uri = str_replace('{' . $model . '}', $id, $uri);
163
+            $uri = str_replace('{' . $model . '?}', $id, $uri);
164 164
         }
165 165
 
166 166
         return $uri;
@@ -239,8 +239,8 @@  discard block
 block discarded – undo
239 239
         foreach ($headers as $name => $value) {
240 240
             $name = strtr(strtoupper($name), '-', '_');
241 241
 
242
-            if (! Str::startsWith($name, $prefix) && $name !== 'CONTENT_TYPE') {
243
-                $name = $prefix.$name;
242
+            if (!Str::startsWith($name, $prefix) && $name !== 'CONTENT_TYPE') {
243
+                $name = $prefix . $name;
244 244
             }
245 245
 
246 246
             $server[$name] = $value;
@@ -278,8 +278,8 @@  discard block
 block discarded – undo
278 278
     protected function getTransformerResponse($tags)
279 279
     {
280 280
         try {
281
-            $transFormerTags = array_filter($tags, function ($tag) {
282
-                if (! ($tag instanceof Tag)) {
281
+            $transFormerTags = array_filter($tags, function($tag) {
282
+                if (!($tag instanceof Tag)) {
283 283
                     return false;
284 284
                 }
285 285
 
@@ -290,8 +290,8 @@  discard block
 block discarded – undo
290 290
                 return false;
291 291
             }
292 292
 
293
-            $modelTag = array_first(array_filter($tags, function ($tag) {
294
-                if (! ($tag instanceof Tag)) {
293
+            $modelTag = array_first(array_filter($tags, function($tag) {
294
+                if (!($tag instanceof Tag)) {
295 295
                     return false;
296 296
                 }
297 297
 
@@ -299,7 +299,7 @@  discard block
 block discarded – undo
299 299
             }));
300 300
             $tag = \array_first($transFormerTags);
301 301
             $transformer = $tag->getContent();
302
-            if (! \class_exists($transformer)) {
302
+            if (!\class_exists($transformer)) {
303 303
                 // if we can't find the transformer we can't generate a response
304 304
                 return;
305 305
             }
@@ -314,7 +314,7 @@  discard block
 block discarded – undo
314 314
             }
315 315
             if (\is_null($type)) {
316 316
                 if ($parameter->hasType() &&
317
-                    ! $parameter->getType()->isBuiltin() &&
317
+                    !$parameter->getType()->isBuiltin() &&
318 318
                     \class_exists((string) $parameter->getType())) {
319 319
                     //we have a type
320 320
                     $type = (string) $parameter->getType();
@@ -367,7 +367,7 @@  discard block
 block discarded – undo
367 367
             // we have a response from the docblock ( @response )
368 368
             $response = $docblockResponse;
369 369
         }
370
-        if (! $response && ($transformerResponse = $this->getTransformerResponse($annotationTags))) {
370
+        if (!$response && ($transformerResponse = $this->getTransformerResponse($annotationTags))) {
371 371
             // we have a transformer response from the docblock ( @transformer || @transformercollection )
372 372
             $response = $transformerResponse;
373 373
         }
Please login to merge, or discard this patch.
src/ApiDocGeneratorServiceProvider.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -15,17 +15,17 @@
 block discarded – undo
15 15
      */
16 16
     public function boot()
17 17
     {
18
-        $this->loadViewsFrom(__DIR__.'/../resources/views/', 'apidoc');
18
+        $this->loadViewsFrom(__DIR__ . '/../resources/views/', 'apidoc');
19 19
 
20 20
         $this->publishes([
21
-            __DIR__.'/../resources/views' => app()->basePath().'/resources/views/vendor/apidoc',
21
+            __DIR__ . '/../resources/views' => app()->basePath() . '/resources/views/vendor/apidoc',
22 22
         ], 'views');
23 23
 
24 24
         $this->publishes([
25
-            __DIR__.'/../config/apidoc.php' => config_path('apidoc.php'),
25
+            __DIR__ . '/../config/apidoc.php' => config_path('apidoc.php'),
26 26
         ], 'config');
27 27
 
28
-        $this->mergeConfigFrom(__DIR__.'/../config/apidoc.php', 'apidoc');
28
+        $this->mergeConfigFrom(__DIR__ . '/../config/apidoc.php', 'apidoc');
29 29
 
30 30
         if ($this->app->runningInConsole()) {
31 31
             $this->commands([
Please login to merge, or discard this patch.
src/Commands/GenerateDocumentation.php 1 patch
Spacing   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
 
61 61
         $parsedRoutes = $this->processRoutes($generator, $routes);
62 62
         $parsedRoutes = collect($parsedRoutes)->groupBy('resource')
63
-            ->sort(function ($a, $b) {
63
+            ->sort(function($a, $b) {
64 64
                 return strcmp($a->first()['resource'], $b->first()['resource']);
65 65
             });
66 66
 
@@ -75,17 +75,17 @@  discard block
 block discarded – undo
75 75
     private function writeMarkdown($parsedRoutes)
76 76
     {
77 77
         $outputPath = config('apidoc.output');
78
-        $targetFile = $outputPath.DIRECTORY_SEPARATOR.'source'.DIRECTORY_SEPARATOR.'index.md';
79
-        $compareFile = $outputPath.DIRECTORY_SEPARATOR.'source'.DIRECTORY_SEPARATOR.'.compare.md';
80
-        $prependFile = $outputPath.DIRECTORY_SEPARATOR.'source'.DIRECTORY_SEPARATOR.'prepend.md';
81
-        $appendFile = $outputPath.DIRECTORY_SEPARATOR.'source'.DIRECTORY_SEPARATOR.'append.md';
78
+        $targetFile = $outputPath . DIRECTORY_SEPARATOR . 'source' . DIRECTORY_SEPARATOR . 'index.md';
79
+        $compareFile = $outputPath . DIRECTORY_SEPARATOR . 'source' . DIRECTORY_SEPARATOR . '.compare.md';
80
+        $prependFile = $outputPath . DIRECTORY_SEPARATOR . 'source' . DIRECTORY_SEPARATOR . 'prepend.md';
81
+        $appendFile = $outputPath . DIRECTORY_SEPARATOR . 'source' . DIRECTORY_SEPARATOR . 'append.md';
82 82
 
83 83
         $infoText = view('apidoc::partials.info')
84 84
             ->with('outputPath', ltrim($outputPath, 'public/'))
85 85
             ->with('showPostmanCollectionButton', config('apidoc.postman'));
86 86
 
87
-        $parsedRouteOutput = $parsedRoutes->map(function ($routeGroup) {
88
-            return $routeGroup->map(function ($route) {
87
+        $parsedRouteOutput = $parsedRoutes->map(function($routeGroup) {
88
+            return $routeGroup->map(function($route) {
89 89
                 $route['output'] = (string) view('apidoc::partials.route')->with('parsedRoute', $route)->render();
90 90
 
91 91
                 return $route;
@@ -105,16 +105,16 @@  discard block
 block discarded – undo
105 105
                 $frontmatter = trim($generatedFrontmatter[1], "\n");
106 106
             }
107 107
 
108
-            $parsedRouteOutput->transform(function ($routeGroup) use ($generatedDocumentation, $compareDocumentation) {
109
-                return $routeGroup->transform(function ($route) use ($generatedDocumentation, $compareDocumentation) {
110
-                    if (preg_match('/<!-- START_'.$route['id'].' -->(.*)<!-- END_'.$route['id'].' -->/is', $generatedDocumentation, $existingRouteDoc)) {
111
-                        $routeDocumentationChanged = (preg_match('/<!-- START_'.$route['id'].' -->(.*)<!-- END_'.$route['id'].' -->/is', $compareDocumentation, $lastDocWeGeneratedForThisRoute) && $lastDocWeGeneratedForThisRoute[1] !== $existingRouteDoc[1]);
108
+            $parsedRouteOutput->transform(function($routeGroup) use ($generatedDocumentation, $compareDocumentation) {
109
+                return $routeGroup->transform(function($route) use ($generatedDocumentation, $compareDocumentation) {
110
+                    if (preg_match('/<!-- START_' . $route['id'] . ' -->(.*)<!-- END_' . $route['id'] . ' -->/is', $generatedDocumentation, $existingRouteDoc)) {
111
+                        $routeDocumentationChanged = (preg_match('/<!-- START_' . $route['id'] . ' -->(.*)<!-- END_' . $route['id'] . ' -->/is', $compareDocumentation, $lastDocWeGeneratedForThisRoute) && $lastDocWeGeneratedForThisRoute[1] !== $existingRouteDoc[1]);
112 112
                         if ($routeDocumentationChanged === false || $this->option('force')) {
113 113
                             if ($routeDocumentationChanged) {
114
-                                $this->warn('Discarded manual changes for route ['.implode(',', $route['methods']).'] '.$route['uri']);
114
+                                $this->warn('Discarded manual changes for route [' . implode(',', $route['methods']) . '] ' . $route['uri']);
115 115
                             }
116 116
                         } else {
117
-                            $this->warn('Skipping modified route ['.implode(',', $route['methods']).'] '.$route['uri']);
117
+                            $this->warn('Skipping modified route [' . implode(',', $route['methods']) . '] ' . $route['uri']);
118 118
                             $route['modified_output'] = $existingRouteDoc[0];
119 119
                         }
120 120
                     }
@@ -125,9 +125,9 @@  discard block
 block discarded – undo
125 125
         }
126 126
 
127 127
         $prependFileContents = file_exists($prependFile)
128
-            ? file_get_contents($prependFile)."\n" : '';
128
+            ? file_get_contents($prependFile) . "\n" : '';
129 129
         $appendFileContents = file_exists($appendFile)
130
-            ? "\n".file_get_contents($appendFile) : '';
130
+            ? "\n" . file_get_contents($appendFile) : '';
131 131
 
132 132
         $documentarian = new Documentarian();
133 133
 
@@ -141,7 +141,7 @@  discard block
 block discarded – undo
141 141
             ->with('showPostmanCollectionButton', config('apidoc.postman'))
142 142
             ->with('parsedRoutes', $parsedRouteOutput);
143 143
 
144
-        if (! is_dir($outputPath)) {
144
+        if (!is_dir($outputPath)) {
145 145
             $documentarian->create($outputPath);
146 146
         }
147 147
 
@@ -161,18 +161,18 @@  discard block
 block discarded – undo
161 161
 
162 162
         file_put_contents($compareFile, $compareMarkdown);
163 163
 
164
-        $this->info('Wrote index.md to: '.$outputPath);
164
+        $this->info('Wrote index.md to: ' . $outputPath);
165 165
 
166 166
         $this->info('Generating API HTML code');
167 167
 
168 168
         $documentarian->generate($outputPath);
169 169
 
170
-        $this->info('Wrote HTML documentation to: '.$outputPath.'/index.html');
170
+        $this->info('Wrote HTML documentation to: ' . $outputPath . '/index.html');
171 171
 
172 172
         if (config('apidoc.postman')) {
173 173
             $this->info('Generating Postman collection');
174 174
 
175
-            file_put_contents($outputPath.DIRECTORY_SEPARATOR.'collection.json', $this->generatePostmanCollection($parsedRoutes));
175
+            file_put_contents($outputPath . DIRECTORY_SEPARATOR . 'collection.json', $this->generatePostmanCollection($parsedRoutes));
176 176
         }
177 177
     }
178 178
 
@@ -207,7 +207,7 @@  discard block
 block discarded – undo
207 207
      */
208 208
     private function isValidRoute(Route $route)
209 209
     {
210
-        return ! is_callable($route->getAction()['uses']) && ! is_null($route->getAction()['uses']);
210
+        return !is_callable($route->getAction()['uses']) && !is_null($route->getAction()['uses']);
211 211
     }
212 212
 
213 213
     /**
@@ -224,7 +224,7 @@  discard block
 block discarded – undo
224 224
             $phpdoc = new DocBlock($comment);
225 225
 
226 226
             return collect($phpdoc->getTags())
227
-                ->filter(function ($tag) use ($route) {
227
+                ->filter(function($tag) use ($route) {
228 228
                     return $tag->getName() === 'hideFromAPIDocumentation';
229 229
                 })
230 230
                 ->isEmpty();
Please login to merge, or discard this patch.