Completed
Pull Request — master (#681)
by
unknown
13:51
created
src/Tools/Utils.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -53,7 +53,7 @@  discard block
 block discarded – undo
53 53
     public static function replaceUrlParameterPlaceholdersWithValues(string $uri, array $urlParameters)
54 54
     {
55 55
         $matches = preg_match_all('/{.+?}/i', $uri, $parameterPaths);
56
-        if (! $matches) {
56
+        if (!$matches) {
57 57
             return $uri;
58 58
         }
59 59
 
@@ -88,7 +88,7 @@  discard block
 block discarded – undo
88 88
 
89 89
     public static function deleteDirectoryAndContents($dir)
90 90
     {
91
-        $adapter = new Local(realpath(__DIR__.'/../../'));
91
+        $adapter = new Local(realpath(__DIR__ . '/../../'));
92 92
         $fs = new Filesystem($adapter);
93 93
         $fs->deleteDir($dir);
94 94
     }
@@ -101,7 +101,7 @@  discard block
 block discarded – undo
101 101
         $result = '';
102 102
         $padWith = str_repeat(' ', $indentationLevel);
103 103
         foreach ($split as $index => $line) {
104
-            $result .= ($index == 0 ? '' : "\n$padWith").$line;
104
+            $result .= ($index == 0 ? '' : "\n$padWith") . $line;
105 105
         }
106 106
 
107 107
         return $result;
Please login to merge, or discard this patch.
src/Extracting/Strategies/Responses/UseResponseFileTag.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -44,7 +44,7 @@  discard block
 block discarded – undo
44 44
     {
45 45
         // Avoid "holes" in the keys of the filtered array, by using array_values on the filtered array
46 46
         $responseFileTags = array_values(
47
-            array_filter($tags, function ($tag) {
47
+            array_filter($tags, function($tag) {
48 48
                 return $tag instanceof Tag && strtolower($tag->getName()) === 'responsefile';
49 49
             })
50 50
         );
@@ -53,16 +53,16 @@  discard block
 block discarded – undo
53 53
             return null;
54 54
         }
55 55
 
56
-        $responses = array_map(function (Tag $responseFileTag) {
56
+        $responses = array_map(function(Tag $responseFileTag) {
57 57
             preg_match('/^(\d{3})?\s?([\S]*[\s]*?)(\{.*\})?$/', $responseFileTag->getContent(), $result);
58 58
             $relativeFilePath = trim($result[2]);
59 59
             $filePath = storage_path($relativeFilePath);
60
-            if (! file_exists($filePath)) {
61
-                throw new \Exception('@responseFile '.$relativeFilePath.' does not exist');
60
+            if (!file_exists($filePath)) {
61
+                throw new \Exception('@responseFile ' . $relativeFilePath . ' does not exist');
62 62
             }
63 63
             $status = $result[1] ?: 200;
64 64
             $content = $result[2] ? file_get_contents($filePath, true) : '{}';
65
-            $json = ! empty($result[3]) ? str_replace("'", '"', $result[3]) : '{}';
65
+            $json = !empty($result[3]) ? str_replace("'", '"', $result[3]) : '{}';
66 66
             $merged = array_merge(json_decode($content, true), json_decode($json, true));
67 67
 
68 68
             return ['content' => json_encode($merged), 'status' => (int) $status];
Please login to merge, or discard this patch.
src/Extracting/Generator.php 2 patches
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -56,7 +56,7 @@  discard block
 block discarded – undo
56 56
         $method = $controller->getMethod($methodName);
57 57
 
58 58
         $parsedRoute = [
59
-            'id' => md5($this->getUri($route).':'.implode($this->getMethods($route))),
59
+            'id' => md5($this->getUri($route) . ':' . implode($this->getMethods($route))),
60 60
             'methods' => $this->getMethods($route),
61 61
             'uri' => $this->getUri($route),
62 62
         ];
@@ -81,7 +81,7 @@  discard block
 block discarded – undo
81 81
 
82 82
         $responses = $this->fetchResponses($controller, $method, $route, $routeRules, $parsedRoute);
83 83
         $parsedRoute['responses'] = $responses;
84
-        $parsedRoute['showresponse'] = ! empty($responses);
84
+        $parsedRoute['showresponse'] = !empty($responses);
85 85
 
86 86
         return $parsedRoute;
87 87
     }
@@ -118,7 +118,7 @@  discard block
 block discarded – undo
118 118
     {
119 119
         $responses = $this->iterateThroughStrategies('responses', $context, [$route, $controller, $method, $rulesToApply]);
120 120
         if (count($responses)) {
121
-            return array_filter($responses, function ($response) {
121
+            return array_filter($responses, function($response) {
122 122
                 return $response['content'] != null;
123 123
             });
124 124
         }
@@ -168,7 +168,7 @@  discard block
 block discarded – undo
168 168
             $strategyArgs = $arguments;
169 169
             $strategyArgs[] = $context;
170 170
             $results = $strategy(...$strategyArgs);
171
-            if (! is_null($results)) {
171
+            if (!is_null($results)) {
172 172
                 foreach ($results as $index => $item) {
173 173
                     if ($stage == 'responses') {
174 174
                         // Responses are additive
@@ -180,7 +180,7 @@  discard block
 block discarded – undo
180 180
                     // and also allows values to be overwritten
181 181
 
182 182
                     // Don't allow overwriting if an empty value is trying to replace a set one
183
-                    if (! in_array($context[$stage], [null, ''], true) && in_array($item, [null, ''], true)) {
183
+                    if (!in_array($context[$stage], [null, ''], true) && in_array($item, [null, ''], true)) {
184 184
                         continue;
185 185
                     } else {
186 186
                         $context[$stage][$index] = $item;
@@ -205,8 +205,8 @@  discard block
 block discarded – undo
205 205
         $values = [];
206 206
 
207 207
         // Remove params which have no examples.
208
-        $params = array_filter($params, function ($details) {
209
-            return ! is_null($details['value']);
208
+        $params = array_filter($params, function($details) {
209
+            return !is_null($details['value']);
210 210
         });
211 211
 
212 212
         foreach ($params as $paramName => $details) {
Please login to merge, or discard this patch.
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -24,7 +24,7 @@
 block discarded – undo
24 24
     /**
25 25
      * @param Route $route
26 26
      *
27
-     * @return mixed
27
+     * @return string
28 28
      */
29 29
     public function getUri(Route $route)
30 30
     {
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/Commands/GenerateDocumentation.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -80,7 +80,7 @@  discard block
 block discarded – undo
80 80
 
81 81
         $groupedRoutes = collect($parsedRoutes)
82 82
             ->groupBy('metadata.groupName')
83
-            ->sortBy(static function ($group) {
83
+            ->sortBy(static function($group) {
84 84
                 /* @var $group Collection */
85 85
                 return $group->first()['metadata']['groupName'];
86 86
             }, SORT_NATURAL);
@@ -108,7 +108,7 @@  discard block
 block discarded – undo
108 108
             $routeMethods = implode(',', $generator->getMethods($route));
109 109
             $routePath = $generator->getUri($route);
110 110
 
111
-            if (! $this->isValidRoute($route) || ! $this->isRouteVisibleForDocumentation($route->getAction())) {
111
+            if (!$this->isValidRoute($route) || !$this->isRouteVisibleForDocumentation($route->getAction())) {
112 112
                 $this->warn(sprintf($messageFormat, 'Skipping', $routeMethods, $routePath));
113 113
                 continue;
114 114
             }
@@ -117,7 +117,7 @@  discard block
 block discarded – undo
117 117
                 $parsedRoutes[] = $generator->processRoute($route, $routeItem->getRules());
118 118
                 $this->info(sprintf($messageFormat, 'Processed', $routeMethods, $routePath));
119 119
             } catch (\Exception $exception) {
120
-                $this->warn(sprintf($messageFormat, 'Skipping', $routeMethods, $routePath).' - '.$exception->getMessage());
120
+                $this->warn(sprintf($messageFormat, 'Skipping', $routeMethods, $routePath) . ' - ' . $exception->getMessage());
121 121
             }
122 122
         }
123 123
 
@@ -136,7 +136,7 @@  discard block
 block discarded – undo
136 136
             $action = implode('@', $action);
137 137
         }
138 138
 
139
-        return ! is_callable($action) && ! is_null($action);
139
+        return !is_callable($action) && !is_null($action);
140 140
     }
141 141
 
142 142
     /**
@@ -151,7 +151,7 @@  discard block
 block discarded – undo
151 151
         list($class, $method) = Utils::getRouteClassAndMethodNames($action);
152 152
         $reflection = new ReflectionClass($class);
153 153
 
154
-        if (! $reflection->hasMethod($method)) {
154
+        if (!$reflection->hasMethod($method)) {
155 155
             return false;
156 156
         }
157 157
 
@@ -161,7 +161,7 @@  discard block
 block discarded – undo
161 161
             $phpdoc = new DocBlock($comment);
162 162
 
163 163
             return collect($phpdoc->getTags())
164
-                ->filter(function ($tag) {
164
+                ->filter(function($tag) {
165 165
                     return $tag->getName() === 'hideFromAPIDocumentation';
166 166
                 })
167 167
                 ->isEmpty();
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/Extracting/Strategies/Responses/UseTransformerTags.php 3 patches
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, ReflectionMethod $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.
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -47,7 +47,7 @@  discard block
 block discarded – undo
47 47
     /**
48 48
      * Get a response from the transformer tags.
49 49
      *
50
-     * @param array $tags
50
+     * @param Tag[] $tags
51 51
      * @param Route $route
52 52
      *
53 53
      * @return array|null
@@ -145,7 +145,7 @@  discard block
 block discarded – undo
145 145
     /**
146 146
      * @param string $type
147 147
      *
148
-     * @return Model|object
148
+     * @return string
149 149
      */
150 150
     protected function instantiateTransformerModel(string $type)
151 151
     {
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.