From a88d3823eba54ce1047569a2df5b787b06496ea8 Mon Sep 17 00:00:00 2001 From: Sleon4 Date: Tue, 8 Sep 2026 15:01:34 -0500 Subject: [PATCH 1/2] fix: The creation of .SH executables was fixed --- .../Commands/Lion/New/ControllerCommand.php | 8 +--- .../Commands/Lion/New/SHFileCommand.php | 46 +++++++++++-------- 2 files changed, 29 insertions(+), 25 deletions(-) diff --git a/src/LionBundle/Commands/Lion/New/ControllerCommand.php b/src/LionBundle/Commands/Lion/New/ControllerCommand.php index 018d8dd4..5c8c096d 100644 --- a/src/LionBundle/Commands/Lion/New/ControllerCommand.php +++ b/src/LionBundle/Commands/Lion/New/ControllerCommand.php @@ -39,16 +39,12 @@ class ControllerCommand extends Command ]; /** - * Controller path - * - * @const PATH_CONTROLLER + * Controller path. */ public const string PATH_CONTROLLER = 'app/Http/Controllers/'; /** - * Model path - * - * @const PATH_MODEL + * Model path. */ public const string PATH_MODEL = 'app/Models/'; diff --git a/src/LionBundle/Commands/Lion/New/SHFileCommand.php b/src/LionBundle/Commands/Lion/New/SHFileCommand.php index 36c0e64c..d63156d0 100644 --- a/src/LionBundle/Commands/Lion/New/SHFileCommand.php +++ b/src/LionBundle/Commands/Lion/New/SHFileCommand.php @@ -15,21 +15,25 @@ use Symfony\Component\Console\Output\OutputInterface; /** - * Generates a .sh file - * - * @package Lion\Bundle\Commands\Lion\New + * Generates a .sh file. */ class SHFileCommand extends Command { /** - * Fabricates the data provided to manipulate information (folder, class, namespace) + * SH path. + */ + public const string PATH_SH = 'storage/Sh/'; + + /** + * Fabricates the data provided to manipulate information (folder, class, + * namespace). * * @var ClassFactory $classFactory */ private ClassFactory $classFactory; /** - * Manipulate system files + * Manipulate system files. * * @var Store $store */ @@ -52,7 +56,7 @@ public function setStore(Store $store): SHFileCommand } /** - * Configures the current command + * Configures the current command. * * @return void */ @@ -60,42 +64,46 @@ protected function configure(): void { $this ->setName('new:sh') - ->setDescription('Command required to create files with sh extension') - ->addArgument('sh', InputArgument::OPTIONAL, 'SH name', 'Example'); + ->setDescription('Command required to create files with sh extension.') + ->addArgument('sh', InputArgument::OPTIONAL, '.sh file name.', 'example'); } /** - * Executes the current command + * Executes the current command. * * This method is not abstract because you can use this class as a concrete * class. In this case, instead of defining the execute() method, you set the - * code to execute by passing a Closure to the setCode() method + * code to execute by passing a Closure to the setCode() method. * * @param InputInterface $input InputInterface is the interface implemented by - * all input classes + * all input classes. * @param OutputInterface $output OutputInterface is the interface implemented - * by all Output classes + * by all Output classes. * * @return int * - * @throws Exception If the file could not be opened - * @throws LogicException When this abstract method is not implemented + * @throws Exception If the file could not be opened. + * @throws LogicException When this abstract method is not implemented. */ protected function execute(InputInterface $input, OutputInterface $output): int { /** @var string $sh */ $sh = $input->getArgument('sh'); - $this->store->folder('storage/sh/'); + $this->classFactory->classFactory(self::PATH_SH, $sh); + + $fileName = basename($sh); + + $folder = $this->classFactory->getFolder(); + + $this->store->folder($folder); $this->classFactory - ->create($sh, ClassFactory::SH_EXTENSION, 'storage/sh/') + ->create($fileName, ClassFactory::SH_EXTENSION, $folder) ->add("#!/bin/bash\n") ->close(); - chmod("storage/sh/{$sh}.sh", 0755); - - $output->writeln($this->warningOutput("\t>> SH: {$sh}")); + $output->writeln($this->warningOutput("\t>> SH: {$folder}{$fileName}." . ClassFactory::SH_EXTENSION)); $output->writeln($this->successOutput("\t>> SH: The script was generated successfully.")); From d0aa718a63bc9d61059dded13cb8b12cb1063b16 Mon Sep 17 00:00:00 2001 From: Sleon4 Date: Wed, 9 Sep 2026 08:42:38 -0500 Subject: [PATCH 2/2] test: Test coverage is added --- tests/Commands/Lion/SH/SHFileCommandTest.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/tests/Commands/Lion/SH/SHFileCommandTest.php b/tests/Commands/Lion/SH/SHFileCommandTest.php index e75551e8..01d3ef97 100644 --- a/tests/Commands/Lion/SH/SHFileCommandTest.php +++ b/tests/Commands/Lion/SH/SHFileCommandTest.php @@ -19,9 +19,8 @@ class SHFileCommandTest extends Test { - private const string URL_PATH = './storage/sh/'; private const string FILE_NAME = 'test-app'; - private const string FILE = self::URL_PATH . self::FILE_NAME . '.sh'; + private const string FILE = SHFileCommand::PATH_SH . self::FILE_NAME . '.sh'; private const string OUTPUT_MESSAGE = 'The script was generated successfully.'; private CommandTester $commandTester; @@ -45,14 +44,14 @@ protected function setUp(): void $this->commandTester = new CommandTester($application->find('new:sh')); - $this->createDirectory(self::URL_PATH); + $this->createDirectory(SHFileCommand::PATH_SH); $this->initReflection($this->shFileCommand); } protected function tearDown(): void { - $this->rmdirRecursively(self::URL_PATH); + $this->rmdirRecursively(SHFileCommand::PATH_SH); } /**