-
-
Notifications
You must be signed in to change notification settings - Fork 140
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Parsing a Class doesn't includes method body. #59
Comments
Should have a proper way of returning the exact same body. Your code is OK. But I think, it can be better, Try this:
protected function getMethodBody(\ReflectionMethod $from) : string
{
if (false === $from->getFileName()) {
return '';
}
$codeLines = file($from->getFileName());
$lineOfCode = array_slice($codeLines, $from->getStartLine() + 1, $from->getEndLine() - $from->getStartLine() - 2);
$unindentedLines = array_map(function ($lineOfCode) {
// Search for 2 tabs indent, then begin from a new line
if (Strings::startsWith($lineOfCode, "\t")) {
return Strings::substring($lineOfCode, strlen("\t\t"));
}
// preserve all other lines of code in body.
return $lineOfCode;
}, $lineOfCode);
return "\n".implode('', $unindentedLines);
} |
This is duplicated to #4. Because content can't be extracted 100% correctly (for example in minified code or due to bad coding style), I don't want to try. So please add this functionality in your code. |
dg
added a commit
that referenced
this issue
May 6, 2020
dg
added a commit
that referenced
this issue
May 6, 2020
dg
added a commit
that referenced
this issue
May 6, 2020
dg
added a commit
that referenced
this issue
May 6, 2020
dg
added a commit
that referenced
this issue
May 6, 2020
dg
added a commit
that referenced
this issue
May 6, 2020
dg
added a commit
that referenced
this issue
May 6, 2020
dg
added a commit
that referenced
this issue
May 26, 2020
dg
added a commit
that referenced
this issue
May 26, 2020
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Version: 3.3.4
Bug Description
Using an existing class won't register method bodies at all.
Steps To Reproduce
Create one class with a method body, and then parse it manually.
Expected Behavior
Possible Solution
Add this method to retrieve the body inside the
\PhpGenerator\Factory::fromMethodReflection
:From there, the only thing would be to "unpad" each line.
The text was updated successfully, but these errors were encountered: