Skip to content

Commit 6cf8818

Browse files
committed
Rename to $pathParameters
1 parent 1c4688b commit 6cf8818

File tree

2 files changed

+29
-28
lines changed

2 files changed

+29
-28
lines changed

src/LaravelRequestDocs.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ public function getControllersInfo(array $onlyMethods): Collection
189189
$controllerName = (new ReflectionClass($controllerFullPath))->getShortName();
190190
}
191191

192-
$paths = $this->routePath->getPaths($route);
192+
$pathParameters = $this->routePath->getPaths($route);
193193

194194
$doc = new Doc(
195195
$route->uri,
@@ -199,7 +199,7 @@ public function getControllersInfo(array $onlyMethods): Collection
199199
config('request-docs.hide_meta_data') ? '' : $controllerFullPath,
200200
config('request-docs.hide_meta_data') ? '' : $method,
201201
'',
202-
$paths,
202+
$pathParameters,
203203
[],
204204
'',
205205
);

src/RoutePath.php

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -18,31 +18,32 @@ class RoutePath
1818
];
1919

2020
/**
21+
* @return array<string, string>
2122
* @throws \ReflectionException
2223
*/
2324
public function getPaths(Route $route): array
2425
{
25-
$paths = $this->initAllParametersWithStringType($route);
26+
$pathParameters = $this->initAllParametersWithStringType($route);
2627

27-
$paths = $this->setParameterType($route, $paths);
28+
$pathParameters = $this->setParameterType($route, $pathParameters);
2829

29-
$paths = $this->setOptional($route, $paths);
30+
$pathParameters = $this->setOptional($route, $pathParameters);
3031

31-
$paths = $this->mutateKeyNameWithBindingField($route, $paths);
32+
$pathParameters = $this->mutateKeyNameWithBindingField($route, $pathParameters);
3233

33-
return $this->setRegex($route, $paths);
34+
return $this->setRegex($route, $pathParameters);
3435
}
3536

3637
/**
3738
* Set route path parameter type.
38-
* This method will overwrite `$paths` type with the real types found from route declaration.
39+
* This method will overwrite `$pathParameters` type with the real types found from route declaration.
3940
*
4041
* @param \Illuminate\Routing\Route $route
41-
* @param array<string, string> $paths
42+
* @param array<string, string> $pathParameters
4243
* @return array<string, string>
4344
* @throws \ReflectionException
4445
*/
45-
private function setParameterType(Route $route, array $paths): array
46+
private function setParameterType(Route $route, array $pathParameters): array
4647
{
4748
$bindableParameters = $this->getBindableParameters($route);
4849

@@ -56,7 +57,7 @@ private function setParameterType(Route $route, array $paths): array
5657

5758
// For builtin type, always get the type from reflection parameter.
5859
if ($bindableParameter['class'] === null) {
59-
$paths[$parameterName] = $this->getParameterType($bindableParameter['parameter']);
60+
$pathParameters[$parameterName] = $this->getParameterType($bindableParameter['parameter']);
6061
continue;
6162
}
6263

@@ -84,10 +85,10 @@ private function setParameterType(Route $route, array $paths): array
8485

8586
// Try set type from model key type.
8687
if ($model->getKeyName() === $model->getRouteKeyName()) {
87-
$paths[$parameterName] = self::TYPE_MAP[$model->getKeyType()] ?? $model->getKeyType();
88+
$pathParameters[$parameterName] = self::TYPE_MAP[$model->getKeyType()] ?? $model->getKeyType();
8889
}
8990
}
90-
return $paths;
91+
return $pathParameters;
9192
}
9293

9394
private function getOptionalParameterNames(string $uri): array
@@ -139,39 +140,39 @@ private function getBindableParameters(Route $route): array
139140

140141
/**
141142
* @param \Illuminate\Routing\Route $route
142-
* @param array<string, string> $paths
143+
* @param array<string, string> $pathParameters
143144
* @return array<string, string>
144145
*/
145-
private function setOptional(Route $route, array $paths): array
146+
private function setOptional(Route $route, array $pathParameters): array
146147
{
147148
$optionalParameters = $this->getOptionalParameterNames($route->uri);
148149

149-
foreach ($paths as $parameter => $rule) {
150+
foreach ($pathParameters as $parameter => $rule) {
150151
if (in_array($parameter, $optionalParameters)) {
151-
$paths[$parameter] .= '|nullable';
152+
$pathParameters[$parameter] .= '|nullable';
152153
continue;
153154
}
154155

155-
$paths[$parameter] .= '|required';
156+
$pathParameters[$parameter] .= '|required';
156157
}
157-
return $paths;
158+
return $pathParameters;
158159
}
159160

160161
/**
161162
* @param \Illuminate\Routing\Route $route
162-
* @param array<string, string> $paths
163+
* @param array<string, string> $pathParameters
163164
* @return array<string, string>
164165
*/
165-
private function setRegex(Route $route, array $paths): array
166+
private function setRegex(Route $route, array $pathParameters): array
166167
{
167-
foreach ($paths as $parameter => $rule) {
168+
foreach ($pathParameters as $parameter => $rule) {
168169
if (!isset($route->wheres[$parameter])) {
169170
continue;
170171
}
171-
$paths[$parameter] .= '|regex:/' . $route->wheres[$parameter] . '/';
172+
$pathParameters[$parameter] .= '|regex:/' . $route->wheres[$parameter] . '/';
172173
}
173174

174-
return $paths;
175+
return $pathParameters;
175176
}
176177

177178
/**
@@ -210,22 +211,22 @@ private function getParameterType(ReflectionParameter $methodParameter): string
210211

211212
/**
212213
* @param \Illuminate\Routing\Route $route
213-
* @param array<string, string> $paths
214+
* @param array<string, string> $pathParameters
214215
* @return array<string, string>
215216
*/
216-
private function mutateKeyNameWithBindingField(Route $route, array $paths): array
217+
private function mutateKeyNameWithBindingField(Route $route, array $pathParameters): array
217218
{
218219
$mutatedPath = [];
219220

220221
foreach ($route->parameterNames() as $name) {
221222
$bindingName = $route->bindingFieldFor($name);
222223

223224
if ($bindingName === null) {
224-
$mutatedPath[$name] = $paths[$name];
225+
$mutatedPath[$name] = $pathParameters[$name];
225226
continue;
226227
}
227228

228-
$mutatedPath["$name:$bindingName"] = $paths[$name];
229+
$mutatedPath["$name:$bindingName"] = $pathParameters[$name];
229230
}
230231

231232
return $mutatedPath;

0 commit comments

Comments
 (0)