-
-
Notifications
You must be signed in to change notification settings - Fork 147
Closed
Description
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.
<?php
namespace App\Providers;
use Illuminate\Auth\Events\Registered;
use Illuminate\Auth\Listeners\SendEmailVerificationNotification;
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
use Illuminate\Support\Facades\Event;
class EventServiceProvider extends ServiceProvider
{
/**
* The event listener mappings for the application.
*
* @var array
*/
protected $listen = [
Registered::class => [
SendEmailVerificationNotification::class,
],
];
/**
* Register any events for your application.
*
* @return void
*/
public function boot()
{
parent::boot();
//
}
}use App\Providers\EventServiceProvider;
$class = \Nette\PhpGenerator\ClassType::from(EventServiceProvider::class);
echo $class->getMethod('boot')->getBody(); // ''Expected Behavior
use App\Providers\EventServiceProvider;
$class = \Nette\PhpGenerator\ClassType::from(EventServiceProvider::class);
echo $class->getMethod('boot')->getBody(); // 'parent::boot();\n\n//'Possible Solution
Add this method to retrieve the body inside the \PhpGenerator\Factory::fromMethodReflection:
protected function getMethodBody(\ReflectionMethod $from) : string
{
$lines = file($from->getFileName());
$string = '';
for ($start = $from->getStartLine()+1, $end = $from->getEndLine()-1; $start < $end; $start++) {
$string .= $lines[$start];
}
return $string;
}From there, the only thing would be to "unpad" each line.
Metadata
Metadata
Assignees
Labels
No labels