Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions system/CLI/CLI.php
Original file line number Diff line number Diff line change
Expand Up @@ -947,6 +947,8 @@ public static function getURI(): string
* // segment(3) is 'three', not '-f' or 'anOption'
* > php spark one two -f anOption three
*
* **IMPORTANT:** The index here is one-based instead of zero-based.
*
* @param integer $index
*
* @return mixed|null
Expand Down
11 changes: 7 additions & 4 deletions system/CLI/GeneratorCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,8 @@ public function run(array $params)
*/
protected function getClassName(): string
{
$name = $this->params[0] ?? CLI::getSegment(0);
$name = $this->params[0] ?? CLI::getSegment(2);

return $name ?? '';
}

Expand Down Expand Up @@ -203,6 +204,7 @@ protected function qualifyClassName(string $class): string
protected function getRootNamespace(): string
{
$rootNamespace = $this->params['n'] ?? CLI::getOption('n') ?? APP_NAMESPACE;

return trim(str_replace('/', '\\', $rootNamespace), '\\');
}

Expand Down Expand Up @@ -238,6 +240,7 @@ protected function buildPath(string $class): string

$path = $base . DIRECTORY_SEPARATOR . str_replace('\\', DIRECTORY_SEPARATOR, $name) . '.php';
$filename = $this->modifyBasename(basename($path));

return implode(DIRECTORY_SEPARATOR, array_slice(explode(DIRECTORY_SEPARATOR, $path), 0, -1)) . DIRECTORY_SEPARATOR . $filename;
}

Expand Down Expand Up @@ -310,6 +313,7 @@ protected function setReplacements(string $template, string $class): string

$template = str_replace($namespaces, $this->getNamespace($class), $template);
$class = str_replace($this->getNamespace($class) . '\\', '', $class);

return str_replace($classes, $class, $template);
}

Expand All @@ -326,11 +330,10 @@ protected function sortImports(string $template): string
{
$imports = explode("\n", trim($match['imports']));
sort($imports);

return str_replace(trim($match['imports']), implode("\n", $imports), $template);
}

// @codeCoverageIgnoreStart
return $template;
// @codeCoverageIgnoreEnd
return $template; // @codeCoverageIgnore
}
}