Skip to content

Commit 7d61142

Browse files
committed
Fix
1 parent 61599a7 commit 7d61142

File tree

3 files changed

+23
-21
lines changed

3 files changed

+23
-21
lines changed

src/RectorRule.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ public function getArgs($tag, $tagContent, $phpDocInfo)
261261
{
262262
$tagContent = trim($tagContent);
263263

264-
$removeEmptyKeys = function ($class, ...$extraData) use ($tagContent) {
264+
$parseAndRemoveEmptyKeys = function ($class, ...$extraData) use ($tagContent) {
265265
$parsed = (new $class($tagContent, ...$extraData))->parse();
266266
$arguments = [];
267267
foreach ($parsed as $key => $value) {
@@ -275,19 +275,19 @@ public function getArgs($tag, $tagContent, $phpDocInfo)
275275

276276
return match(strtolower($tag)) {
277277
'header' => explode(' ', $tagContent),
278-
'urlparam' => $removeEmptyKeys(UrlParamTagParser::class),
279-
'queryparam' => $removeEmptyKeys(QueryParamTagParser::class),
280-
'bodyparam' => $removeEmptyKeys(BodyParamTagParser::class),
281-
'responsefield' => $removeEmptyKeys(ResponseFieldTagParser::class),
278+
'urlparam' => $parseAndRemoveEmptyKeys(UrlParamTagParser::class),
279+
'queryparam' => $parseAndRemoveEmptyKeys(QueryParamTagParser::class),
280+
'bodyparam' => $parseAndRemoveEmptyKeys(BodyParamTagParser::class),
281+
'responsefield' => $parseAndRemoveEmptyKeys(ResponseFieldTagParser::class),
282282

283-
'response' => $removeEmptyKeys(ResponseTagParser::class),
284-
'responsefile' => $removeEmptyKeys(ResponseFileTagParser::class),
285-
'apiresource' => $removeEmptyKeys(ApiResourceTagParser::class, $phpDocInfo->getPhpDocNode()->getTags()),
286-
'apiresourcecollection' => $removeEmptyKeys(ApiResourceTagParser::class, $phpDocInfo->getPhpDocNode()->getTags(), true),
287-
'transformer' => $removeEmptyKeys(TransformerTagParser::class, $phpDocInfo->getPhpDocNode()->getTags()),
288-
'transformercollection' => $removeEmptyKeys(TransformerTagParser::class, $phpDocInfo->getPhpDocNode()->getTags(), true),
283+
'response' => $parseAndRemoveEmptyKeys(ResponseTagParser::class),
284+
'responsefile' => $parseAndRemoveEmptyKeys(ResponseFileTagParser::class),
285+
'apiresource' => $parseAndRemoveEmptyKeys(ApiResourceTagParser::class, $phpDocInfo->getPhpDocNode()->getTags()),
286+
'apiresourcecollection' => $parseAndRemoveEmptyKeys(ApiResourceTagParser::class, $phpDocInfo->getPhpDocNode()->getTags(), true),
287+
'transformer' => $parseAndRemoveEmptyKeys(TransformerTagParser::class, $phpDocInfo->getPhpDocNode()->getTags()),
288+
'transformercollection' => $parseAndRemoveEmptyKeys(TransformerTagParser::class, $phpDocInfo->getPhpDocNode()->getTags(), true),
289289

290-
'subgroup' => $removeEmptyKeys(SubgroupTagParser::class, $phpDocInfo->getPhpDocNode()->getTags()),
290+
'subgroup' => $parseAndRemoveEmptyKeys(SubgroupTagParser::class, $phpDocInfo->getPhpDocNode()->getTags()),
291291
};
292292
}
293293
}

src/TagParsers/TransformerTagParser.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,18 @@ public function parse()
3030

3131
$data = [
3232
$transformerClass,
33-
$model
3433
];
3534

35+
if (!empty($model)) {
36+
$data[] = $model;
37+
}
38+
3639
if (!empty($statusCode)) {
37-
$data[] = (int) $statusCode;
40+
if ($model) {
41+
$data[] = (int)$statusCode;
42+
} else {
43+
$data['status'] = (int)$statusCode;
44+
}
3845
}
3946

4047
if ($this->isCollection) {
@@ -74,11 +81,6 @@ private function getClassToBeTransformed(): array
7481
$states = $fields['states'] ? explode(',', $fields['states']) : [];
7582
$relations = $fields['with'] ? explode(',', $fields['with']) : [];
7683
$resourceKey = $fields['resourceKey'] ?? null;
77-
} else {
78-
$parameter = Arr::first($transformerMethod->getParameters());
79-
if ($parameter->hasType() && !$parameter->getType()->isBuiltin() && class_exists($parameter->getType()->getName())) {
80-
$type = $parameter->getType()->getName();
81-
}
8284
}
8385

8486
return [$type, $states, $relations, $resourceKey];

src/TagParsers/UrlParamTagParser.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ public function parse()
2121
// @urlParam user_id The ID of the user.
2222

2323
// We match on all the possible types for URL parameters. It's a limited range, so no biggie.
24-
preg_match('/(\w+?)\s+((int|integer|string|float|double|number)\s+)?(required\s+)?([\s\S]*)/', $tagContent, $content);
24+
preg_match('/(\w+?)\s+((int|integer|string|float|double|number)\s+)?(required\s+)?([\s\S]*)/', $this->tagContent, $content);
2525
if (empty($content)) {
2626
// This means only name was supplied
27-
$name = $tagContent;
27+
$name = $this->tagContent;
2828
$required = false;
2929
$description = '';
3030
$type = null;

0 commit comments

Comments
 (0)