/** * Execute the console command. * * @return mixed */ public function handle() { // recuperation du controller $controller = $this->argument('controller'); // création de la méthode $method = camel_case($this->argument('name')); $method = PhpMethod::create($method); $method->setStatic(true); // Gestion du body $body = file_get_contents(__DIR__ . '/stubs/table.stub'); $method->setBody($body); // block de commentaire $dockblock = new Docblock(); $dockblock->appendTag(TagFactory::create('name', 'Artisan')); $dockblock->appendTag(TagFactory::create('see', 'php artisan ffmake:table')); $dockblock->appendTag(TagFactory::create('generated', Carbon::now())); $method->setDocblock($dockblock); // Récupération du controller à mettre à jour $controller = ucfirst(camel_case($controller . '_controller')); $controller = new \ReflectionClass('App\\Http\\Controllers\\' . $controller); $class = PhpClass::fromReflection($controller)->setMethod($method); $class->setParentClassName('Controller'); // fix la gestion des namespaec pour la parent class // Génration du code $generator = new CodeGenerator(); $class = '<?php ' . $generator->generate($class); // inscription du code dans la classe file_put_contents($controller->getFileName(), $class); $this->info('Action generated dans le fichier : ' . $controller->getFileName()); }
public function testDocblock() { $expected = '/** * @var mixed $foo bar */'; $docblock = new Docblock(); $var = VarTag::create()->setType('mixed')->setVariable('foo')->setDescription('bar'); $docblock->appendTag($var); $this->assertEquals($expected, $docblock->toString()); }
/** * @param Node\Stmt\ClassMethod $node * @param string $text * * @return string */ public function addParams(Node\Stmt\ClassMethod $node, $text) { $docBlock = new Docblock($text); foreach ($node->getParams() as $param) { $type = $this->getFullyQualifiedParamType($param); if (null === $type) { continue; } $docBlock->appendTag(new ParamTag((string) $type . ' $' . $param->name)); } return str_replace("* \n", "*\n", $docBlock->toString()); //TODO remove once https://github.com/gossi/docblock/pull/2 is merged }
/** * @param Node\Stmt\ClassMethod $node * @param string $text * * @return string */ public function addParams(Node\Stmt\ClassMethod $node, $text) { $docBlock = new Docblock($text); foreach ($node->getParams() as $param) { if ($param->type && $param->type instanceof Node\Name) { $type = $this->resolver->resolve(implode('\\', $param->type->parts), $this->context); $type = str_replace('\\\\', '\\', $type); } elseif ($param->type && is_string($param->type)) { $type = $param->type; } if (!isset($type)) { continue; } $docBlock->appendTag(new ParamTag((string) $type . ' $' . $param->name)); } $string = $docBlock->toString(); return str_replace("* \n", "*\n", $string); //TODO remove once https://github.com/gossi/docblock/pull/2 is merged }
public function testMethod() { $expected = '/** * my method * * my very long method * * @see MyClass#myMethod see-desc * @param $a method-param * @throws \\Exception when something goes wrong * @return string this method returns a string */'; $throws = new ThrowsTag('\\Exception when something goes wrong'); $doc = new Docblock(); $doc->appendTag($throws); $method = $this->getMethod(); $method->setDocblock($doc); $method->generateDocblock(); $docblock = $method->getDocblock(); $see = new SeeTag('MyClass#myMethod see-desc'); $docblock->appendTag($see); $this->assertSame($docblock, $doc); $this->assertEquals($expected, $docblock->toString()); }
public function testEmpty() { $doc = new Docblock(); $this->assertTrue($doc->isEmpty()); $doc->setLongDescription('bla'); $this->assertFalse($doc->isEmpty()); $doc->setLongDescription(null); $this->assertTrue($doc->isEmpty()); $doc->setShortDescription('bla'); $this->assertFalse($doc->isEmpty()); $doc->setShortDescription(null); $this->assertTrue($doc->isEmpty()); $doc->appendTag(new SeeTag()); $this->assertFalse($doc->isEmpty()); }
/** * Execute the console command. * * @return mixed */ public function handle() { $controller = $this->argument('controller'); // création de la méthode $method = camel_case($this->argument('method') . '_' . $this->argument('name')); $method = PhpMethod::create($method); // PARAMS $this->generateParams($method); // BODY $body = ''; $body .= $this->generateAcl(); // TEMPLATE $template = camel_case('template_' . $this->option('template')); if (!method_exists($this, $template)) { exc('Impossible de trouver le template : ' . $template); } $body .= call_user_func([$this, $template]); $method->setBody($body); // DOCKBOCK $dockblock = new Docblock(); $dockblock->appendTag(TagFactory::create('name', 'Artisan')); $dockblock->appendTag(TagFactory::create('see', 'php artisan ffmake:action')); $dockblock->appendTag(TagFactory::create('generated', Carbon::now())); $method->setDocblock($dockblock); // CONTROLLER $controller = ucfirst(camel_case($controller . '_controller')); $controller = new \ReflectionClass('App\\Http\\Controllers\\' . $controller); $class = PhpClass::fromReflection($controller)->setMethod($method); $class->setParentClassName('Controller'); // fix la gestion des namespaec pour la parent class // GENERATION $generator = new CodeGenerator(); $class = '<?php ' . $generator->generate($class); // inscription du code dans la classe file_put_contents($controller->getFileName(), $class); $this->info('Action generated dans le fichier : ' . $controller->getFileName()); }