Skip to content

Commit da2c52f

Browse files
Merge pull request rakutentech#31 from nimah79/patch-1
Refactor sortDocs
2 parents 0d9a868 + 34d5414 commit da2c52f

File tree

1 file changed

+12
-23
lines changed

1 file changed

+12
-23
lines changed

src/LaravelRequestDocs.php

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -46,29 +46,18 @@ public function sortDocs(array $docs, $sortBy = 'default'): array
4646
return $docs;
4747
}
4848
$sorted = [];
49-
foreach ($docs as $key => $doc) {
50-
if (in_array('GET', $doc['methods'])) {
51-
$sorted[] = $doc;
52-
}
53-
}
54-
foreach ($docs as $key => $doc) {
55-
if (in_array('POST', $doc['methods'])) {
56-
$sorted[] = $doc;
57-
}
58-
}
59-
foreach ($docs as $key => $doc) {
60-
if (in_array('PUT', $doc['methods'])) {
61-
$sorted[] = $doc;
62-
}
63-
}
64-
foreach ($docs as $key => $doc) {
65-
if (in_array('PATCH', $doc['methods'])) {
66-
$sorted[] = $doc;
67-
}
68-
}
69-
foreach ($docs as $key => $doc) {
70-
if (in_array('DELETE', $doc['methods'])) {
71-
$sorted[] = $doc;
49+
$methods = [
50+
'GET',
51+
'POST',
52+
'PUT',
53+
'PATCH',
54+
'DELETE',
55+
];
56+
foreach ($methods as $method) {
57+
foreach ($docs as $key => $doc) {
58+
if (in_array($method, $doc['methods'])) {
59+
$sorted[] = $doc;
60+
}
7261
}
7362
}
7463
return $sorted;

0 commit comments

Comments
 (0)