Completed
Pull Request — master (#429)
by Phan
02:30
created
src/Commands/GenerateDocumentation.php 1 patch
Spacing   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -56,7 +56,7 @@  discard block
 block discarded – undo
56 56
         $generator = new Generator();
57 57
         $parsedRoutes = $this->processRoutes($generator, $routes);
58 58
         $parsedRoutes = collect($parsedRoutes)->groupBy('group')
59
-            ->sort(function ($a, $b) {
59
+            ->sort(function($a, $b) {
60 60
                 return strcmp($a->first()['group'], $b->first()['group']);
61 61
             });
62 62
 
@@ -71,17 +71,17 @@  discard block
 block discarded – undo
71 71
     private function writeMarkdown($parsedRoutes)
72 72
     {
73 73
         $outputPath = config('apidoc.output');
74
-        $targetFile = $outputPath.DIRECTORY_SEPARATOR.'source'.DIRECTORY_SEPARATOR.'index.md';
75
-        $compareFile = $outputPath.DIRECTORY_SEPARATOR.'source'.DIRECTORY_SEPARATOR.'.compare.md';
76
-        $prependFile = $outputPath.DIRECTORY_SEPARATOR.'source'.DIRECTORY_SEPARATOR.'prepend.md';
77
-        $appendFile = $outputPath.DIRECTORY_SEPARATOR.'source'.DIRECTORY_SEPARATOR.'append.md';
74
+        $targetFile = $outputPath . DIRECTORY_SEPARATOR . 'source' . DIRECTORY_SEPARATOR . 'index.md';
75
+        $compareFile = $outputPath . DIRECTORY_SEPARATOR . 'source' . DIRECTORY_SEPARATOR . '.compare.md';
76
+        $prependFile = $outputPath . DIRECTORY_SEPARATOR . 'source' . DIRECTORY_SEPARATOR . 'prepend.md';
77
+        $appendFile = $outputPath . DIRECTORY_SEPARATOR . 'source' . DIRECTORY_SEPARATOR . 'append.md';
78 78
 
79 79
         $infoText = view('apidoc::partials.info')
80 80
             ->with('outputPath', ltrim($outputPath, 'public/'))
81 81
             ->with('showPostmanCollectionButton', config('apidoc.postman'));
82 82
 
83
-        $parsedRouteOutput = $parsedRoutes->map(function ($routeGroup) {
84
-            return $routeGroup->map(function ($route) {
83
+        $parsedRouteOutput = $parsedRoutes->map(function($routeGroup) {
84
+            return $routeGroup->map(function($route) {
85 85
                 $route['output'] = (string) view('apidoc::partials.route')->with('route', $route)->render();
86 86
 
87 87
                 return $route;
@@ -101,16 +101,16 @@  discard block
 block discarded – undo
101 101
                 $frontmatter = trim($generatedFrontmatter[1], "\n");
102 102
             }
103 103
 
104
-            $parsedRouteOutput->transform(function ($routeGroup) use ($generatedDocumentation, $compareDocumentation) {
105
-                return $routeGroup->transform(function ($route) use ($generatedDocumentation, $compareDocumentation) {
106
-                    if (preg_match('/<!-- START_'.$route['id'].' -->(.*)<!-- END_'.$route['id'].' -->/is', $generatedDocumentation, $existingRouteDoc)) {
107
-                        $routeDocumentationChanged = (preg_match('/<!-- START_'.$route['id'].' -->(.*)<!-- END_'.$route['id'].' -->/is', $compareDocumentation, $lastDocWeGeneratedForThisRoute) && $lastDocWeGeneratedForThisRoute[1] !== $existingRouteDoc[1]);
104
+            $parsedRouteOutput->transform(function($routeGroup) use ($generatedDocumentation, $compareDocumentation) {
105
+                return $routeGroup->transform(function($route) use ($generatedDocumentation, $compareDocumentation) {
106
+                    if (preg_match('/<!-- START_' . $route['id'] . ' -->(.*)<!-- END_' . $route['id'] . ' -->/is', $generatedDocumentation, $existingRouteDoc)) {
107
+                        $routeDocumentationChanged = (preg_match('/<!-- START_' . $route['id'] . ' -->(.*)<!-- END_' . $route['id'] . ' -->/is', $compareDocumentation, $lastDocWeGeneratedForThisRoute) && $lastDocWeGeneratedForThisRoute[1] !== $existingRouteDoc[1]);
108 108
                         if ($routeDocumentationChanged === false || $this->option('force')) {
109 109
                             if ($routeDocumentationChanged) {
110
-                                $this->warn('Discarded manual changes for route ['.implode(',', $route['methods']).'] '.$route['uri']);
110
+                                $this->warn('Discarded manual changes for route [' . implode(',', $route['methods']) . '] ' . $route['uri']);
111 111
                             }
112 112
                         } else {
113
-                            $this->warn('Skipping modified route ['.implode(',', $route['methods']).'] '.$route['uri']);
113
+                            $this->warn('Skipping modified route [' . implode(',', $route['methods']) . '] ' . $route['uri']);
114 114
                             $route['modified_output'] = $existingRouteDoc[0];
115 115
                         }
116 116
                     }
@@ -121,9 +121,9 @@  discard block
 block discarded – undo
121 121
         }
122 122
 
123 123
         $prependFileContents = file_exists($prependFile)
124
-            ? file_get_contents($prependFile)."\n" : '';
124
+            ? file_get_contents($prependFile) . "\n" : '';
125 125
         $appendFileContents = file_exists($appendFile)
126
-            ? "\n".file_get_contents($appendFile) : '';
126
+            ? "\n" . file_get_contents($appendFile) : '';
127 127
 
128 128
         $documentarian = new Documentarian();
129 129
 
@@ -137,7 +137,7 @@  discard block
 block discarded – undo
137 137
             ->with('showPostmanCollectionButton', config('apidoc.postman'))
138 138
             ->with('parsedRoutes', $parsedRouteOutput);
139 139
 
140
-        if (! is_dir($outputPath)) {
140
+        if (!is_dir($outputPath)) {
141 141
             $documentarian->create($outputPath);
142 142
         }
143 143
 
@@ -157,24 +157,24 @@  discard block
 block discarded – undo
157 157
 
158 158
         file_put_contents($compareFile, $compareMarkdown);
159 159
 
160
-        $this->info('Wrote index.md to: '.$outputPath);
160
+        $this->info('Wrote index.md to: ' . $outputPath);
161 161
 
162 162
         $this->info('Generating API HTML code');
163 163
 
164 164
         $documentarian->generate($outputPath);
165 165
 
166
-        $this->info('Wrote HTML documentation to: '.$outputPath.'/index.html');
166
+        $this->info('Wrote HTML documentation to: ' . $outputPath . '/index.html');
167 167
 
168 168
         if (config('apidoc.postman')) {
169 169
             $this->info('Generating Postman collection');
170 170
 
171
-            file_put_contents($outputPath.DIRECTORY_SEPARATOR.'collection.json', $this->generatePostmanCollection($parsedRoutes));
171
+            file_put_contents($outputPath . DIRECTORY_SEPARATOR . 'collection.json', $this->generatePostmanCollection($parsedRoutes));
172 172
         }
173 173
 
174 174
         if ($logo = config('apidoc.logo')) {
175 175
             copy(
176 176
                 $logo,
177
-                $outputPath.DIRECTORY_SEPARATOR.'images'.DIRECTORY_SEPARATOR.'logo.png'
177
+                $outputPath . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'logo.png'
178 178
             );
179 179
         }
180 180
     }
@@ -193,9 +193,9 @@  discard block
 block discarded – undo
193 193
             /** @var Route $route */
194 194
             if ($this->isValidRoute($route) && $this->isRouteVisibleForDocumentation($route->getAction()['uses'])) {
195 195
                 $parsedRoutes[] = $generator->processRoute($route, $routeItem['apply']);
196
-                $this->info('Processed route: ['.implode(',', $generator->getMethods($route)).'] '.$generator->getUri($route));
196
+                $this->info('Processed route: [' . implode(',', $generator->getMethods($route)) . '] ' . $generator->getUri($route));
197 197
             } else {
198
-                $this->warn('Skipping route: ['.implode(',', $generator->getMethods($route)).'] '.$generator->getUri($route));
198
+                $this->warn('Skipping route: [' . implode(',', $generator->getMethods($route)) . '] ' . $generator->getUri($route));
199 199
             }
200 200
         }
201 201
 
@@ -209,7 +209,7 @@  discard block
 block discarded – undo
209 209
      */
210 210
     private function isValidRoute(Route $route)
211 211
     {
212
-        return ! is_callable($route->getAction()['uses']) && ! is_null($route->getAction()['uses']);
212
+        return !is_callable($route->getAction()['uses']) && !is_null($route->getAction()['uses']);
213 213
     }
214 214
 
215 215
     /**
@@ -224,7 +224,7 @@  discard block
 block discarded – undo
224 224
         list($class, $method) = explode('@', $route);
225 225
         $reflection = new ReflectionClass($class);
226 226
 
227
-        if (! $reflection->hasMethod($method)) {
227
+        if (!$reflection->hasMethod($method)) {
228 228
             return false;
229 229
         }
230 230
 
@@ -234,7 +234,7 @@  discard block
 block discarded – undo
234 234
             $phpdoc = new DocBlock($comment);
235 235
 
236 236
             return collect($phpdoc->getTags())
237
-                ->filter(function ($tag) use ($route) {
237
+                ->filter(function($tag) use ($route) {
238 238
                     return $tag->getName() === 'hideFromAPIDocumentation';
239 239
                 })
240 240
                 ->isEmpty();
Please login to merge, or discard this patch.