Completed
Push — master ( b2d17b...894367 )
by Marcel
02:35
created
src/Mpociot/ApiDoc/Commands/GenerateDocumentation.php 1 patch
Spacing   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -67,7 +67,7 @@  discard block
 block discarded – undo
67 67
 
68 68
         $this->setUserToBeImpersonated($this->option('actAsUserId'));
69 69
 
70
-        if ($routePrefix === null && ! count($allowedRoutes)) {
70
+        if ($routePrefix === null && !count($allowedRoutes)) {
71 71
             $this->error('You must provide either a route prefix or a route to generate the documentation.');
72 72
 
73 73
             return false;
@@ -91,16 +91,16 @@  discard block
 block discarded – undo
91 91
     private function writeMarkdown($parsedRoutes)
92 92
     {
93 93
         $outputPath = $this->option('output');
94
-        $targetFile = $outputPath.DIRECTORY_SEPARATOR.'source'.DIRECTORY_SEPARATOR.'index.md';
95
-        $compareFile = $outputPath.DIRECTORY_SEPARATOR.'source'.DIRECTORY_SEPARATOR.'.compare.md';
94
+        $targetFile = $outputPath . DIRECTORY_SEPARATOR . 'source' . DIRECTORY_SEPARATOR . 'index.md';
95
+        $compareFile = $outputPath . DIRECTORY_SEPARATOR . 'source' . DIRECTORY_SEPARATOR . '.compare.md';
96 96
 
97 97
         $infoText = view('apidoc::partials.info')
98 98
             ->with('outputPath', $this->option('output'))
99
-            ->with('showPostmanCollectionButton', ! $this->option('noPostmanCollection'));
99
+            ->with('showPostmanCollectionButton', !$this->option('noPostmanCollection'));
100 100
 
101
-        $parsedRouteOutput = $parsedRoutes->map(function ($routeGroup) {
102
-            return $routeGroup->map(function($route){
103
-                $route['output'] = (string)view('apidoc::partials.route')->with('parsedRoute', $route);
101
+        $parsedRouteOutput = $parsedRoutes->map(function($routeGroup) {
102
+            return $routeGroup->map(function($route) {
103
+                $route['output'] = (string) view('apidoc::partials.route')->with('parsedRoute', $route);
104 104
                 return $route;
105 105
             });
106 106
         });
@@ -115,23 +115,23 @@  discard block
 block discarded – undo
115 115
             $compareDocumentation = file_get_contents($compareFile);
116 116
 
117 117
             if (preg_match("/<!-- START_INFO -->(.*)<!-- END_INFO -->/is", $generatedDocumentation, $generatedInfoText)) {
118
-                $infoText = trim($generatedInfoText[1],"\n");
118
+                $infoText = trim($generatedInfoText[1], "\n");
119 119
             }
120 120
 
121 121
             if (preg_match("/---(.*)---\\s<!-- START_INFO -->/is", $generatedDocumentation, $generatedFrontmatter)) {
122
-                $frontmatter = trim($generatedFrontmatter[1],"\n");
122
+                $frontmatter = trim($generatedFrontmatter[1], "\n");
123 123
             }
124 124
 
125
-            $parsedRouteOutput->transform(function ($routeGroup) use($generatedDocumentation, $compareDocumentation) {
125
+            $parsedRouteOutput->transform(function($routeGroup) use($generatedDocumentation, $compareDocumentation) {
126 126
                 return $routeGroup->transform(function($route) use($generatedDocumentation, $compareDocumentation) {
127
-                    if (preg_match("/<!-- START_".$route['id']." -->(.*)<!-- END_".$route['id']." -->/is", $generatedDocumentation, $routeMatch)) {
128
-                        $routeDocumentationChanged = (preg_match("/<!-- START_".$route['id']." -->(.*)<!-- END_".$route['id']." -->/is", $compareDocumentation, $compareMatch) && $compareMatch[1] !== $routeMatch[1]);
129
-                        if ($routeDocumentationChanged === false ||  $this->option('force')) {
127
+                    if (preg_match("/<!-- START_" . $route['id'] . " -->(.*)<!-- END_" . $route['id'] . " -->/is", $generatedDocumentation, $routeMatch)) {
128
+                        $routeDocumentationChanged = (preg_match("/<!-- START_" . $route['id'] . " -->(.*)<!-- END_" . $route['id'] . " -->/is", $compareDocumentation, $compareMatch) && $compareMatch[1] !== $routeMatch[1]);
129
+                        if ($routeDocumentationChanged === false || $this->option('force')) {
130 130
                             if ($routeDocumentationChanged) {
131
-                                $this->warn('Discarded manual changes for route ['.implode(',', $route['methods']).'] '.$route['uri']);
131
+                                $this->warn('Discarded manual changes for route [' . implode(',', $route['methods']) . '] ' . $route['uri']);
132 132
                             }
133 133
                         } else {
134
-                            $this->warn('Skipping modified route ['.implode(',', $route['methods']).'] '.$route['uri']);
134
+                            $this->warn('Skipping modified route [' . implode(',', $route['methods']) . '] ' . $route['uri']);
135 135
                             $route['modified_output'] = $routeMatch[0];
136 136
                         }
137 137
                     }
@@ -147,10 +147,10 @@  discard block
 block discarded – undo
147 147
             ->with('frontmatter', $frontmatter)
148 148
             ->with('infoText', $infoText)
149 149
             ->with('outputPath', $this->option('output'))
150
-            ->with('showPostmanCollectionButton', ! $this->option('noPostmanCollection'))
150
+            ->with('showPostmanCollectionButton', !$this->option('noPostmanCollection'))
151 151
             ->with('parsedRoutes', $parsedRouteOutput);
152 152
 
153
-        if (! is_dir($outputPath)) {
153
+        if (!is_dir($outputPath)) {
154 154
             $documentarian->create($outputPath);
155 155
         }
156 156
 
@@ -163,24 +163,24 @@  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 169
         file_put_contents($compareFile, $compareMarkdown);
170 170
 
171
-        $this->info('Wrote index.md to: '.$outputPath);
171
+        $this->info('Wrote index.md to: ' . $outputPath);
172 172
 
173 173
         $this->info('Generating API HTML code');
174 174
 
175 175
         $documentarian->generate($outputPath);
176 176
 
177
-        $this->info('Wrote HTML documentation to: '.$outputPath.'/public/index.html');
177
+        $this->info('Wrote HTML documentation to: ' . $outputPath . '/public/index.html');
178 178
 
179 179
 
180 180
         if ($this->option('noPostmanCollection') !== true) {
181 181
             $this->info('Generating Postman collection');
182 182
 
183
-            file_put_contents($outputPath.DIRECTORY_SEPARATOR.'collection.json', $this->generatePostmanCollection($parsedRoutes));
183
+            file_put_contents($outputPath . DIRECTORY_SEPARATOR . 'collection.json', $this->generatePostmanCollection($parsedRoutes));
184 184
         }
185 185
     }
186 186
 
@@ -208,7 +208,7 @@  discard block
 block discarded – undo
208 208
      */
209 209
     private function setUserToBeImpersonated($actAs)
210 210
     {
211
-        if (! empty($actAs)) {
211
+        if (!empty($actAs)) {
212 212
             if (version_compare($this->laravel->version(), '5.2.0', '<')) {
213 213
                 $userModel = config('auth.model');
214 214
                 $user = $userModel::find($actAs);
@@ -250,9 +250,9 @@  discard block
 block discarded – undo
250 250
             if (in_array($route->getName(), $allowedRoutes) || str_is($routePrefix, $route->getUri())) {
251 251
                 if ($this->isValidRoute($route) && $this->isRouteVisibleForDocumentation($route->getAction()['uses'])) {
252 252
                     $parsedRoutes[] = $generator->processRoute($route, $bindings, $withResponse);
253
-                    $this->info('Processed route: '.$route->getUri());
253
+                    $this->info('Processed route: ' . $route->getUri());
254 254
                 } else {
255
-                    $this->warn('Skipping route: '.$route->getUri());
255
+                    $this->warn('Skipping route: ' . $route->getUri());
256 256
                 }
257 257
             }
258 258
         }
@@ -276,7 +276,7 @@  discard block
 block discarded – undo
276 276
         foreach ($routes as $route) {
277 277
             if (empty($allowedRoutes) || in_array($route->getName(), $allowedRoutes) || str_is($routePrefix, $route->uri())) {
278 278
                 $parsedRoutes[] = $generator->processRoute($route, $bindings, $withResponse);
279
-                $this->info('Processed route: '.$route->uri());
279
+                $this->info('Processed route: ' . $route->uri());
280 280
             }
281 281
         }
282 282
 
@@ -290,7 +290,7 @@  discard block
 block discarded – undo
290 290
      */
291 291
     private function isValidRoute($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
     /**
Please login to merge, or discard this patch.