diff --git a/src/libraries/Console/BaseCommand.php b/src/libraries/Console/BaseCommand.php index 7511818..318067d 100644 --- a/src/libraries/Console/BaseCommand.php +++ b/src/libraries/Console/BaseCommand.php @@ -1,14 +1,17 @@ + * Class BaseCommand * - * For the full copyright and license information, please view - * the LICENSE file that was distributed with this source code. + * @author Juan Cristobal + * @link http://www.axm.com/ + * @license http://www.axm.com/license/ + * @package Console */ - namespace Console; use Console\CLI; @@ -120,25 +123,25 @@ public function showHelp() { CLI::write('CLI help Usage: ', 'yellow'); - if (!empty($this->usage)) { + if (!empty ($this->usage)) { $usage = $this->usage; } else { $usage = $this->name; - if (!empty($this->arguments)) { + if (!empty ($this->arguments)) { $usage .= ' [arguments]'; } } CLI::write($this->setPad($usage, 0, 0, 2)); - if (!empty($this->description)) { + if (!empty ($this->description)) { CLI::newLine(); CLI::write(self::ARROW_SYMBOL . 'CLI help Description: ', 'yellow'); CLI::write($this->setPad($this->description, 0, 0, 2)); } - if (!empty($this->arguments)) { + if (!empty ($this->arguments)) { CLI::newLine(); CLI::write(self::ARROW_SYMBOL . 'CLI help Arguments: ', 'yellow'); @@ -149,7 +152,7 @@ public function showHelp() } } - if (!empty($this->options)) { + if (!empty ($this->options)) { CLI::newLine(); CLI::write(self::ARROW_SYMBOL . 'CLI help Options: ', 'yellow'); @@ -201,6 +204,6 @@ public function __get(string $key) */ public function __isset(string $key): bool { - return isset($this->{$key}); + return isset ($this->{$key}); } } diff --git a/src/libraries/Console/CLI.php b/src/libraries/Console/CLI.php index bf83e75..f75f716 100644 --- a/src/libraries/Console/CLI.php +++ b/src/libraries/Console/CLI.php @@ -1,13 +1,22 @@ */ protected static $foreground_colors = [ - 'black' => '0;30', - 'dark_gray' => '1;30', - 'blue' => '0;34', - 'light_blue' => '1;34', - 'green' => '0;32', - 'light_green' => '1;32', - 'cyan' => '0;36', - 'light_cyan' => '1;36', - 'red' => '0;31', - 'light_red' => '1;31', - 'purple' => '0;35', + 'black' => '0;30', + 'dark_gray' => '1;30', + 'blue' => '0;34', + 'light_blue' => '1;34', + 'green' => '0;32', + 'light_green' => '1;32', + 'cyan' => '0;36', + 'light_cyan' => '1;36', + 'red' => '0;31', + 'light_red' => '1;31', + 'purple' => '0;35', 'light_purple' => '1;35', - 'yellow' => '0;33', + 'yellow' => '0;33', 'light_yellow' => '1;33', - 'light_gray' => '0;37', - 'white' => '1;37', - 'default' => '1;37', + 'light_gray' => '0;37', + 'white' => '1;37', + 'default' => '1;37', ]; /** @@ -62,13 +71,13 @@ class CLI * @var array */ protected static $background_colors = [ - 'black' => '40', - 'red' => '41', - 'green' => '42', - 'yellow' => '43', - 'blue' => '44', - 'magenta' => '45', - 'cyan' => '46', + 'black' => '40', + 'red' => '41', + 'green' => '42', + 'yellow' => '43', + 'blue' => '44', + 'magenta' => '45', + 'cyan' => '46', 'light_gray' => '47', ]; @@ -127,7 +136,7 @@ public static function init() // clear segments & options to keep testing clean static::$segments = []; - static::$options = []; + static::$options = []; // Check our stream resource for color support static::$isColored = static::hasColorSupport(STDOUT); @@ -183,7 +192,7 @@ public static function input(?string $prefix = null): string public static function prompt(string $field, $options = null, $validation = null, string $color = 'yellow'): string { $extraOutput = ''; - $default = ''; + $default = ''; if ($validation && !is_array($validation) && !is_string($validation)) { throw new Exception('$rules can only be of type string|array'); @@ -191,25 +200,25 @@ public static function prompt(string $field, $options = null, $validation = null if (is_string($options)) { $extraOutput = ' [' . static::color($options, 'green') . ']'; - $default = $options; + $default = $options; } if (is_array($options) && $options) { - $opts = $options; + $opts = $options; $extraOutputDefault = static::color($opts[0], 'green'); unset($opts[0]); - if (empty($opts)) { + if (empty ($opts)) { $extraOutput = $extraOutputDefault; } else { - $extraOutput = '[' . $extraOutputDefault . ', ' . implode(', ', $opts) . ']'; + $extraOutput = '[' . $extraOutputDefault . ', ' . implode(', ', $opts) . ']'; } $default = $options[0]; } - static::fwrite(STDOUT, static::color($field, $color) . (trim($field) ? ' ' : '') . $extraOutput . ': '); + static::fwrite(STDOUT, static::color($field, $color) . (trim($field) ? ' ' : '') . $extraOutput . ': '); // Read the input from keyboard. $input = trim(static::input()) ?: $default; @@ -252,8 +261,8 @@ public static function promptByKey($text, array $options, $validation = null): s $keyMaxLength = max(array_map('mb_strwidth', array_keys($options))) + 2; foreach ($options as $key => $description) { - $name = str_pad(' [' . $key . '] ', $keyMaxLength + 4, ' '); - CLI::write(CLI::color($name, 'green') . CLI::wrap($description, 125, $keyMaxLength + 4)); + $name = str_pad(' [' . $key . '] ', (int) ($keyMaxLength + 4), ' '); + CLI::write(CLI::color($name, 'green') . CLI::wrap($description, 125, (int) ($keyMaxLength + 4))); } return static::prompt(PHP_EOL . array_shift($text), array_keys($options), $validation); @@ -269,8 +278,8 @@ public static function promptByKey($text, array $options, $validation = null): s */ protected static function validate(string $field, string $value, $rules): bool { - $rules = ['input' => $rules]; - $data = ['input' => $value]; + $rules = ['input' => $rules]; + $data = ['input' => $value]; $validator = Validator::make($rules, $data); if ($validator->fails()) { @@ -307,7 +316,7 @@ public static function write(string $text = '', ?string $foreground = null, ?str } if (static::$lastWrite !== 'write') { - $text = PHP_EOL . $text; + $text = PHP_EOL . $text; static::$lastWrite = 'write'; } @@ -320,7 +329,7 @@ public static function write(string $text = '', ?string $foreground = null, ?str public static function msg(string $text, string $foreground = 'light_red', ?string $background = null) { // Check color support for STDERR - $stdout = static::$isColored; + $stdout = static::$isColored; static::$isColored = static::hasColorSupport(STDERR); if ($foreground || $background) { @@ -434,7 +443,7 @@ public static function loading(int $seconds) $coloredChar = static::color($loadingChars[$i], array_rand($colors)); // Aplicar el color al carácter actual static::fwrite(STDOUT, $coloredChar . ' '); // Imprimir el carácter coloreado - usleep($interval * 1000000); // Esperar el intervalo de tiempo + usleep((int) ($interval * 1000000)); // Esperar el intervalo de tiempo static::fwrite(STDOUT, "\r"); // Volver al principio de la línea para sobrescribir el carácter anterior } } @@ -474,7 +483,7 @@ public static function progressBar(int $seconds) $estimatedRemainingTime = $remainingTime / ($progressPercentage == 0 ? 1 : $progressPercentage / 100); // Imprimir la barra de progreso y el porcentaje de avance - printf("\r%.1f%% %s Time Remaining: %.1f sec ", $progressPercentage, $bar, $estimatedRemainingTime); + printf("\r%.1f%% %s Time Remaining: %.1f sec ", $progressPercentage, $bar, $estimatedRemainingTime); // Incrementar el progreso $progress++; @@ -633,7 +642,7 @@ public static function streamSupports(string $function, $resource): bool public static function hasColorSupport($resource): bool { // Follow https://no-color.org/ - if (isset($_SERVER['NO_COLOR']) || getenv('NO_COLOR') !== false) { + if (isset ($_SERVER['NO_COLOR']) || getenv('NO_COLOR') !== false) { return false; } @@ -643,7 +652,7 @@ public static function hasColorSupport($resource): bool if (static::isWindows()) { return static::streamSupports('sapi_windows_vt100_support', $resource) - || isset($_SERVER['ANSICON']) + || isset ($_SERVER['ANSICON']) || getenv('ANSICON') !== false || getenv('ConEmuANSI') === 'ON' || getenv('TERM') === 'xterm'; @@ -687,7 +696,7 @@ public static function generateDimensions() // when executing `mode CON`, so we use `tput` instead if (getenv('TERM') || (($shell = getenv('SHELL')) && preg_match('/(?:bash|zsh)(?:\.exe)?$/', $shell))) { static::$height = (int) exec('tput lines'); - static::$width = (int) exec('tput cols'); + static::$width = (int) exec('tput cols'); } else { $return = -1; $output = []; @@ -697,21 +706,21 @@ public static function generateDimensions() // Searching for "Columns:" or "Lines:" will fail on non-English locales if ($return === 0 && $output && preg_match('/:\s*(\d+)\n[^:]+:\s*(\d+)\n/', implode("\n", $output), $matches)) { static::$height = (int) $matches[1]; - static::$width = (int) $matches[2]; + static::$width = (int) $matches[2]; } } } elseif (($size = exec('stty size')) && preg_match('/(\d+)\s+(\d+)/', $size, $matches)) { static::$height = (int) $matches[1]; - static::$width = (int) $matches[2]; + static::$width = (int) $matches[2]; } else { static::$height = (int) exec('tput lines'); - static::$width = (int) exec('tput cols'); + static::$width = (int) exec('tput cols'); } } catch (\Throwable $e) { // Reset the dimensions so that the default values will be returned later. // Then let the developer know of the error. static::$height = null; - static::$width = null; + static::$width = null; error_log('error: ' . $e->getMessage()); } } @@ -734,11 +743,11 @@ public static function showProgress($thisStep = 1, int $totalSteps = 10) if ($thisStep !== false) { // Don't allow div by zero or negative numbers.... - $thisStep = abs($thisStep); + $thisStep = abs($thisStep); $totalSteps = $totalSteps < 1 ? 1 : $totalSteps; $percent = (int) (($thisStep / $totalSteps) * 100); - $step = (int) round($percent / 10); + $step = (int) round($percent / 10); // Write the progress bar static::fwrite(STDOUT, "[\033[32m" . str_repeat('#', $step) . str_repeat('.', 10 - $step) . "\033[0m]"); @@ -760,7 +769,7 @@ public static function showProgress($thisStep = 1, int $totalSteps = 10) */ public static function wrap(?string $string = null, int $max = 0, int $padLeft = 0): string { - if (empty($string)) { + if (empty ($string)) { return ''; } @@ -825,11 +834,11 @@ protected static function parseCommandLine() continue; } - $arg = ltrim($arg, '-'); + $arg = ltrim($arg, '-'); $value = null; - if (isset($args[$i + 1]) && mb_strpos($args[$i + 1], '-') !== 0) { - $value = $args[$i + 1]; + if (isset ($args[$i + 1]) && mb_strpos($args[$i + 1], '-') !== 0) { + $value = $args[$i + 1]; $optionValue = true; } @@ -909,7 +918,7 @@ public static function getOptions(): array */ public static function getOptionString(bool $useLongOpts = false, bool $trim = false): string { - if (empty(static::$options)) { + if (empty (static::$options)) { return ''; } @@ -948,7 +957,7 @@ public static function table(array $tbody, array $thead = []) $tableRows = []; // We need only indexes and not keys - if (!empty($thead)) { + if (!empty ($thead)) { $tableRows[] = array_values($thead); } @@ -978,7 +987,7 @@ public static function table(array $tbody, array $thead = []) // If the current column does not have a value among the larger ones // or the value of this is greater than the existing one // then, now, this assumes the maximum length - if (!isset($maxColsLengths[$column]) || $allColsLengths[$row][$column] > $maxColsLengths[$column]) { + if (!isset ($maxColsLengths[$column]) || $allColsLengths[$row][$column] > $maxColsLengths[$column]) { $maxColsLengths[$column] = $allColsLengths[$row][$column]; } @@ -1021,7 +1030,7 @@ public static function table(array $tbody, array $thead = []) $table .= '| ' . implode(' | ', $tableRows[$row]) . ' |' . PHP_EOL; // Set the thead and table borders-bottom - if (isset($cols) && (($row === 0 && !empty($thead)) || ($row + 1 === $totalRows))) { + if (isset ($cols) && (($row === 0 && !empty ($thead)) || ($row + 1 === $totalRows))) { $table .= $cols . PHP_EOL; } } @@ -1058,7 +1067,7 @@ protected static function is_cli(): bool return true; } - return !isset($_SERVER['REMOTE_ADDR']) && !isset($_SERVER['REQUEST_METHOD']); + return !isset ($_SERVER['REMOTE_ADDR']) && !isset ($_SERVER['REQUEST_METHOD']); } } diff --git a/src/libraries/Console/CLIException.php b/src/libraries/Console/CLIException.php index d109f64..d0992c0 100644 --- a/src/libraries/Console/CLIException.php +++ b/src/libraries/Console/CLIException.php @@ -7,11 +7,19 @@ use Throwable; /** - * CLIException + * Axm Framework PHP. + * + * Class CLIException * * This class shows in a nice and detailed way the error in the console, * this code has been inspired by the Laravel Colision library. + * + * @author Juan Cristobal + * @link http://www.axm.com/ + * @license http://www.axm.com/license/ + * @package Console */ + class CLIException { private const DELIMITER = '|'; @@ -23,7 +31,6 @@ class CLIException /** * Handles an exception and displays relevant information in the console. - * @param Throwable $e The exception to handle. */ public static function handleCLIException(Throwable $e): void { @@ -33,10 +40,7 @@ public static function handleCLIException(Throwable $e): void } /** - * info - * - * @param string $key - * @return void + * Message Info */ public static function info(string $key) { @@ -51,7 +55,6 @@ public static function info(string $key) /** * Prints information about the exception. - * @param Throwable $e The exception. */ protected static function printExceptionInfo(Throwable $e): void { @@ -64,10 +67,6 @@ protected static function printExceptionInfo(Throwable $e): void /** * Displays a formatted header box with a title and message. - * - * @param string $title The title of the header box. - * @param string $message The message to be displayed in the header box. - * @return void */ protected static function displayHeaderBox(string $title, string $message): void { @@ -80,9 +79,8 @@ protected static function displayHeaderBox(string $title, string $message): void /** * Displays a snippet of relevant code for the exception. - * @param Throwable $e The exception. */ - public static function snipCode(Throwable $e) + public static function snipCode(Throwable $e): void { $code = self::getCode($e); CLI::write($code); @@ -90,9 +88,6 @@ public static function snipCode(Throwable $e) /** * Gets the relevant source code for the exception. - * - * @param Throwable $e The exception. - * @return string The source code. */ public static function getCode(Throwable $e): string { @@ -102,9 +97,6 @@ public static function getCode(Throwable $e): string /** * Gets the color associated with a PHP token ID. - * - * @param int $tokenId The PHP token ID. - * @return string The color associated with the token ID. */ protected static function getTokenColor(int $tokenId): string { @@ -114,6 +106,7 @@ protected static function getTokenColor(int $tokenId): string T_CLOSE_TAG => 'blue', T_STRING => 'blue', T_VARIABLE => 'light_cyan', + // Constants T_DIR => 'light_cyan', T_FILE => 'default', @@ -125,6 +118,7 @@ protected static function getTokenColor(int $tokenId): string T_CLASS_C => 'light_cyan', T_FUNC_C => 'light_yellow', T_TRAIT_C => 'light_cyan', + // Comment T_COMMENT => 'light_green', T_DOC_COMMENT => 'dark_gray', @@ -154,7 +148,6 @@ protected static function getTokenColor(int $tokenId): string T_ENDFOR => 'light_purple', T_ENDFOREACH => 'light_purple', T_ENDWHILE => 'light_purple', - T_THROW => 'light_purple', // T_DOLLAR_OPEN_CURLY_BRACES => 'light_purple', @@ -177,11 +170,6 @@ protected static function getTokenColor(int $tokenId): string /** * Renders the relevant source code. - * - * @param string $file The file name. - * @param int $errorLine The line number with the error. - * @param int $maxLines The maximum number of lines to display. - * @return string The formatted source code. */ protected static function renderSourceCode(string $file, int $errorLine, int $maxLines): string { @@ -200,11 +188,6 @@ protected static function renderSourceCode(string $file, int $errorLine, int $ma /** * Calculates the line range to display. - * - * @param int $errorLine Error line number. - * @param int $lineCount Total number of lines. - * @param int $maxLines Maximum number of lines to display. - * @return array Line range to display (start and end). */ protected static function calculateLineRange(int $errorLine, int $lineCount, int $maxLines): array { @@ -219,13 +202,8 @@ protected static function calculateLineRange(int $errorLine, int $lineCount, int /** * Highlights the relevant lines of the source code. - * - * @param array $lines Array of code lines. - * @param array $lineRange Line range to display. - * @param int $errorLine Error line number. - * @return array Array of highlighted lines. */ - protected static function highlightLines($lines, $lineRange, $errorLine) + protected static function highlightLines(array $lines, array $lineRange, int $errorLine): string { $highlightedLines = []; @@ -250,12 +228,8 @@ protected static function highlightLines($lines, $lineRange, $errorLine) return implode('', $highlightedLines); } - /** * Prepares the code for rendering by adding a PHP opening tag. - * - * @param array $code An array of code lines. - * @return string The prepared code with a PHP opening tag. */ protected static function prepareCode(array $code): string { @@ -266,9 +240,6 @@ protected static function prepareCode(array $code): string /** * Highlights the syntax of the provided code using ANSI colors. - * - * @param string $code The code to be highlighted. - * @return string The highlighted code with ANSI color codes. */ protected static function highlightSyntax(string $code): string { @@ -285,11 +256,6 @@ protected static function highlightSyntax(string $code): string /** * Formats and adds highlighted lines to create the final output. - * - * @param array $highlightedLines An array of highlighted code lines. - * @param int $lineBegin The starting line number. - * @param int $errorLine The line number with the error. - * @return string The formatted output with line numbers and ANSI colors. */ protected static function addLines(array $highlightedLines, int $lineBegin, int $errorLine): string { @@ -311,10 +277,7 @@ protected static function addLines(array $highlightedLines, int $lineBegin, int /** * Clears unnecessary code elements from the provided code. - * * Removes PHP opening tags and other unwanted code elements. - * @param string $code The code to be cleaned. - * @return string The code with unnecessary elements removed. */ protected static function clearCodeOutput(string $code): string { @@ -324,9 +287,6 @@ protected static function clearCodeOutput(string $code): string /** * Prints a formatted backtrace for display. - * - * @param array $backtrace An array containing the backtrace information. - * @return void */ protected static function printBacktrace(array $backtrace): void { @@ -341,10 +301,6 @@ protected static function printBacktrace(array $backtrace): void /** * Prints a formatted backtrace entry for display. - * - * @param int $i The index of the backtrace entry. - * @param array $error An array containing information about the backtrace entry. - * @return void */ protected static function printStackTraceEntryInfo(int $i, array $error): void { @@ -359,9 +315,6 @@ protected static function printStackTraceEntryInfo(int $i, array $error): void /** * Formats information about a function or method for display. - * - * @param array $error An array containing information about the error. - * @return string The formatted string representation of the function or method information. */ protected static function formatCallableInfo(array $error): string { @@ -383,7 +336,6 @@ protected static function formatCallableInfo(array $error): string * Formats a function argument for display. * * @param mixed $arg The argument to be formatted. - * @return string The formatted string representation of the argument. */ protected static function formatArgument($arg): string { @@ -400,9 +352,6 @@ protected static function formatArgument($arg): string /** * Formats an associative array for display. - * - * @param array $array The associative array to be formatted. - * @return string The formatted string representation of the array. */ protected static function formatArray(array $array): string { diff --git a/src/libraries/Console/Commands.php b/src/libraries/Console/Commands.php index 578359a..bb4f5bc 100644 --- a/src/libraries/Console/Commands.php +++ b/src/libraries/Console/Commands.php @@ -1,14 +1,17 @@ - * - * For the full copyright and license information, please view - * the LICENSE file that was distributed with this source code. + * Axm Framework PHP. + * + * Class Commands + * + * @author Juan Cristobal + * @link http://www.axm.com/ + * @license http://www.axm.com/license/ + * @package Console */ - namespace Console; use Console\CLI; @@ -28,18 +31,17 @@ class Commands * The found commands. * @var array */ - public $commands = []; + public $commands = []; private $classCache = []; private $cachedCommands = []; const COMMAND_EXTENSION = 'php'; /** * Constructor - * @param Logger|null $logger */ public function __construct() { - return $this->discoverCommands(); + $this->discoverCommands(); } /** @@ -58,7 +60,7 @@ public function run(string $command, array $params) // The file would have already been loaded during the // createCommandList function... $className = $this->commands[$command]['class']; - $class = new $className(); + $class = new $className(); return $class->run($params); } @@ -78,11 +80,13 @@ public function getCommands(): array */ protected function discoverCommands(): void { - if ($this->commands !== []) return; + if ($this->commands !== []) + return; - $commandsFolder = AXM_PATH; + $vendorCommandsFolder = VENDOR_PATH . DIRECTORY_SEPARATOR . 'axm' . DIRECTORY_SEPARATOR; $appCommandsFolder = config('paths.commandsPath') . DIRECTORY_SEPARATOR; + // Caching if ($cachedCommands = $this->loadCachedCommands()) { $this->commands = $cachedCommands; @@ -90,7 +94,7 @@ protected function discoverCommands(): void } // Create an array of directories to scan, including the vendor directory - $directoriesToScan = [$commandsFolder, $appCommandsFolder]; + $directoriesToScan = [$vendorCommandsFolder, $appCommandsFolder]; foreach ($directoriesToScan as $dir) { $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir)); @@ -113,11 +117,11 @@ protected function discoverCommands(): void /** @var BaseCommand $class */ $class = new $className(); - if (isset($class->group)) { + if (isset ($class->group)) { $this->commands[$class->name] = [ - 'class' => $className, - 'file' => $fileInfo->getPathname(), - 'group' => $class->group, + 'class' => $className, + 'file' => $fileInfo->getPathname(), + 'group' => $class->group, 'description' => $class->description, ]; } @@ -136,13 +140,12 @@ protected function discoverCommands(): void /** * loadCachedCommands - * @return void */ private function loadCachedCommands() { // Implement your caching logic to load from an array here // For example, if using a class property for caching: - if (isset($this->cachedCommands)) { + if (isset ($this->cachedCommands)) { return $this->cachedCommands; } @@ -166,7 +169,7 @@ private function saveCachedCommands($commands) private function getClassnameFromFile(string $filePath, bool $includeNamespace = true) { // Check if the result is cached - if (isset($this->classCache[$filePath][$includeNamespace])) { + if (isset ($this->classCache[$filePath][$includeNamespace])) { return $this->classCache[$filePath][$includeNamespace]; } @@ -207,11 +210,10 @@ private function getClassnameFromFile(string $filePath, bool $includeNamespace = */ public function verifyCommand(string $command, array $commands): bool { - if (isset($commands[$command])) { + if (isset ($commands[$command])) { return true; } - $command = $command; $message = "Command Not Found: [$command]"; if ($alternatives = $this->getCommandAlternatives($command, $commands)) { diff --git a/src/libraries/Console/ConsoleApplication.php b/src/libraries/Console/ConsoleApplication.php index 1b774cb..b70fc0e 100644 --- a/src/libraries/Console/ConsoleApplication.php +++ b/src/libraries/Console/ConsoleApplication.php @@ -1,7 +1,13 @@ - * - * For the full copyright and license information, please view - * the LICENSE file that was distributed with this source code. - */ +declare(strict_types=1); namespace Console; use Console\CLI; /** + * Axm Framework PHP. + * * GeneratorTrait contains a collection of methods * to build the commands that generates a file. + * + * @author Juan Cristobal + * @link http://www.axm.com/ + * @license http://www.axm.com/license/ + * @package Console */ + trait GeneratorTrait { /** @@ -127,7 +128,7 @@ protected function execute(array $params): void $path = $this->buildPath($this->className ?? $class); // Check if path is empty. - if (empty($path)) { + if (empty ($path)) { return; } @@ -136,7 +137,7 @@ protected function execute(array $params): void // Overwriting files unknowingly is a serious annoyance, So we'll check if // we are duplicating things, If 'force' option is not supplied, we bail. if (!$this->getOption('force') && $isFile) { - CLI::error(self::ARROW_SYMBOL . 'File exist: ' . realpath($path) . ' ❌ ', 'light_gray', 'red'); + CLI::error(self::ARROW_SYMBOL . 'File exist: ' . realpath($path) . ' ❌ ', 'light_gray'); CLI::newLine(); return; } @@ -152,7 +153,7 @@ protected function execute(array $params): void // Build the class based on the details we have, We'll be getting our file // contents from the template, and then we'll do the necessary replacements. if (!writeFile($path, $this->buildContent($class, $this->replace ?? [], $this->data ?? []))) { - CLI::error(self::ARROW_SYMBOL . 'File Error: ' . realpath($path) . ' ❌ ', 'light_gray', 'red'); + CLI::error(self::ARROW_SYMBOL . 'File Error: ' . realpath($path) . ' ❌ ', 'light_gray'); CLI::newLine(); return; } @@ -194,7 +195,7 @@ protected function qualifyClassName(): string if ($class === null && $this->hasClassName) { $nameLang = $this->classNameLang ?: ' Class name ❓'; - $class = CLI::prompt($nameLang, null, 'required'); + $class = CLI::prompt($nameLang, null, 'required'); CLI::newLine(); } @@ -234,7 +235,7 @@ protected function qualifyClassName(): string */ protected function renderTemplate(array $data = []): string { - $templatePath = (is_file($this->template)) ? $this->template : + $templatePath = (is_file($this->template)) ? $this->template : config('paths.consoleTemplatePath') . DIRECTORY_SEPARATOR . $this->template; $output = app()->view->file($templatePath, $data); @@ -285,7 +286,7 @@ protected function getNamespace($name) */ protected function buildContent(string $class, array $replace = [], array $data = []): string { - $template = $this->prepare($class, $replace, $data); + $template = $this->prepare($class, $replace, $data); if ($this->sortImports && preg_match('/(?P(?:^use [^;]+;$\n?)+)/m', $template, $match)) { $imports = explode(PHP_EOL, trim($match['imports'])); @@ -307,7 +308,7 @@ protected function buildPath(string $class): string // Check if the namespace is actually defined and we are not just typing gibberish. $base = [$namespace]; if (!$base = reset($base)) { - CLI::error(self::ARROW_SYMBOL . 'Namespace not defined: ' . $namespace . ' ❌ ', 'light_gray', 'red'); + CLI::error(self::ARROW_SYMBOL . 'Namespace not defined: ' . $namespace . ' ❌ ', 'light_gray'); CLI::newLine(); return ''; } diff --git a/src/libraries/Console/HelpConsole.php b/src/libraries/Console/HelpConsole.php index d8e0998..df449f5 100644 --- a/src/libraries/Console/HelpConsole.php +++ b/src/libraries/Console/HelpConsole.php @@ -1,21 +1,19 @@ - * - * For the full copyright and license information, please view - * the LICENSE file that was distributed with this source code. - */ - - use Console\BaseCommand; +use Console\BaseCommand; /** + * Axm Framework PHP. + * * CI Help command for the axm script. * * Lists the basic usage information for the axm script, * and provides a way to list help for other commands. + * + * @author Juan Cristobal + * @link http://www.axm.com/ + * @license http://www.axm.com/license/ + * @package Console */ class Help extends BaseCommand {