From 67d5d0b5a056e88b764ee876e9899a1315f30b07 Mon Sep 17 00:00:00 2001 From: NGUEREZA Tony Date: Sun, 17 Sep 2023 07:58:30 +0100 Subject: [PATCH] Update make commands --- src/Console/Command/MakeEntityCommand.php | 4 +++- src/Console/Command/MakeFormParamCommand.php | 11 ++++++++--- src/Console/Command/MakeRepositoryCommand.php | 7 +++++-- src/Console/MakeCommand.php | 16 ++++++++++++++++ tests/Console/Command/MakeActionCommandTest.php | 5 +++++ 5 files changed, 37 insertions(+), 6 deletions(-) diff --git a/src/Console/Command/MakeEntityCommand.php b/src/Console/Command/MakeEntityCommand.php index 6965bd9..4a80bf3 100644 --- a/src/Console/Command/MakeEntityCommand.php +++ b/src/Console/Command/MakeEntityCommand.php @@ -134,12 +134,14 @@ public function getClassTemplate(): string /** * @class %classname% * @package %namespace% + * @extends Entity<%classname%> */ class %classname% extends Entity { /** - * {@inheritdoc} + * @param EntityMapperInterface<%classname%> \$mapper + * @return void */ public static function mapEntity(EntityMapperInterface \$mapper): void { diff --git a/src/Console/Command/MakeFormParamCommand.php b/src/Console/Command/MakeFormParamCommand.php index 31ce137..25c8186 100644 --- a/src/Console/Command/MakeFormParamCommand.php +++ b/src/Console/Command/MakeFormParamCommand.php @@ -161,6 +161,7 @@ public function getClassTemplate(): string /** * @class %classname% * @package %namespace% + * %template_entity% */ class %classname% extends BaseParam { @@ -278,10 +279,12 @@ public function $getterName(): string protected function getFromEntityBody(string $content): string { $result = ''; + $templateEntity = '@template TEntity as Entity'; if ($this->createInstanceFormEntity && !empty($this->fromEntityMaps)) { $result = << */ class %classname% extends Repository { /** * Create new instance - * @param EntityManager \$manager + * @param EntityManager<%entity_base_class%> \$manager */ public function __construct(EntityManager \$manager) { @@ -164,7 +165,9 @@ protected function getUsesContent(): string protected function getEntityBody(string $content): string { $entityName = basename($this->entityClass) . '::class'; + $entityBaseName = $this->getClassBaseName($this->entityClass); - return str_replace('%entity_class%', $entityName, $content); + $template = str_replace('%entity_base_class%', $entityBaseName, $content); + return str_replace('%entity_class%', $entityName, $template); } } diff --git a/src/Console/MakeCommand.php b/src/Console/MakeCommand.php index 7308576..1e128df 100644 --- a/src/Console/MakeCommand.php +++ b/src/Console/MakeCommand.php @@ -176,6 +176,22 @@ public function interact(Reader $reader, Writer $writer): void $this->className = $name; } + + /** + * Return the base class name + * @param string|object $fullClassName + * @return string + */ + public function getClassBaseName($fullClassName): string + { + if (is_object($fullClassName)) { + $fullClassName = get_class($fullClassName); + } + + $temp = explode('\\', $fullClassName); + + return end($temp); + } /** * Return the the class template diff --git a/tests/Console/Command/MakeActionCommandTest.php b/tests/Console/Command/MakeActionCommandTest.php index e0b3851..fc2c321 100644 --- a/tests/Console/Command/MakeActionCommandTest.php +++ b/tests/Console/Command/MakeActionCommandTest.php @@ -11,6 +11,7 @@ use Platine\Framework\App\Application; use Platine\Framework\Console\Command\MakeActionCommand; use Platine\Test\Framework\Console\BaseCommandTestCase; +use stdClass; /* * @group core @@ -47,6 +48,10 @@ public function testExecuteDefault(): void $o->bind($consoleApp); $o->parse(['platine', $actionName]); $this->assertEquals('make:action', $o->getName()); + + // Only to coverage tests + $this->assertEquals('MakeActionCommandTest', $o->getClassBaseName($this)); + $this->assertEquals(stdClass::class, $o->getClassBaseName(stdClass::class)); $o->interact($reader, $writer); $o->execute();