Skip to content

Commit

Permalink
commented and regexp based rules disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
kevincobain2000 committed Feb 9, 2022
1 parent 4de850d commit abf3534
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/LaravelRequestDocs.php
Expand Up @@ -130,7 +130,11 @@ public function appendRequestRules(array $controllersInfo)
try {
$controllersInfo[$index]['rules'] = $this->flattenRules($requestClass->rules());
} catch (Exception $e) {
$controllersInfo[$index]['rules'] = $this->rulesByRegex($requestClassName);
// disabled. This only works when the rules are defined as 'required|integer' and that too in single line
// doesn't work well when the same rule is defined as array ['required', 'integer'] or in multiple lines such as
// If your rules are not populated using this library, then fix your rule to only throw validation errors and not throw exceptions
// such as 404, 500 inside the request class.
// $controllersInfo[$index]['rules'] = $this->rulesByRegex($requestClassName);
}
$controllersInfo[$index]['docBlock'] = $this->lrdDocComment($reflectionMethod->getDocComment());
}
Expand Down Expand Up @@ -196,6 +200,7 @@ public function rulesByRegex($requestClassName)
$data = new ReflectionMethod($requestClassName, 'rules');
$lines = file($data->getFileName());
$rules = [];

for ($i = $data->getStartLine() - 1; $i <= $data->getEndLine() - 1; $i++) {
preg_match_all("/(?:'|\").*?(?:'|\")/", $lines[$i], $matches);
$rules[] = $matches;
Expand Down

0 comments on commit abf3534

Please sign in to comment.