Skip to content

Commit b0b9b94

Browse files
Merge pull request rakutentech#38 from rakutentech/feature/reg
WIP - Fixes rakutentech#37, regexp rules were not fetching
2 parents 1930288 + abf3534 commit b0b9b94

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/LaravelRequestDocs.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,12 @@ public function appendRequestRules(array $controllersInfo)
129129
if ($requestClass instanceof FormRequest) {
130130
try {
131131
$controllersInfo[$index]['rules'] = $this->flattenRules($requestClass->rules());
132-
} catch (Exception $th) {
133-
$controllerInfo[$index]['rules'] = $this->rulesByRegex($requestClassName);
132+
} catch (Exception $e) {
133+
// disabled. This only works when the rules are defined as 'required|integer' and that too in single line
134+
// doesn't work well when the same rule is defined as array ['required', 'integer'] or in multiple lines such as
135+
// If your rules are not populated using this library, then fix your rule to only throw validation errors and not throw exceptions
136+
// such as 404, 500 inside the request class.
137+
// $controllersInfo[$index]['rules'] = $this->rulesByRegex($requestClassName);
134138
}
135139
$controllersInfo[$index]['docBlock'] = $this->lrdDocComment($reflectionMethod->getDocComment());
136140
}
@@ -196,6 +200,7 @@ public function rulesByRegex($requestClassName)
196200
$data = new ReflectionMethod($requestClassName, 'rules');
197201
$lines = file($data->getFileName());
198202
$rules = [];
203+
199204
for ($i = $data->getStartLine() - 1; $i <= $data->getEndLine() - 1; $i++) {
200205
preg_match_all("/(?:'|\").*?(?:'|\")/", $lines[$i], $matches);
201206
$rules[] = $matches;

0 commit comments

Comments
 (0)