Completed
Pull Request — master (#439)
by
unknown
01:27
created
src/Commands/GenerateDocumentation.php 1 patch
Spacing   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -58,7 +58,7 @@  discard block
 block discarded – undo
58 58
         $generator = new Generator();
59 59
         $parsedRoutes = $this->processRoutes($generator, $routes);
60 60
         $parsedRoutes = collect($parsedRoutes)->groupBy('group')
61
-            ->sortBy(static function ($group) {
61
+            ->sortBy(static function($group) {
62 62
                 /* @var $group Collection */
63 63
                 return $group->first()['group'];
64 64
             }, SORT_NATURAL);
@@ -74,17 +74,17 @@  discard block
 block discarded – undo
74 74
     private function writeMarkdown($parsedRoutes)
75 75
     {
76 76
         $outputPath = config('apidoc.output');
77
-        $targetFile = $outputPath.DIRECTORY_SEPARATOR.'source'.DIRECTORY_SEPARATOR.'index.md';
78
-        $compareFile = $outputPath.DIRECTORY_SEPARATOR.'source'.DIRECTORY_SEPARATOR.'.compare.md';
79
-        $prependFile = $outputPath.DIRECTORY_SEPARATOR.'source'.DIRECTORY_SEPARATOR.'prepend.md';
80
-        $appendFile = $outputPath.DIRECTORY_SEPARATOR.'source'.DIRECTORY_SEPARATOR.'append.md';
77
+        $targetFile = $outputPath . DIRECTORY_SEPARATOR . 'source' . DIRECTORY_SEPARATOR . 'index.md';
78
+        $compareFile = $outputPath . DIRECTORY_SEPARATOR . 'source' . DIRECTORY_SEPARATOR . '.compare.md';
79
+        $prependFile = $outputPath . DIRECTORY_SEPARATOR . 'source' . DIRECTORY_SEPARATOR . 'prepend.md';
80
+        $appendFile = $outputPath . DIRECTORY_SEPARATOR . 'source' . DIRECTORY_SEPARATOR . 'append.md';
81 81
 
82 82
         $infoText = view('apidoc::partials.info')
83 83
             ->with('outputPath', ltrim($outputPath, 'public/'))
84 84
             ->with('showPostmanCollectionButton', config('apidoc.postman'));
85 85
 
86
-        $parsedRouteOutput = $parsedRoutes->map(function ($routeGroup) {
87
-            return $routeGroup->map(function ($route) {
86
+        $parsedRouteOutput = $parsedRoutes->map(function($routeGroup) {
87
+            return $routeGroup->map(function($route) {
88 88
                 $route['output'] = (string) view('apidoc::partials.route')->with('route', $route)->render();
89 89
 
90 90
                 return $route;
@@ -104,16 +104,16 @@  discard block
 block discarded – undo
104 104
                 $frontmatter = trim($generatedFrontmatter[1], "\n");
105 105
             }
106 106
 
107
-            $parsedRouteOutput->transform(function ($routeGroup) use ($generatedDocumentation, $compareDocumentation) {
108
-                return $routeGroup->transform(function ($route) use ($generatedDocumentation, $compareDocumentation) {
109
-                    if (preg_match('/<!-- START_'.$route['id'].' -->(.*)<!-- END_'.$route['id'].' -->/is', $generatedDocumentation, $existingRouteDoc)) {
110
-                        $routeDocumentationChanged = (preg_match('/<!-- START_'.$route['id'].' -->(.*)<!-- END_'.$route['id'].' -->/is', $compareDocumentation, $lastDocWeGeneratedForThisRoute) && $lastDocWeGeneratedForThisRoute[1] !== $existingRouteDoc[1]);
107
+            $parsedRouteOutput->transform(function($routeGroup) use ($generatedDocumentation, $compareDocumentation) {
108
+                return $routeGroup->transform(function($route) use ($generatedDocumentation, $compareDocumentation) {
109
+                    if (preg_match('/<!-- START_' . $route['id'] . ' -->(.*)<!-- END_' . $route['id'] . ' -->/is', $generatedDocumentation, $existingRouteDoc)) {
110
+                        $routeDocumentationChanged = (preg_match('/<!-- START_' . $route['id'] . ' -->(.*)<!-- END_' . $route['id'] . ' -->/is', $compareDocumentation, $lastDocWeGeneratedForThisRoute) && $lastDocWeGeneratedForThisRoute[1] !== $existingRouteDoc[1]);
111 111
                         if ($routeDocumentationChanged === false || $this->option('force')) {
112 112
                             if ($routeDocumentationChanged) {
113
-                                $this->warn('Discarded manual changes for route ['.implode(',', $route['methods']).'] '.$route['uri']);
113
+                                $this->warn('Discarded manual changes for route [' . implode(',', $route['methods']) . '] ' . $route['uri']);
114 114
                             }
115 115
                         } else {
116
-                            $this->warn('Skipping modified route ['.implode(',', $route['methods']).'] '.$route['uri']);
116
+                            $this->warn('Skipping modified route [' . implode(',', $route['methods']) . '] ' . $route['uri']);
117 117
                             $route['modified_output'] = $existingRouteDoc[0];
118 118
                         }
119 119
                     }
@@ -124,9 +124,9 @@  discard block
 block discarded – undo
124 124
         }
125 125
 
126 126
         $prependFileContents = file_exists($prependFile)
127
-            ? file_get_contents($prependFile)."\n" : '';
127
+            ? file_get_contents($prependFile) . "\n" : '';
128 128
         $appendFileContents = file_exists($appendFile)
129
-            ? "\n".file_get_contents($appendFile) : '';
129
+            ? "\n" . file_get_contents($appendFile) : '';
130 130
 
131 131
         $documentarian = new Documentarian();
132 132
 
@@ -140,7 +140,7 @@  discard block
 block discarded – undo
140 140
             ->with('showPostmanCollectionButton', config('apidoc.postman'))
141 141
             ->with('parsedRoutes', $parsedRouteOutput);
142 142
 
143
-        if (! is_dir($outputPath)) {
143
+        if (!is_dir($outputPath)) {
144 144
             $documentarian->create($outputPath);
145 145
         }
146 146
 
@@ -160,24 +160,24 @@  discard block
 block discarded – undo
160 160
 
161 161
         file_put_contents($compareFile, $compareMarkdown);
162 162
 
163
-        $this->info('Wrote index.md to: '.$outputPath);
163
+        $this->info('Wrote index.md to: ' . $outputPath);
164 164
 
165 165
         $this->info('Generating API HTML code');
166 166
 
167 167
         $documentarian->generate($outputPath);
168 168
 
169
-        $this->info('Wrote HTML documentation to: '.$outputPath.'/index.html');
169
+        $this->info('Wrote HTML documentation to: ' . $outputPath . '/index.html');
170 170
 
171 171
         if (config('apidoc.postman')) {
172 172
             $this->info('Generating Postman collection');
173 173
 
174
-            file_put_contents($outputPath.DIRECTORY_SEPARATOR.'collection.json', $this->generatePostmanCollection($parsedRoutes));
174
+            file_put_contents($outputPath . DIRECTORY_SEPARATOR . 'collection.json', $this->generatePostmanCollection($parsedRoutes));
175 175
         }
176 176
 
177 177
         if ($logo = config('apidoc.logo')) {
178 178
             copy(
179 179
                 $logo,
180
-                $outputPath.DIRECTORY_SEPARATOR.'images'.DIRECTORY_SEPARATOR.'logo.png'
180
+                $outputPath . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'logo.png'
181 181
             );
182 182
         }
183 183
     }
@@ -196,9 +196,9 @@  discard block
 block discarded – undo
196 196
             /** @var Route $route */
197 197
             if ($this->isValidRoute($route) && $this->isRouteVisibleForDocumentation($route)) {
198 198
                 $parsedRoutes[] = $generator->processRoute($route, $routeItem['apply']);
199
-                $this->info('Processed route: ['.implode(',', $generator->getMethods($route)).'] '.$generator->getUri($route));
199
+                $this->info('Processed route: [' . implode(',', $generator->getMethods($route)) . '] ' . $generator->getUri($route));
200 200
             } else {
201
-                $this->warn('Skipping route: ['.implode(',', $generator->getMethods($route)).'] '.$generator->getUri($route));
201
+                $this->warn('Skipping route: [' . implode(',', $generator->getMethods($route)) . '] ' . $generator->getUri($route));
202 202
             }
203 203
         }
204 204
 
@@ -212,7 +212,7 @@  discard block
 block discarded – undo
212 212
      */
213 213
     private function isValidRoute(Route $route)
214 214
     {
215
-        return ! is_callable($route->getAction()['uses']) && ! is_null($route->getAction()['uses']);
215
+        return !is_callable($route->getAction()['uses']) && !is_null($route->getAction()['uses']);
216 216
     }
217 217
 
218 218
     /**
@@ -227,7 +227,7 @@  discard block
 block discarded – undo
227 227
         list($class, $method) = explode('@', $route->getAction()['uses']);
228 228
         $reflection = new ReflectionClass($class);
229 229
 
230
-        if (! $reflection->hasMethod($method)) {
230
+        if (!$reflection->hasMethod($method)) {
231 231
             return false;
232 232
         }
233 233
 
@@ -242,10 +242,10 @@  discard block
 block discarded – undo
242 242
         $routeTags = $route->getAction('tags');
243 243
 
244 244
         if ($routeTags) {
245
-            if (! is_array($routeTags)) {
245
+            if (!is_array($routeTags)) {
246 246
                 $routeTags = [$routeTags];
247 247
             }
248
-            if (! $this->skipRouteWithTags($routeTags, $allowedTags, $disallowedTags)) {
248
+            if (!$this->skipRouteWithTags($routeTags, $allowedTags, $disallowedTags)) {
249 249
                 return true;
250 250
             }
251 251
         }
@@ -253,12 +253,12 @@  discard block
 block discarded – undo
253 253
         if ($comment) {
254 254
             $phpdoc = new DocBlock($comment);
255 255
 
256
-            if (count($allowedTags) && ! $phpdoc->hasTag('tags')) {
256
+            if (count($allowedTags) && !$phpdoc->hasTag('tags')) {
257 257
                 return false;
258 258
             }
259 259
 
260 260
             return collect($phpdoc->getTags())
261
-                ->filter(function ($tag) use ($allowedTags, $disallowedTags) {
261
+                ->filter(function($tag) use ($allowedTags, $disallowedTags) {
262 262
                     if ((count($allowedTags) || count($disallowedTags)) &&
263 263
                         $tag->getName() == 'tags') {
264 264
                         $tags = explode(' ', $tag->getContent());
@@ -280,7 +280,7 @@  discard block
 block discarded – undo
280 280
         $containedAllowedTags = array_intersect($tags, $allowedTags);
281 281
         $containedDisallowedTags = array_intersect($tags, $disallowedTags);
282 282
 
283
-        return ! count($containedAllowedTags) || count($containedDisallowedTags);
283
+        return !count($containedAllowedTags) || count($containedDisallowedTags);
284 284
     }
285 285
 
286 286
     /**
Please login to merge, or discard this patch.