Completed
Pull Request — master (#690)
by
unknown
02:14 queued 52s
created
src/Extracting/Strategies/Responses/UseTransformerTags.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -141,7 +141,7 @@
 block discarded – undo
141 141
     /**
142 142
      * @param string $type
143 143
      *
144
-     * @return Model|object
144
+     * @return string
145 145
      */
146 146
     protected function instantiateTransformerModel(string $type)
147 147
     {
Please login to merge, or discard this patch.
Unused Use Statements   -1 removed lines patch added patch discarded remove patch
@@ -3,7 +3,6 @@
 block discarded – undo
3 3
 namespace Mpociot\ApiDoc\Extracting\Strategies\Responses;
4 4
 
5 5
 use Exception;
6
-use Illuminate\Database\Eloquent\Model;
7 6
 use Illuminate\Database\Eloquent\Model as IlluminateModel;
8 7
 use Illuminate\Routing\Route;
9 8
 use Illuminate\Support\Arr;
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -65,7 +65,7 @@  discard block
 block discarded – undo
65 65
 
66 66
             $fractal = new Manager();
67 67
 
68
-            if (! is_null(config('apidoc.fractal.serializer'))) {
68
+            if (!is_null(config('apidoc.fractal.serializer'))) {
69 69
                 $fractal->setSerializer(app(config('apidoc.fractal.serializer')));
70 70
             }
71 71
 
@@ -84,7 +84,7 @@  discard block
 block discarded – undo
84 84
                 ],
85 85
             ];
86 86
         } catch (Exception $e) {
87
-            echo 'Exception thrown when fetching transformer response for ['.implode(',', $route->methods)."] {$route->uri}.\n";
87
+            echo 'Exception thrown when fetching transformer response for [' . implode(',', $route->methods) . "] {$route->uri}.\n";
88 88
             if (Flags::$shouldBeVerbose) {
89 89
                 Utils::dumpException($e);
90 90
             } else {
@@ -120,7 +120,7 @@  discard block
 block discarded – undo
120 120
      */
121 121
     private function getClassToBeTransformed(array $tags, ReflectionFunctionAbstract $transformerMethod): string
122 122
     {
123
-        $modelTag = Arr::first(array_filter($tags, function ($tag) {
123
+        $modelTag = Arr::first(array_filter($tags, function($tag) {
124 124
             return ($tag instanceof Tag) && strtolower($tag->getName()) == 'transformermodel';
125 125
         }));
126 126
 
@@ -129,7 +129,7 @@  discard block
 block discarded – undo
129 129
             $type = $modelTag->getContent();
130 130
         } else {
131 131
             $parameter = Arr::first($transformerMethod->getParameters());
132
-            if ($parameter->hasType() && ! $parameter->getType()->isBuiltin() && class_exists($parameter->getType()->getName())) {
132
+            if ($parameter->hasType() && !$parameter->getType()->isBuiltin() && class_exists($parameter->getType()->getName())) {
133 133
                 // Ladies and gentlemen, we have a type!
134 134
                 $type = $parameter->getType()->getName();
135 135
             }
@@ -190,7 +190,7 @@  discard block
 block discarded – undo
190 190
     private function getTransformerTag(array $tags)
191 191
     {
192 192
         $transformerTags = array_values(
193
-            array_filter($tags, function ($tag) {
193
+            array_filter($tags, function($tag) {
194 194
                 return ($tag instanceof Tag) && in_array(strtolower($tag->getName()), ['transformer', 'transformercollection']);
195 195
             })
196 196
         );
Please login to merge, or discard this patch.
src/Commands/RebuildDocumentation.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -15,13 +15,13 @@
 block discarded – undo
15 15
     public function handle()
16 16
     {
17 17
         $sourceOutputPath = 'resources/docs/source';
18
-        if (! is_dir($sourceOutputPath)) {
19
-            $this->error('There is no existing documentation available at '.$sourceOutputPath.'.');
18
+        if (!is_dir($sourceOutputPath)) {
19
+            $this->error('There is no existing documentation available at ' . $sourceOutputPath . '.');
20 20
 
21 21
             return false;
22 22
         }
23 23
 
24
-        $this->info('Rebuilding API documentation from '.$sourceOutputPath.'/index.md');
24
+        $this->info('Rebuilding API documentation from ' . $sourceOutputPath . '/index.md');
25 25
 
26 26
         $writer = new Writer($this, new DocumentationConfig(config('apidoc')));
27 27
         $writer->writeHtmlDocs();
Please login to merge, or discard this patch.
src/Writing/Writer.php 1 patch
Spacing   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -91,8 +91,8 @@  discard block
 block discarded – undo
91 91
      */
92 92
     public function writeMarkdownAndSourceFiles(Collection $parsedRoutes)
93 93
     {
94
-        $targetFile = $this->sourceOutputPath.'/source/index.md';
95
-        $compareFile = $this->sourceOutputPath.'/source/.compare.md';
94
+        $targetFile = $this->sourceOutputPath . '/source/index.md';
95
+        $compareFile = $this->sourceOutputPath . '/source/.compare.md';
96 96
 
97 97
         $infoText = view('apidoc::partials.info')
98 98
             ->with('outputPath', 'docs')
@@ -114,16 +114,16 @@  discard block
 block discarded – undo
114 114
             $generatedDocumentation = file_get_contents($targetFile);
115 115
             $compareDocumentation = file_get_contents($compareFile);
116 116
 
117
-            $parsedRouteOutput->transform(function (Collection $routeGroup) use ($generatedDocumentation, $compareDocumentation) {
118
-                return $routeGroup->transform(function (array $route) use ($generatedDocumentation, $compareDocumentation) {
119
-                    if (preg_match('/<!-- START_'.$route['id'].' -->(.*)<!-- END_'.$route['id'].' -->/is', $generatedDocumentation, $existingRouteDoc)) {
120
-                        $routeDocumentationChanged = (preg_match('/<!-- START_'.$route['id'].' -->(.*)<!-- END_'.$route['id'].' -->/is', $compareDocumentation, $lastDocWeGeneratedForThisRoute) && $lastDocWeGeneratedForThisRoute[1] !== $existingRouteDoc[1]);
117
+            $parsedRouteOutput->transform(function(Collection $routeGroup) use ($generatedDocumentation, $compareDocumentation) {
118
+                return $routeGroup->transform(function(array $route) use ($generatedDocumentation, $compareDocumentation) {
119
+                    if (preg_match('/<!-- START_' . $route['id'] . ' -->(.*)<!-- END_' . $route['id'] . ' -->/is', $generatedDocumentation, $existingRouteDoc)) {
120
+                        $routeDocumentationChanged = (preg_match('/<!-- START_' . $route['id'] . ' -->(.*)<!-- END_' . $route['id'] . ' -->/is', $compareDocumentation, $lastDocWeGeneratedForThisRoute) && $lastDocWeGeneratedForThisRoute[1] !== $existingRouteDoc[1]);
121 121
                         if ($routeDocumentationChanged === false || $this->forceIt) {
122 122
                             if ($routeDocumentationChanged) {
123
-                                $this->output->warn('Discarded manual changes for route ['.implode(',', $route['methods']).'] '.$route['uri']);
123
+                                $this->output->warn('Discarded manual changes for route [' . implode(',', $route['methods']) . '] ' . $route['uri']);
124 124
                             }
125 125
                         } else {
126
-                            $this->output->warn('Skipping modified route ['.implode(',', $route['methods']).'] '.$route['uri']);
126
+                            $this->output->warn('Skipping modified route [' . implode(',', $route['methods']) . '] ' . $route['uri']);
127 127
                             $route['modified_output'] = $existingRouteDoc[0];
128 128
                         }
129 129
                     }
@@ -146,9 +146,9 @@  discard block
 block discarded – undo
146 146
             ->with('showPostmanCollectionButton', $this->shouldGeneratePostmanCollection)
147 147
             ->with('parsedRoutes', $parsedRouteOutput);
148 148
 
149
-        $this->output->info('Writing index.md and source files to: '.$this->sourceOutputPath);
149
+        $this->output->info('Writing index.md and source files to: ' . $this->sourceOutputPath);
150 150
 
151
-        if (! is_dir($this->sourceOutputPath)) {
151
+        if (!is_dir($this->sourceOutputPath)) {
152 152
             $documentarian = new Documentarian();
153 153
             $documentarian->create($this->sourceOutputPath);
154 154
         }
@@ -169,19 +169,19 @@  discard block
 block discarded – undo
169 169
 
170 170
         file_put_contents($compareFile, $compareMarkdown);
171 171
 
172
-        $this->output->info('Wrote index.md and source files to: '.$this->sourceOutputPath);
172
+        $this->output->info('Wrote index.md and source files to: ' . $this->sourceOutputPath);
173 173
     }
174 174
 
175 175
     public function generateMarkdownOutputForEachRoute(Collection $parsedRoutes, array $settings): Collection
176 176
     {
177
-        $parsedRouteOutput = $parsedRoutes->map(function (Collection $routeGroup) use ($settings) {
178
-            return $routeGroup->map(function (array $route) use ($settings) {
179
-                if (count($route['cleanBodyParameters']) && ! isset($route['headers']['Content-Type'])) {
177
+        $parsedRouteOutput = $parsedRoutes->map(function(Collection $routeGroup) use ($settings) {
178
+            return $routeGroup->map(function(array $route) use ($settings) {
179
+                if (count($route['cleanBodyParameters']) && !isset($route['headers']['Content-Type'])) {
180 180
                     // Set content type if the user forgot to set it
181 181
                     $route['headers']['Content-Type'] = 'application/json';
182 182
                 }
183 183
 
184
-                $hasRequestOptions = ! empty($route['headers']) || ! empty($route['cleanQueryParameters']) || ! empty($route['cleanBodyParameters']);
184
+                $hasRequestOptions = !empty($route['headers']) || !empty($route['cleanQueryParameters']) || !empty($route['cleanBodyParameters']);
185 185
                 $route['output'] = (string) view('apidoc::partials.route')
186 186
                     ->with('hasRequestOptions', $hasRequestOptions)
187 187
                     ->with('route', $route)
@@ -230,18 +230,18 @@  discard block
 block discarded – undo
230 230
 
231 231
     protected function getMarkdownToPrepend(): string
232 232
     {
233
-        $prependFile = $this->sourceOutputPath.'/source/prepend.md';
233
+        $prependFile = $this->sourceOutputPath . '/source/prepend.md';
234 234
         $prependFileContents = file_exists($prependFile)
235
-            ? file_get_contents($prependFile)."\n" : '';
235
+            ? file_get_contents($prependFile) . "\n" : '';
236 236
 
237 237
         return $prependFileContents;
238 238
     }
239 239
 
240 240
     protected function getMarkdownToAppend(): string
241 241
     {
242
-        $appendFile = $this->sourceOutputPath.'/source/append.md';
242
+        $appendFile = $this->sourceOutputPath . '/source/append.md';
243 243
         $appendFileContents = file_exists($appendFile)
244
-            ? "\n".file_get_contents($appendFile) : '';
244
+            ? "\n" . file_get_contents($appendFile) : '';
245 245
 
246 246
         return $appendFileContents;
247 247
     }
@@ -249,7 +249,7 @@  discard block
 block discarded – undo
249 249
     protected function copyAssetsFromSourceFolderToPublicFolder(): void
250 250
     {
251 251
         $publicPath = 'public/docs';
252
-        if (! is_dir($publicPath)) {
252
+        if (!is_dir($publicPath)) {
253 253
             mkdir($publicPath, 0777, true);
254 254
             mkdir("{$publicPath}/css");
255 255
             mkdir("{$publicPath}/js");
@@ -272,7 +272,7 @@  discard block
 block discarded – undo
272 272
             rename("{$this->sourceOutputPath}/index.html", "{$this->outputPath}/index.html");
273 273
         } else {
274 274
             // Move output to resources/views
275
-            if (! is_dir($this->outputPath)) {
275
+            if (!is_dir($this->outputPath)) {
276 276
                 mkdir($this->outputPath);
277 277
             }
278 278
             rename("{$this->sourceOutputPath}/index.html", "$this->outputPath/index.blade.php");
Please login to merge, or discard this patch.
src/Matching/RouteMatcher/Match.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -49,7 +49,7 @@  discard block
 block discarded – undo
49 49
      */
50 50
     public function offsetExists($offset)
51 51
     {
52
-        return is_callable([$this, 'get'.ucfirst($offset)]);
52
+        return is_callable([$this, 'get' . ucfirst($offset)]);
53 53
     }
54 54
 
55 55
     /**
@@ -57,7 +57,7 @@  discard block
 block discarded – undo
57 57
      */
58 58
     public function offsetGet($offset)
59 59
     {
60
-        return call_user_func([$this, 'get'.ucfirst($offset)]);
60
+        return call_user_func([$this, 'get' . ucfirst($offset)]);
61 61
     }
62 62
 
63 63
     /**
Please login to merge, or discard this patch.
src/Writing/PostmanCollectionWriter.php 1 patch
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -47,12 +47,12 @@  discard block
 block discarded – undo
47 47
         $collection = [
48 48
             'variables' => [],
49 49
             'info' => [
50
-                'name' => config('apidoc.postman.name') ?: config('app.name').' API',
50
+                'name' => config('apidoc.postman.name') ?: config('app.name') . ' API',
51 51
                 '_postman_id' => Uuid::uuid4()->toString(),
52 52
                 'description' => config('apidoc.postman.description') ?: '',
53 53
                 'schema' => 'https://schema.getpostman.com/json/collection/v2.0.0/collection.json',
54 54
             ],
55
-            'item' => $this->routeGroups->map(function (Collection $routes, $groupName) {
55
+            'item' => $this->routeGroups->map(function(Collection $routes, $groupName) {
56 56
                 return [
57 57
                     'name' => $groupName,
58 58
                     'description' => $routes->first()['metadata']['groupDescription'],
@@ -61,7 +61,7 @@  discard block
 block discarded – undo
61 61
             })->values()->toArray(),
62 62
         ];
63 63
 
64
-        if (! empty($this->auth)) {
64
+        if (!empty($this->auth)) {
65 65
             $collection['auth'] = $this->auth;
66 66
         }
67 67
 
@@ -96,7 +96,7 @@  discard block
 block discarded – undo
96 96
 
97 97
         // Exclude authentication headers if they're handled by Postman auth
98 98
         $authHeader = $this->getAuthHeader();
99
-        if (! empty($authHeader)) {
99
+        if (!empty($authHeader)) {
100 100
             $headers = $headers->except($authHeader);
101 101
         }
102 102
 
@@ -104,7 +104,7 @@  discard block
 block discarded – undo
104 104
             ->union([
105 105
                 'Accept' => 'application/json',
106 106
             ])
107
-            ->map(function ($value, $header) {
107
+            ->map(function($value, $header) {
108 108
                 return [
109 109
                     'key' => $header,
110 110
                     'value' => $value,
@@ -118,8 +118,8 @@  discard block
 block discarded – undo
118 118
     {
119 119
         // URL Parameters are collected by the `UrlParameters` strategies, but only make sense if they're in the route
120 120
         // definition. Filter out any URL parameters that don't appear in the URL.
121
-        $urlParams = collect($route['urlParameters'])->filter(function ($_, $key) use ($route) {
122
-            return Str::contains($route['uri'], '{'.$key.'}');
121
+        $urlParams = collect($route['urlParameters'])->filter(function($_, $key) use ($route) {
122
+            return Str::contains($route['uri'], '{' . $key . '}');
123 123
         });
124 124
 
125 125
         /** @var Collection $queryParams */
@@ -127,16 +127,16 @@  discard block
 block discarded – undo
127 127
             'protocol' => $this->protocol,
128 128
             'host' => $this->baseUrl,
129 129
             // Substitute laravel/symfony query params ({example}) to Postman style, prefixed with a colon
130
-            'path' => preg_replace_callback('/\/{(\w+)\??}(?=\/|$)/', function ($matches) {
131
-                return '/:'.$matches[1];
130
+            'path' => preg_replace_callback('/\/{(\w+)\??}(?=\/|$)/', function($matches) {
131
+                return '/:' . $matches[1];
132 132
             }, $route['uri']),
133
-            'query' => collect($route['queryParameters'])->map(function ($parameter, $key) {
133
+            'query' => collect($route['queryParameters'])->map(function($parameter, $key) {
134 134
                 return [
135 135
                     'key' => $key,
136 136
                     'value' => urlencode($parameter['value']),
137 137
                     'description' => $parameter['description'],
138 138
                     // Default query params to disabled if they aren't required and have empty values
139
-                    'disabled' => ! $parameter['required'] && empty($parameter['value']),
139
+                    'disabled' => !$parameter['required'] && empty($parameter['value']),
140 140
                 ];
141 141
             })->values()->toArray(),
142 142
         ];
@@ -147,7 +147,7 @@  discard block
 block discarded – undo
147 147
             return $base;
148 148
         }
149 149
 
150
-        $base['variable'] = $urlParams->map(function ($parameter, $key) {
150
+        $base['variable'] = $urlParams->map(function($parameter, $key) {
151 151
             return [
152 152
                 'id' => $key,
153 153
                 'key' => $key,
@@ -162,7 +162,7 @@  discard block
 block discarded – undo
162 162
     protected function getAuthHeader()
163 163
     {
164 164
         $auth = $this->auth;
165
-        if (empty($auth) || ! is_string($auth['type'] ?? null)) {
165
+        if (empty($auth) || !is_string($auth['type'] ?? null)) {
166 166
             return null;
167 167
         }
168 168
 
Please login to merge, or discard this patch.
src/ApiDoc.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -18,7 +18,7 @@
 block discarded – undo
18 18
         Route::prefix($path)
19 19
             ->namespace('\Mpociot\ApiDoc\Http')
20 20
             ->middleware(static::middleware())
21
-            ->group(function () {
21
+            ->group(function() {
22 22
                 Route::get('/', 'Controller@html')->name('apidoc');
23 23
                 Route::get('.json', 'Controller@json')->name('apidoc.json');
24 24
             });
Please login to merge, or discard this patch.
routes/laravel.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -7,7 +7,7 @@
 block discarded – undo
7 7
 
8 8
 Route::namespace('\Mpociot\ApiDoc\Http')
9 9
     ->middleware($middleware)
10
-    ->group(function () use ($prefix) {
10
+    ->group(function() use ($prefix) {
11 11
         Route::get($prefix, 'Controller@html')->name('apidoc');
12 12
         Route::get("$prefix.json", 'Controller@json')->name('apidoc.json');
13 13
     });
Please login to merge, or discard this patch.
src/ApiDocGeneratorServiceProvider.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -16,17 +16,17 @@  discard block
 block discarded – undo
16 16
      */
17 17
     public function boot()
18 18
     {
19
-        $this->loadViewsFrom(__DIR__.'/../resources/views/', 'apidoc');
19
+        $this->loadViewsFrom(__DIR__ . '/../resources/views/', 'apidoc');
20 20
 
21 21
         $this->publishes([
22
-            __DIR__.'/../resources/views' => $this->app->basePath('resources/views/vendor/apidoc'),
22
+            __DIR__ . '/../resources/views' => $this->app->basePath('resources/views/vendor/apidoc'),
23 23
         ], 'apidoc-views');
24 24
 
25 25
         $this->publishes([
26
-            __DIR__.'/../config/apidoc.php' => $this->app->configPath('apidoc.php'),
26
+            __DIR__ . '/../config/apidoc.php' => $this->app->configPath('apidoc.php'),
27 27
         ], 'apidoc-config');
28 28
 
29
-        $this->mergeConfigFrom(__DIR__.'/../config/apidoc.php', 'apidoc');
29
+        $this->mergeConfigFrom(__DIR__ . '/../config/apidoc.php', 'apidoc');
30 30
 
31 31
         $this->bootRoutes();
32 32
 
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
             config('apidoc.laravel.autoload', false)
61 61
         ) {
62 62
             $this->loadRoutesFrom(
63
-                __DIR__.'/../routes/laravel.php'
63
+                __DIR__ . '/../routes/laravel.php'
64 64
             );
65 65
         }
66 66
     }
Please login to merge, or discard this patch.
src/Extracting/Strategies/Responses/ResponseCalls.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -31,7 +31,7 @@  discard block
 block discarded – undo
31 31
     public function __invoke(Route $route, \ReflectionClass $controller, \ReflectionFunctionAbstract $method, array $routeRules, array $context = [])
32 32
     {
33 33
         $rulesToApply = $routeRules['response_calls'] ?? [];
34
-        if (! $this->shouldMakeApiCall($route, $rulesToApply, $context)) {
34
+        if (!$this->shouldMakeApiCall($route, $rulesToApply, $context)) {
35 35
             return null;
36 36
         }
37 37
 
@@ -52,7 +52,7 @@  discard block
 block discarded – undo
52 52
                 ],
53 53
             ];
54 54
         } catch (\Exception $e) {
55
-            echo 'Exception thrown during response call for ['.implode(',', $route->methods)."] {$route->uri}.\n";
55
+            echo 'Exception thrown during response call for [' . implode(',', $route->methods) . "] {$route->uri}.\n";
56 56
             if (Flags::$shouldBeVerbose) {
57 57
                 Utils::dumpException($e);
58 58
             } else {
@@ -194,14 +194,14 @@  discard block
 block discarded – undo
194 194
         // set URL and query parameters
195 195
         $uri = $request->getRequestUri();
196 196
         $query = $request->getQueryString();
197
-        if (! empty($query)) {
197
+        if (!empty($query)) {
198 198
             $uri .= "?$query";
199 199
         }
200 200
         $response = call_user_func_array([$dispatcher, strtolower($request->method())], [$uri]);
201 201
 
202 202
         // the response from the Dingo dispatcher is the 'raw' response from the controller,
203 203
         // so we have to ensure it's JSON first
204
-        if (! $response instanceof Response) {
204
+        if (!$response instanceof Response) {
205 205
             $response = response()->json($response);
206 206
         }
207 207
 
@@ -329,7 +329,7 @@  discard block
 block discarded – undo
329 329
         }
330 330
 
331 331
         // Don't attempt a response call if there are already successful responses
332
-        $successResponses = collect($context['responses'])->filter(function ($response) {
332
+        $successResponses = collect($context['responses'])->filter(function($response) {
333 333
             return ((string) $response['status'])[0] == '2';
334 334
         })->count();
335 335
         if ($successResponses) {
@@ -365,8 +365,8 @@  discard block
 block discarded – undo
365 365
         $prefix = 'HTTP_';
366 366
         foreach ($headers as $name => $value) {
367 367
             $name = strtr(strtoupper($name), '-', '_');
368
-            if (! Str::startsWith($name, $prefix) && $name !== 'CONTENT_TYPE') {
369
-                $name = $prefix.$name;
368
+            if (!Str::startsWith($name, $prefix) && $name !== 'CONTENT_TYPE') {
369
+                $name = $prefix . $name;
370 370
             }
371 371
             $server[$name] = $value;
372 372
         }
Please login to merge, or discard this patch.