diff --git a/system/CLI/CLI.php b/system/CLI/CLI.php index 8da7814aee0b..3f982c129c22 100644 --- a/system/CLI/CLI.php +++ b/system/CLI/CLI.php @@ -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 diff --git a/system/CLI/GeneratorCommand.php b/system/CLI/GeneratorCommand.php index 0bf96cac8bd0..0b0ba192ade8 100644 --- a/system/CLI/GeneratorCommand.php +++ b/system/CLI/GeneratorCommand.php @@ -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 ?? ''; } @@ -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), '\\'); } @@ -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; } @@ -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); } @@ -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 } }