Skip to content

Commit

Permalink
refactoring runner
Browse files Browse the repository at this point in the history
  • Loading branch information
secure73 committed Sep 27, 2024
1 parent 0c931d6 commit 4602ffd
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions src/core/Runner.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,12 @@ private function registerDefaultCommands():void
{
$this->commands['Migrate'] = [$this, 'handleMigrate'];
}

public function run($argv):void
/**
* Summary of run
* @param array<string> $argv
* @return void
*/
public function run(array $argv):void
{
if (count($argv) < 3) {
echo "Usage: Gemvc <Command> <ClassName>\n";
Expand All @@ -33,15 +37,15 @@ public function run($argv):void
$this->printAvailableCommands();
exit(1);
}

call_user_func($this->commands[$command], $className);
// @phpstan-ignore-next-line
call_user_func($this->commands[$command], args: $className);
}
/**
* Summary of handleMigrate
* @param string $className
* @return void
* @return bool
*/
private function handleMigrate($className):void
private function handleMigrate(string $className):bool
{
if (!class_exists($className)) {
echo "Class '$className' not found.\n";
Expand All @@ -50,14 +54,15 @@ private function handleMigrate($className):void

// Create instance of the class
$object = new $className();
if(!$object instanceof Table)
{
echo "The provided object is not a valid table instance.";
return false;
}

// Generate the table
$tableGenerator = new TableGenerator();
$result = $tableGenerator->createTableFromObject($object);

if ($result === false) {
echo "The provided object is not a valid table instance.";
}
return $tableGenerator->createTableFromObject($object);
}

private function printAvailableCommands():void
Expand All @@ -68,4 +73,3 @@ private function printAvailableCommands():void
}
}
}
?>

0 comments on commit 4602ffd

Please sign in to comment.