Skip to content

Commit

Permalink
refactor(generator): Refactor GeneratorManager to improve readability…
Browse files Browse the repository at this point in the history
… and maintainability

- Removed unnecessary array_filter usage
- Simplified variable assignment for studlyName
- Improved method_exists and class_exists checks for driver creation
- Added exception handling for unsupported drivers
  • Loading branch information
[email protected] committed Apr 7, 2024
1 parent fe6668d commit 6e7aa67
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions app/GeneratorManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,15 @@ protected function createDriver($driver)
}

$config = $this->config->get("ai-commit.generators.$driver");
$drivers = array_filter([$driver, $config['driver'] ?? null]);

foreach ($drivers as $d) {
$studlyName = Str::studly($d);
$studlyName = Str::studly($config['driver'] ?? $driver);

if (method_exists($this, $method = "create{$studlyName}Driver")) {
return $this->{$method}($config);
}
if (method_exists($this, $method = "create{$studlyName}Driver")) {
return $this->{$method}($config);
}

if (class_exists($class = "App\\Generators\\{$studlyName}Generator")) {
return new $class($config);
}
if (class_exists($class = "App\\Generators\\{$studlyName}Generator")) {
return new $class($config);
}

throw new InvalidArgumentException("Driver [$driver] not supported.");
Expand Down

0 comments on commit 6e7aa67

Please sign in to comment.