From 1bcf165be945f87672ce9496be22ed81b40e0f1d Mon Sep 17 00:00:00 2001 From: Abderrahim Darghal Belkacemi Date: Tue, 16 Jun 2026 13:28:41 +0200 Subject: [PATCH 01/12] refactor: safe functions and error preventing --- src/Utils.php | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/Utils.php b/src/Utils.php index aaf3e83..e74ffee 100644 --- a/src/Utils.php +++ b/src/Utils.php @@ -34,10 +34,40 @@ public static function createFolder(string $path): bool return false; } + public static function readFile(string $path): string|false + { + if (!file_exists($path)) { + self::echo("* ERROR: Archivo no encontrado: $path\n"); + return false; + } + + $content = file_get_contents($path); + if ($content === false) { + self::echo("* ERROR: Sin permisos de lectura: $path\n"); + return false; + } + + return $content; + } + + public static function writeFile(string $path, string $content): bool + { + if (false === file_put_contents($path, $content)) { + self::echo("* ERROR: No se pudo escribir: $path\n"); + return false; + } + + return true; + } + public static function findPluginName(): string { if (self::isPluginFolder()) { $ini = parse_ini_file('facturascripts.ini'); + if ($ini === false) { + self::echo("* WARNING: No se pudo leer facturascripts.ini.\n"); + return ''; + } return $ini['name'] ?? ''; } @@ -57,6 +87,10 @@ public static function getNamespace(): string if (self::isPluginFolder()) { $ini = parse_ini_file('facturascripts.ini'); + if ($ini === false) { + self::echo("* WARNING: No se pudo leer facturascripts.ini.\n"); + return ''; + } return 'Plugins\\' . ($ini['name'] ?? ''); } From c78a932177afa75988c121bc1b925e8e2d1f8a81 Mon Sep 17 00:00:00 2001 From: Abderrahim Darghal Belkacemi Date: Wed, 17 Jun 2026 09:12:08 +0200 Subject: [PATCH 02/12] refactor: unsafe operations with safe operations --- src/Command/Controller/ControllerCommand.php | 37 +++++++++++++----- src/Command/Cron/CronCommand.php | 9 ++++- src/Command/Cron/CronJobCommand.php | 24 +++++++++--- src/Command/Init/InitCommand.php | 9 ++++- src/Command/Migration/MigrationCommand.php | 12 ++++-- src/Command/Mod/ModCommand.php | 9 ++++- src/Command/Model/ModelCommand.php | 18 +++++++-- src/Command/Plugin/PluginCommand.php | 20 +++++++--- src/Command/Test/TestCommand.php | 9 ++++- src/Command/View/ViewCommand.php | 9 ++++- src/FileGenerator.php | 40 +++++++++++++------- src/ZipGenerator.php | 4 ++ 12 files changed, 148 insertions(+), 52 deletions(-) diff --git a/src/Command/Controller/ControllerCommand.php b/src/Command/Controller/ControllerCommand.php index 26cf428..a6011ac 100644 --- a/src/Command/Controller/ControllerCommand.php +++ b/src/Command/Controller/ControllerCommand.php @@ -98,7 +98,10 @@ private function createController(string $name): void ); $samplePath = dirname(__DIR__, 3) . "/samples/Controller.php.sample"; - $sample = file_get_contents($samplePath); + $sample = Utils::readFile($samplePath); + if ($sample === false) { + return; + } if (!$createView) { $search = "\n\n \$this->view('[[NAME]].html.twig');"; @@ -107,7 +110,9 @@ private function createController(string $name): void $template = str_replace(['[[NAME_SPACE]]', '[[NAME]]', '[[MENU]]'], [Utils::getNamespace(), $name, $menu], $sample); Utils::createFolder($filePath); - file_put_contents($fileName, $template); + if (!Utils::writeFile($fileName, $template)) { + return; + } Utils::echo('* ' . $fileName . " -> OK.\n"); if ($createView) { @@ -120,10 +125,14 @@ private function createController(string $name): void } $samplePath2 = dirname(__DIR__, 3) . "/samples/View.html.twig.sample"; - $sample2 = file_get_contents($samplePath2); + $sample2 = Utils::readFile($samplePath2); + if ($sample2 === false) { + return; + } $template2 = str_replace('[[NADA_A_REEMPLAZAR]]', $name, $sample2); - file_put_contents($viewFilename, $template2); - Utils::echo('* ' . $viewFilename . " -> OK.\n"); + if (Utils::writeFile($viewFilename, $template2)) { + Utils::echo('* ' . $viewFilename . " -> OK.\n"); + } } } @@ -152,13 +161,18 @@ private function createEditController(string $modelName, array $fields): void ); $samplePath = dirname(__DIR__, 3) . "/samples/EditController.php.sample"; - $sample = file_get_contents($samplePath); + $sample = Utils::readFile($samplePath); + if ($sample === false) { + return; + } $template = str_replace( ['[[NAME_SPACE]]', '[[MODEL_NAME]]', '[[MENU]]'], [Utils::getNamespace(), $modelName, $menu], $sample ); - file_put_contents($fileName, $template); + if (!Utils::writeFile($fileName, $template)) { + return; + } Utils::echo('* ' . $fileName . " -> OK.\n"); $xmlPath = Utils::isCoreFolder() ? 'Core/XMLView/' : 'XMLView/'; @@ -207,13 +221,18 @@ private function createListController(string $modelName, array $fields): void } $samplePath = dirname(__DIR__, 3) . "/samples/ListController.php.sample"; - $sample = file_get_contents($samplePath); + $sample = Utils::readFile($samplePath); + if ($sample === false) { + return; + } $template = str_replace( ['[[NAME_SPACE]]', '[[MODEL_NAME]]', '[[MENU]]', '[[TITLE]]'], [Utils::getNamespace(), $modelName, $menu, $title], $sample ); - file_put_contents($fileName, $template); + if (!Utils::writeFile($fileName, $template)) { + return; + } Utils::echo('* ' . $fileName . " -> OK.\n"); $xmlPath = Utils::isCoreFolder() ? 'Core/XMLView/' : 'XMLView/'; diff --git a/src/Command/Cron/CronCommand.php b/src/Command/Cron/CronCommand.php index 6e78695..b77aaa2 100644 --- a/src/Command/Cron/CronCommand.php +++ b/src/Command/Cron/CronCommand.php @@ -33,9 +33,14 @@ protected function execute(InputInterface $input, OutputInterface $output): int } $samplePath = dirname(__DIR__, 3) . "/samples/Cron.php.sample"; - $sample = file_get_contents($samplePath); + $sample = Utils::readFile($samplePath); + if ($sample === false) { + return Command::FAILURE; + } $template = str_replace(['[[NAME_SPACE]]', '[[NAME]]'], [Utils::getNamespace(), $name], $sample); - file_put_contents($fileName, $template); + if (!Utils::writeFile($fileName, $template)) { + return Command::FAILURE; + } Utils::echo('* ' . $fileName . " -> OK.\n"); return Command::SUCCESS; diff --git a/src/Command/Cron/CronJobCommand.php b/src/Command/Cron/CronJobCommand.php index bd35d21..a44e6a3 100644 --- a/src/Command/Cron/CronJobCommand.php +++ b/src/Command/Cron/CronJobCommand.php @@ -42,11 +42,16 @@ protected function execute(InputInterface $input, OutputInterface $output): int } $samplePath = dirname(__DIR__, 3) . "/samples/CronJob.php.sample"; - $sample = file_get_contents($samplePath); + $sample = Utils::readFile($samplePath); + if ($sample === false) { + return Command::FAILURE; + } $jobName = Utils::kebab($name); $template = str_replace(['[[NAME_SPACE]]', '[[NAME]]', '[[JOB_NAME]]'], [Utils::getNamespace(), $name, $jobName], $sample); - file_put_contents($fileName, $template); + if (!Utils::writeFile($fileName, $template)) { + return Command::FAILURE; + } Utils::echo('* ' . $fileName . " -> OK.\n"); if (file_exists('Cron.php')) { @@ -68,15 +73,22 @@ private function createCron(string $name): void } $samplePath = dirname(__DIR__, 3) . "/samples/Cron.php.sample"; - $sample = file_get_contents($samplePath); + $sample = Utils::readFile($samplePath); + if ($sample === false) { + return; + } $template = str_replace(['[[NAME_SPACE]]', '[[NAME]]'], [Utils::getNamespace(), $name], $sample); - file_put_contents($fileName, $template); - Utils::echo('* ' . $fileName . " -> OK.\n"); + if (Utils::writeFile($fileName, $template)) { + Utils::echo('* ' . $fileName . " -> OK.\n"); + } } private function updateCron(string $name): void { - $fileStr = file_get_contents('Cron.php'); + $fileStr = Utils::readFile('Cron.php'); + if ($fileStr === false) { + return; + } $newJob = <<job($name::JOB_NAME) diff --git a/src/Command/Init/InitCommand.php b/src/Command/Init/InitCommand.php index 28daff1..7ab51c8 100644 --- a/src/Command/Init/InitCommand.php +++ b/src/Command/Init/InitCommand.php @@ -31,9 +31,14 @@ protected function execute(InputInterface $input, OutputInterface $output): int } $samplePath = dirname(__DIR__, 3) . "/samples/Init.php.sample"; - $sample = file_get_contents($samplePath); + $sample = Utils::readFile($samplePath); + if ($sample === false) { + return Command::FAILURE; + } $template = str_replace('[[NAME]]', Utils::findPluginName(), $sample); - file_put_contents($fileName, $template); + if (!Utils::writeFile($fileName, $template)) { + return Command::FAILURE; + } Utils::echo('* ' . $fileName . " -> OK.\n"); return Command::SUCCESS; diff --git a/src/Command/Migration/MigrationCommand.php b/src/Command/Migration/MigrationCommand.php index ad090b2..7a5c279 100644 --- a/src/Command/Migration/MigrationCommand.php +++ b/src/Command/Migration/MigrationCommand.php @@ -50,16 +50,20 @@ private function createMigration(string $name): void } $samplePath = dirname(__DIR__, 3) . "/samples/Migration.php.sample"; - $sample = file_get_contents($samplePath); - + $sample = Utils::readFile($samplePath); + if ($sample === false) { + return; + } + $migrationNameConst = strtolower(preg_replace('/(? OK.\n"); + if (Utils::writeFile($fileName, $template)) { + Utils::echo('* ' . $fileName . " -> OK.\n"); + } $newContentUse = InitEditor::addUse('use FacturaScripts\Core\Migrations;'); if ($newContentUse) { diff --git a/src/Command/Mod/ModCommand.php b/src/Command/Mod/ModCommand.php index 2067e82..9b4365c 100644 --- a/src/Command/Mod/ModCommand.php +++ b/src/Command/Mod/ModCommand.php @@ -77,9 +77,14 @@ private function createMod(string $name, string $sampleName, string $useClass, s Utils::createFolder($dir); $samplePath = dirname(__DIR__, 3) . "/samples/" . $sampleName; - $sample = file_get_contents($samplePath); + $sample = Utils::readFile($samplePath); + if ($sample === false) { + return Command::FAILURE; + } $template = str_replace(['[[NAME_SPACE]]', '[[NAME]]'], [Utils::getNamespace(), $name], $sample); - file_put_contents($fileName, $template); + if (!Utils::writeFile($fileName, $template)) { + return Command::FAILURE; + } Utils::echo('* ' . $fileName . " -> OK.\n"); // Escribir en Init.php diff --git a/src/Command/Model/ModelCommand.php b/src/Command/Model/ModelCommand.php index ca964f9..b91cf60 100644 --- a/src/Command/Model/ModelCommand.php +++ b/src/Command/Model/ModelCommand.php @@ -104,13 +104,18 @@ private function createEditController(string $modelName, array $fields): void ); $samplePath = dirname(__DIR__, 3) . "/samples/EditController.php.sample"; - $sample = file_get_contents($samplePath); + $sample = Utils::readFile($samplePath); + if ($sample === false) { + return; + } $template = str_replace( ['[[NAME_SPACE]]', '[[MODEL_NAME]]', '[[MENU]]'], [Utils::getNamespace(), $modelName, $menu], $sample ); - file_put_contents($fileName, $template); + if (!Utils::writeFile($fileName, $template)) { + return; + } Utils::echo('* ' . $fileName . " -> OK.\n"); $xmlPath = Utils::isCoreFolder() ? 'Core/XMLView/' : 'XMLView/'; @@ -159,13 +164,18 @@ private function createListController(string $modelName, array $fields): void } $samplePath = dirname(__DIR__, 3) . "/samples/ListController.php.sample"; - $sample = file_get_contents($samplePath); + $sample = Utils::readFile($samplePath); + if ($sample === false) { + return; + } $template = str_replace( ['[[NAME_SPACE]]', '[[MODEL_NAME]]', '[[MENU]]', '[[TITLE]]'], [Utils::getNamespace(), $modelName, $menu, $title], $sample ); - file_put_contents($fileName, $template); + if (!Utils::writeFile($fileName, $template)) { + return; + } Utils::echo('* ' . $fileName . " -> OK.\n"); $xmlPath = Utils::isCoreFolder() ? 'Core/XMLView/' : 'XMLView/'; diff --git a/src/Command/Plugin/PluginCommand.php b/src/Command/Plugin/PluginCommand.php index 19c0030..7224447 100644 --- a/src/Command/Plugin/PluginCommand.php +++ b/src/Command/Plugin/PluginCommand.php @@ -73,10 +73,14 @@ private function createCron(string $name): void } $samplePath = dirname(__DIR__, 3) . "/samples/Cron.php.sample"; - $sample = file_get_contents($samplePath); + $sample = Utils::readFile($samplePath); + if ($sample === false) { + return; + } $template = str_replace(['[[NAME_SPACE]]', '[[NAME]]'], [Utils::getNamespace(), $name], $sample); - file_put_contents($fileName, $template); - Utils::echo('* ' . $fileName . " -> OK.\n"); + if (Utils::writeFile($fileName, $template)) { + Utils::echo('* ' . $fileName . " -> OK.\n"); + } } private function createInit(): void @@ -88,9 +92,13 @@ private function createInit(): void } $samplePath = dirname(__DIR__, 3) . "/samples/Init.php.sample"; - $sample = file_get_contents($samplePath); + $sample = Utils::readFile($samplePath); + if ($sample === false) { + return; + } $template = str_replace('[[NAME]]', Utils::findPluginName(), $sample); - file_put_contents($fileName, $template); - Utils::echo('* ' . $fileName . " -> OK.\n"); + if (Utils::writeFile($fileName, $template)) { + Utils::echo('* ' . $fileName . " -> OK.\n"); + } } } diff --git a/src/Command/Test/TestCommand.php b/src/Command/Test/TestCommand.php index b6fa02b..66cd829 100644 --- a/src/Command/Test/TestCommand.php +++ b/src/Command/Test/TestCommand.php @@ -50,10 +50,15 @@ protected function execute(InputInterface $input, OutputInterface $output): int } $samplePath = dirname(__DIR__, 3) . "/samples/Test.php.sample"; - $sample = file_get_contents($samplePath); + $sample = Utils::readFile($samplePath); + if ($sample === false) { + return Command::FAILURE; + } $nameSpace = Utils::getNamespace() . '\\' . str_replace('/', '\\', substr($filePath, 0, -1)); $template = str_replace(['[[NAME_SPACE]]', '[[NAME]]'], [$nameSpace, $name], $sample); - file_put_contents($fileName, $template); + if (!Utils::writeFile($fileName, $template)) { + return Command::FAILURE; + } Utils::echo('* ' . $fileName . " -> OK.\n"); return Command::SUCCESS; diff --git a/src/Command/View/ViewCommand.php b/src/Command/View/ViewCommand.php index 5ec0fef..50cf6f5 100644 --- a/src/Command/View/ViewCommand.php +++ b/src/Command/View/ViewCommand.php @@ -65,9 +65,14 @@ private function createView(string $name): int } $samplePath = dirname(__DIR__, 3) . "/samples/View.html.twig.sample"; - $sample = file_get_contents($samplePath); + $sample = Utils::readFile($samplePath); + if ($sample === false) { + return Command::FAILURE; + } - file_put_contents($fileName, $sample); + if (!Utils::writeFile($fileName, $sample)) { + return Command::FAILURE; + } Utils::echo('* ' . $fileName . " -> OK.\n"); diff --git a/src/FileGenerator.php b/src/FileGenerator.php index 25ff1e3..86a7207 100644 --- a/src/FileGenerator.php +++ b/src/FileGenerator.php @@ -26,8 +26,11 @@ public static function createGithubActionRelease(): void return; } - $template = file_get_contents(__DIR__ . '/../samples/github-action-release.yml.sample'); - if (file_put_contents($filePath, $template)) { + $template = Utils::readFile(__DIR__ . '/../samples/github-action-release.yml.sample'); + if ($template === false) { + return; + } + if (Utils::writeFile($filePath, $template)) { Utils::echo('* ' . $filePath . self::OK); } } @@ -56,9 +59,12 @@ public static function createGithubActionTest(): void return; } - $template = file_get_contents(__DIR__ . '/../samples/github-action-test.yml.sample'); + $template = Utils::readFile(__DIR__ . '/../samples/github-action-test.yml.sample'); + if ($template === false) { + return; + } $content = str_replace('$$NOMBRE-DEL-PLUGIN$$', $pluginName, $template); - if (file_put_contents($filePath, $content)) { + if (Utils::writeFile($filePath, $content)) { Utils::echo('* ' . $filePath . self::OK); } } @@ -71,9 +77,13 @@ public static function createGitIgnore(): void return; } - $template = file_get_contents(__DIR__ . "/../samples/gitignore.sample"); - file_put_contents($fileName, $template); - Utils::echo('* ' . $fileName . self::OK); + $template = Utils::readFile(__DIR__ . "/../samples/gitignore.sample"); + if ($template === false) { + return; + } + if (Utils::writeFile($fileName, $template)) { + Utils::echo('* ' . $fileName . self::OK); + } } public static function createIni(string $name): void @@ -84,10 +94,14 @@ public static function createIni(string $name): void return; } - $sample = file_get_contents(__DIR__ . "/../samples/facturascripts.ini.sample"); + $sample = Utils::readFile(__DIR__ . "/../samples/facturascripts.ini.sample"); + if ($sample === false) { + return; + } $template = str_replace('[[NAME]]', $name, $sample); - file_put_contents($fileName, $template); - Utils::echo('* ' . $fileName . self::OK); + if (Utils::writeFile($fileName, $template)) { + Utils::echo('* ' . $fileName . self::OK); + } } /** @@ -157,7 +171,7 @@ public static function createModelByFields(string $fileName, string $tableName, $sample .= "}\n"; - file_put_contents($fileName, $sample); + Utils::writeFile($fileName, $sample); } /** @@ -178,7 +192,7 @@ public static function createTableXmlByFields(string $tableFilename, string $tab $sample = '' . "\n" . "\n" . $columns . $constraints . "
"; - file_put_contents($tableFilename, $sample); + Utils::writeFile($tableFilename, $sample); } /** @@ -247,6 +261,6 @@ public static function createXMLViewByFields(string $xmlFilename, array $fields, $sample .= " \n" . ""; - file_put_contents($xmlFilename, $sample); + Utils::writeFile($xmlFilename, $sample); } } diff --git a/src/ZipGenerator.php b/src/ZipGenerator.php index eb13f5d..8773f85 100644 --- a/src/ZipGenerator.php +++ b/src/ZipGenerator.php @@ -19,6 +19,10 @@ public static function generate(): void } $ini = parse_ini_file('facturascripts.ini'); + if ($ini === false) { + Utils::echo("* No se pudo leer facturascripts.ini.\n"); + return; + } $pluginName = $ini['name'] ?? ''; if (empty($pluginName)) { Utils::echo("* No se ha encontrado el nombre del plugin.\n"); From d23731abed6ec27ae064ab1dd199c99c7efe8a9c Mon Sep 17 00:00:00 2001 From: Abderrahim Darghal Belkacemi Date: Wed, 17 Jun 2026 09:20:11 +0200 Subject: [PATCH 03/12] refactor: unsafe operations with safe operations --- src/Command/Worker/WorkerCommand.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Command/Worker/WorkerCommand.php b/src/Command/Worker/WorkerCommand.php index f3eec41..4e36849 100644 --- a/src/Command/Worker/WorkerCommand.php +++ b/src/Command/Worker/WorkerCommand.php @@ -45,9 +45,14 @@ protected function execute(InputInterface $input, OutputInterface $output): int } $samplePath = dirname(__DIR__, 3) . "/samples/Worker.php.sample"; - $sample = file_get_contents($samplePath); + $sample = Utils::readFile($samplePath); + if ($sample === false) { + return Command::FAILURE; + } $template = str_replace(['[[NAME_SPACE]]', '[[NAME]]'], [Utils::getNamespace(), $name], $sample); - file_put_contents($fileName, $template); + if (!Utils::writeFile($fileName, $template)) { + return Command::FAILURE; + } Utils::echo('* ' . $fileName . " -> OK.\n"); $options = multiselect( From 66fa67f4f2272f698eb2becb21374b9f98b4f797 Mon Sep 17 00:00:00 2001 From: Abderrahim Darghal Belkacemi Date: Wed, 17 Jun 2026 09:20:41 +0200 Subject: [PATCH 04/12] feat: safe ini file --- src/Utils.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/Utils.php b/src/Utils.php index e74ffee..7f10a5c 100644 --- a/src/Utils.php +++ b/src/Utils.php @@ -60,6 +60,22 @@ public static function writeFile(string $path, string $content): bool return true; } + public static function parseIniFile(string $path): array|false + { + if (!file_exists($path)) { + self::echo("* ERROR: Archivo no encontrado: $path\n"); + return false; + } + + $ini = parse_ini_file($path); + if ($ini === false) { + self::echo("* ERROR: No se pudo leer o parsear: $path\n"); + return false; + } + + return $ini; + } + public static function findPluginName(): string { if (self::isPluginFolder()) { From 537fd55560f419c4c16c5c559ecd8a61dbbc0c0b Mon Sep 17 00:00:00 2001 From: Abderrahim Darghal Belkacemi Date: Wed, 17 Jun 2026 09:40:52 +0200 Subject: [PATCH 05/12] refactor: implement safe read ini file --- src/UpdateTranslations.php | 5 ++++- src/Utils.php | 6 ++---- src/ZipGenerator.php | 3 +-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/UpdateTranslations.php b/src/UpdateTranslations.php index 67b21ff..5dfccb7 100644 --- a/src/UpdateTranslations.php +++ b/src/UpdateTranslations.php @@ -25,7 +25,10 @@ public static function run(): void if (Utils::isPluginFolder()) { $folder = 'Translation/'; Utils::createFolder($folder); - $ini = parse_ini_file('facturascripts.ini'); + $ini = Utils::parseIniFile('facturascripts.ini'); + if ($ini === false) { + return; + } $project = $ini['name'] ?? ''; } elseif (Utils::isCoreFolder()) { $folder = 'Core/Translation/'; diff --git a/src/Utils.php b/src/Utils.php index 7f10a5c..0abd4e5 100644 --- a/src/Utils.php +++ b/src/Utils.php @@ -79,9 +79,8 @@ public static function parseIniFile(string $path): array|false public static function findPluginName(): string { if (self::isPluginFolder()) { - $ini = parse_ini_file('facturascripts.ini'); + $ini = self::parseIniFile('facturascripts.ini'); if ($ini === false) { - self::echo("* WARNING: No se pudo leer facturascripts.ini.\n"); return ''; } return $ini['name'] ?? ''; @@ -102,9 +101,8 @@ public static function getNamespace(): string } if (self::isPluginFolder()) { - $ini = parse_ini_file('facturascripts.ini'); + $ini = self::parseIniFile('facturascripts.ini'); if ($ini === false) { - self::echo("* WARNING: No se pudo leer facturascripts.ini.\n"); return ''; } return 'Plugins\\' . ($ini['name'] ?? ''); diff --git a/src/ZipGenerator.php b/src/ZipGenerator.php index 8773f85..6b457e7 100644 --- a/src/ZipGenerator.php +++ b/src/ZipGenerator.php @@ -18,9 +18,8 @@ public static function generate(): void return; } - $ini = parse_ini_file('facturascripts.ini'); + $ini = Utils::parseIniFile('facturascripts.ini'); if ($ini === false) { - Utils::echo("* No se pudo leer facturascripts.ini.\n"); return; } $pluginName = $ini['name'] ?? ''; From fbdb5852972da3313cf35be339a4fbe2c4e783e4 Mon Sep 17 00:00:00 2001 From: Abderrahim Darghal Belkacemi Date: Wed, 17 Jun 2026 09:41:25 +0200 Subject: [PATCH 06/12] refactor: safe scandir --- src/RunTests.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/RunTests.php b/src/RunTests.php index e291dbb..3d1a439 100644 --- a/src/RunTests.php +++ b/src/RunTests.php @@ -86,8 +86,13 @@ public static function run(?string $fs_folder = null): void } $foundTests = false; + $testEntries = scandir('Test/'); + if ($testEntries === false) { + Utils::echo("* No se pudo leer la carpeta Test/.\n"); + return; + } // recorremos las carpetas dentro de Test - foreach (scandir('Test/') as $item) { + foreach ($testEntries as $item) { if ($item === '.' || $item === '..') { continue; } From 7b66cca822c1adb57744895be575266fe49cd415 Mon Sep 17 00:00:00 2001 From: Abderrahim Darghal Belkacemi Date: Wed, 17 Jun 2026 11:30:08 +0200 Subject: [PATCH 07/12] refactor: create translations function --- src/UpdateTranslations.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/UpdateTranslations.php b/src/UpdateTranslations.php index 5dfccb7..eee18ab 100644 --- a/src/UpdateTranslations.php +++ b/src/UpdateTranslations.php @@ -11,12 +11,14 @@ class UpdateTranslations public static function create(string $name): void { + if (!Utils::createFolder($name . '/Translation')) { + return; + } foreach (explode(',', self::TRANSLATIONS) as $filename) { - file_put_contents( - $name . '/Translation/' . $filename . '.json', - '{"' . strtolower($name) . '": "' . $name . '"}' - ); - Utils::echo('* ' . $name . '/Translation/' . $filename . ".json -> OK.\n"); + $path = $name . '/Translation/' . $filename . '.json'; + if (Utils::writeFile($path, '{"' . strtolower($name) . '": "' . $name . '"}')) { + Utils::echo('* ' . $path . " -> OK.\n"); + } } } From 4e97946f675af696b4a769ba37247e087448576f Mon Sep 17 00:00:00 2001 From: Abderrahim Darghal Belkacemi Date: Wed, 17 Jun 2026 11:30:44 +0200 Subject: [PATCH 08/12] refactor: get translation request error handling --- src/UpdateTranslations.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/UpdateTranslations.php b/src/UpdateTranslations.php index eee18ab..98d78ee 100644 --- a/src/UpdateTranslations.php +++ b/src/UpdateTranslations.php @@ -47,6 +47,7 @@ public static function run(): void } // descargamos el json de facturascripts.com + $errores = 0; foreach (explode(',', self::TRANSLATIONS) as $filename) { // esperamos medio segundo entre peticiones usleep(500000); @@ -54,13 +55,21 @@ public static function run(): void Utils::echo("D " . $folder . $filename . ".json"); $url = "https://facturascripts.com/EditLanguage?action=json&project=" . $project . "&code=" . $filename; $json = file_get_contents($url); + if ($json === false) { + Utils::echo(" - ERROR de red\n"); + $errores++; + continue; + } if (!empty($json) && strlen($json) > 10) { - file_put_contents($folder . $filename . '.json', $json); + Utils::writeFile($folder . $filename . '.json', $json); Utils::echo("\n"); continue; } Utils::echo(" - vacío\n"); } + if ($errores > 0) { + Utils::echo("* $errores traducciones no se pudieron descargar.\n"); + } } } From e58a6f5472ad67f76a7b5e1b30825e2829ca3926 Mon Sep 17 00:00:00 2001 From: Abderrahim Darghal Belkacemi Date: Wed, 17 Jun 2026 11:45:49 +0200 Subject: [PATCH 09/12] refactor: safe file operations --- src/Command/Test/TestCommand.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Command/Test/TestCommand.php b/src/Command/Test/TestCommand.php index 66cd829..11e6527 100644 --- a/src/Command/Test/TestCommand.php +++ b/src/Command/Test/TestCommand.php @@ -44,8 +44,13 @@ protected function execute(InputInterface $input, OutputInterface $output): int $txtFile = $filePath . 'install-plugins.txt'; if (false === file_exists($txtFile)) { // Creamos el fichero install-plugins.txt con el nombre del plugin - $ini = parse_ini_file('facturascripts.ini'); - file_put_contents($txtFile, $ini['name'] ?? ''); + $ini = Utils::parseIniFile('facturascripts.ini'); + if ($ini === false) { + return Command::FAILURE; + } + if (!Utils::writeFile($txtFile, $ini['name'] ?? '')) { + return Command::FAILURE; + } Utils::echo('* ' . $txtFile . " -> OK.\n"); } From 78bf0b57a60ee924815df5d1e8407e98125a83eb Mon Sep 17 00:00:00 2001 From: Abderrahim Darghal Belkacemi Date: Wed, 17 Jun 2026 12:28:45 +0200 Subject: [PATCH 10/12] refactor: more handling read file failure --- src/ApiGenerator.php | 13 ++++++++++--- src/Command/Controller/ControllerCommand.php | 9 +++------ src/Command/Cron/CronJobCommand.php | 12 +++++++++--- src/Command/Mod/ModCommand.php | 4 +++- src/Command/Test/TestCommand.php | 4 +++- src/Command/View/ViewCommand.php | 4 +++- src/Command/Worker/WorkerCommand.php | 4 +++- src/UpdateTranslations.php | 12 +++++++++--- 8 files changed, 43 insertions(+), 19 deletions(-) diff --git a/src/ApiGenerator.php b/src/ApiGenerator.php index 5422403..db4e7c5 100644 --- a/src/ApiGenerator.php +++ b/src/ApiGenerator.php @@ -38,10 +38,17 @@ public static function generate(): void errorMessage: 'Inválido, debe comenzar con /api/3/ y tener solo letras, números, guiones o barras.' ); - $sample = file_get_contents(dirname(__DIR__, 1) . "/samples/ApiController.php.sample"); + $sample = Utils::readFile(dirname(__DIR__, 1) . "/samples/ApiController.php.sample"); + if ($sample === false) { + return; + } $template = str_replace(['[[NAME_SPACE]]', '[[NAME]]'], [Utils::getNamespace(), $name], $sample); - Utils::createFolder('Controller'); - file_put_contents($file_path, $template); + if (false === Utils::createFolder('Controller')) { + return; + } + if (!Utils::writeFile($file_path, $template)) { + return; + } Utils::echo('* ' . $file_path . " -> OK.\n"); $use = "use FacturaScripts\Core\Controller\ApiRoot;\n" diff --git a/src/Command/Controller/ControllerCommand.php b/src/Command/Controller/ControllerCommand.php index a6011ac..85ebb36 100644 --- a/src/Command/Controller/ControllerCommand.php +++ b/src/Command/Controller/ControllerCommand.php @@ -52,18 +52,15 @@ protected function execute(InputInterface $input, OutputInterface $output): int switch ($option) { case 'Controller': - $this->createController($modelName); - return Command::SUCCESS; + return $this->createController($modelName) ? Command::SUCCESS : Command::FAILURE; case 'ListController': $fields = Column::askMulti(); - $this->createListController($modelName, $fields); - return Command::SUCCESS; + return $this->createListController($modelName, $fields) ? Command::SUCCESS : Command::FAILURE; case 'EditController': $fields = Column::askMulti(); - $this->createEditController($modelName, $fields); - return Command::SUCCESS; + return $this->createEditController($modelName, $fields) ? Command::SUCCESS : Command::FAILURE; } Utils::echo("Opción no válida.\n"); diff --git a/src/Command/Cron/CronJobCommand.php b/src/Command/Cron/CronJobCommand.php index a44e6a3..48dcb91 100644 --- a/src/Command/Cron/CronJobCommand.php +++ b/src/Command/Cron/CronJobCommand.php @@ -33,7 +33,9 @@ protected function execute(InputInterface $input, OutputInterface $output): int $folder = 'CronJob/'; $plugin = Utils::findPluginName(); - Utils::createFolder($folder); + if (false === Utils::createFolder($folder)) { + return Command::FAILURE; + } $fileName = $folder . $name . '.php'; if (file_exists($fileName)) { @@ -104,11 +106,15 @@ private function updateCron(string $name): void if ($position !== false) { $position = strpos($fileStr, '{', $position) + 1; $fileStr = substr_replace($fileStr, $newJob, $position, 0); - file_put_contents('Cron.php', $fileStr); + if (!Utils::writeFile('Cron.php', $fileStr)) { + return; + } $usePosition = strpos($fileStr, 'use FacturaScripts\Core\Template\CronClass'); $usePosition = strpos($fileStr, ';', $usePosition) + 1; $fileStr = substr_replace($fileStr, "\nuse FacturaScripts\\$nameSpace\CronJob\\$name;", $usePosition, 0); - file_put_contents('Cron.php', $fileStr); + if (!Utils::writeFile('Cron.php', $fileStr)) { + return; + } Utils::echo('* Cron.php actualizado' . " -> OK.\n"); } } diff --git a/src/Command/Mod/ModCommand.php b/src/Command/Mod/ModCommand.php index 9b4365c..3a501d1 100644 --- a/src/Command/Mod/ModCommand.php +++ b/src/Command/Mod/ModCommand.php @@ -74,7 +74,9 @@ private function createMod(string $name, string $sampleName, string $useClass, s return Command::FAILURE; } - Utils::createFolder($dir); + if (false === Utils::createFolder($dir)) { + return Command::FAILURE; + } $samplePath = dirname(__DIR__, 3) . "/samples/" . $sampleName; $sample = Utils::readFile($samplePath); diff --git a/src/Command/Test/TestCommand.php b/src/Command/Test/TestCommand.php index 11e6527..aedba40 100644 --- a/src/Command/Test/TestCommand.php +++ b/src/Command/Test/TestCommand.php @@ -35,7 +35,9 @@ protected function execute(InputInterface $input, OutputInterface $output): int $filePath = 'Test/main/'; $fileName = $filePath . $name . '.php'; - Utils::createFolder($filePath); + if (false === Utils::createFolder($filePath)) { + return Command::FAILURE; + } if (file_exists($fileName)) { Utils::echo("* El test " . $name . " YA EXISTE.\n"); return Command::FAILURE; diff --git a/src/Command/View/ViewCommand.php b/src/Command/View/ViewCommand.php index 50cf6f5..0131634 100644 --- a/src/Command/View/ViewCommand.php +++ b/src/Command/View/ViewCommand.php @@ -57,7 +57,9 @@ private function createView(string $name): int $fileName = $viewPath . $name . '.html.twig'; - Utils::createFolder($viewPath); + if (false === Utils::createFolder($viewPath)) { + return Command::FAILURE; + } if (file_exists($fileName)) { Utils::echo("* La vista " . $fileName . " YA EXISTE.\n"); diff --git a/src/Command/Worker/WorkerCommand.php b/src/Command/Worker/WorkerCommand.php index 4e36849..8b4bbc6 100644 --- a/src/Command/Worker/WorkerCommand.php +++ b/src/Command/Worker/WorkerCommand.php @@ -38,7 +38,9 @@ protected function execute(InputInterface $input, OutputInterface $output): int $filePath = 'Worker/'; $fileName = $filePath . $name . '.php'; - Utils::createFolder($filePath); + if (false === Utils::createFolder($filePath)) { + return Command::FAILURE; + } if (file_exists($fileName)) { Utils::echo("* El worker " . $name . " YA EXISTE.\n"); return Command::FAILURE; diff --git a/src/UpdateTranslations.php b/src/UpdateTranslations.php index 98d78ee..f0e9108 100644 --- a/src/UpdateTranslations.php +++ b/src/UpdateTranslations.php @@ -26,7 +26,9 @@ public static function run(): void { if (Utils::isPluginFolder()) { $folder = 'Translation/'; - Utils::createFolder($folder); + if (false === Utils::createFolder($folder)) { + return; + } $ini = Utils::parseIniFile('facturascripts.ini'); if ($ini === false) { return; @@ -34,7 +36,9 @@ public static function run(): void $project = $ini['name'] ?? ''; } elseif (Utils::isCoreFolder()) { $folder = 'Core/Translation/'; - Utils::createFolder($folder); + if (false === Utils::createFolder($folder)) { + return; + } $project = 'CORE'; } else { Utils::echo("* Esta no es la carpeta raíz del plugin.\n"); @@ -61,7 +65,9 @@ public static function run(): void continue; } if (!empty($json) && strlen($json) > 10) { - Utils::writeFile($folder . $filename . '.json', $json); + if (!Utils::writeFile($folder . $filename . '.json', $json)) { + $errores++; + } Utils::echo("\n"); continue; } From 0124b4bbededdf5eab189688915e322ac1deb1b3 Mon Sep 17 00:00:00 2001 From: Abderrahim Darghal Belkacemi Date: Wed, 17 Jun 2026 12:29:41 +0200 Subject: [PATCH 11/12] feat: FileGenerator return if operation success --- src/FileGenerator.php | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/FileGenerator.php b/src/FileGenerator.php index 86a7207..18c3bcf 100644 --- a/src/FileGenerator.php +++ b/src/FileGenerator.php @@ -110,9 +110,9 @@ public static function createIni(string $name): void * @param Column[] $fields * @param string $name * @param string $namespace - * @return void + * @return bool */ - public static function createModelByFields(string $fileName, string $tableName, array $fields, string $name, string $namespace): void + public static function createModelByFields(string $fileName, string $tableName, array $fields, string $name, string $namespace): bool { $properties = ''; $primaryColumn = ''; @@ -171,16 +171,16 @@ public static function createModelByFields(string $fileName, string $tableName, $sample .= "}\n"; - Utils::writeFile($fileName, $sample); + return Utils::writeFile($fileName, $sample); } /** * @param string $tableFilename * @param string $tableName * @param Column[] $fields - * @return void + * @return bool */ - public static function createTableXmlByFields(string $tableFilename, string $tableName, array $fields): void + public static function createTableXmlByFields(string $tableFilename, string $tableName, array $fields): bool { $columns = ''; $constraints = ''; @@ -192,7 +192,7 @@ public static function createTableXmlByFields(string $tableFilename, string $tab $sample = '' . "\n" . "\n" . $columns . $constraints . "
"; - Utils::writeFile($tableFilename, $sample); + return Utils::writeFile($tableFilename, $sample); } /** @@ -200,9 +200,9 @@ public static function createTableXmlByFields(string $tableFilename, string $tab * @param Column[] $fields * @param string $type * @param bool $extension - * @return void + * @return bool */ - public static function createXMLViewByFields(string $xmlFilename, array $fields, string $type, bool $extension = false): void + public static function createXMLViewByFields(string $xmlFilename, array $fields, string $type, bool $extension = false): bool { if (empty($fields)) { $fields = Column::askMulti($extension); @@ -255,12 +255,12 @@ public static function createXMLViewByFields(string $xmlFilename, array $fields, break; default: // No es ninguna de las opciones de antes - return; + return false; } $sample .= " \n" . ""; - Utils::writeFile($xmlFilename, $sample); + return Utils::writeFile($xmlFilename, $sample); } } From 84ee1cc0bb433d8b3b19ef683145bd428250e7fe Mon Sep 17 00:00:00 2001 From: Abderrahim Darghal Belkacemi Date: Wed, 17 Jun 2026 12:40:30 +0200 Subject: [PATCH 12/12] refactor: more handling --- src/Command/Controller/ControllerCommand.php | 81 +++++++++++++------- src/Command/Migration/MigrationCommand.php | 21 ++--- src/Command/Model/ModelCommand.php | 16 +++- 3 files changed, 76 insertions(+), 42 deletions(-) diff --git a/src/Command/Controller/ControllerCommand.php b/src/Command/Controller/ControllerCommand.php index 85ebb36..8d4d3c8 100644 --- a/src/Command/Controller/ControllerCommand.php +++ b/src/Command/Controller/ControllerCommand.php @@ -67,18 +67,18 @@ protected function execute(InputInterface $input, OutputInterface $output): int return Command::FAILURE; } - private function createController(string $name): void + private function createController(string $name): bool { if (empty($name)) { Utils::echo("* No introdujo el nombre del controlador.\n"); - return; + return false; } $filePath = Utils::isCoreFolder() ? 'Core/Controller/' : 'Controller/'; $fileName = $filePath . $name . '.php'; if (file_exists($fileName)) { Utils::echo("* El controlador " . $name . " YA EXISTE.\n"); - return; + return false; } $menu = text( @@ -97,7 +97,7 @@ private function createController(string $name): void $samplePath = dirname(__DIR__, 3) . "/samples/Controller.php.sample"; $sample = Utils::readFile($samplePath); if ($sample === false) { - return; + return false; } if (!$createView) { @@ -106,46 +106,55 @@ private function createController(string $name): void } $template = str_replace(['[[NAME_SPACE]]', '[[NAME]]', '[[MENU]]'], [Utils::getNamespace(), $name, $menu], $sample); - Utils::createFolder($filePath); + if (false === Utils::createFolder($filePath)) { + return false; + } if (!Utils::writeFile($fileName, $template)) { - return; + return false; } Utils::echo('* ' . $fileName . " -> OK.\n"); if ($createView) { $viewPath = Utils::isCoreFolder() ? 'Core/View/' : 'View/'; $viewFilename = $viewPath . $name . '.html.twig'; - Utils::createFolder($viewPath); + if (false === Utils::createFolder($viewPath)) { + return false; + } if (file_exists($viewFilename)) { Utils::echo('* ' . $viewFilename . " YA EXISTE.\n"); - return; + return true; } $samplePath2 = dirname(__DIR__, 3) . "/samples/View.html.twig.sample"; $sample2 = Utils::readFile($samplePath2); if ($sample2 === false) { - return; + return false; } $template2 = str_replace('[[NADA_A_REEMPLAZAR]]', $name, $sample2); - if (Utils::writeFile($viewFilename, $template2)) { - Utils::echo('* ' . $viewFilename . " -> OK.\n"); + if (!Utils::writeFile($viewFilename, $template2)) { + return false; } + Utils::echo('* ' . $viewFilename . " -> OK.\n"); } + + return true; } - private function createEditController(string $modelName, array $fields): void + private function createEditController(string $modelName, array $fields): bool { if (empty($modelName)) { Utils::echo('* No introdujo el nombre del EditController'); - return; + return false; } $filePath = Utils::isCoreFolder() ? 'Core/Controller/' : 'Controller/'; $fileName = $filePath . 'Edit' . $modelName . '.php'; - Utils::createFolder($filePath); + if (false === Utils::createFolder($filePath)) { + return false; + } if (file_exists($fileName)) { Utils::echo("El controlador " . $fileName . " YA EXISTE.\n"); - return; + return false; } $menu = text( @@ -160,7 +169,7 @@ private function createEditController(string $modelName, array $fields): void $samplePath = dirname(__DIR__, 3) . "/samples/EditController.php.sample"; $sample = Utils::readFile($samplePath); if ($sample === false) { - return; + return false; } $template = str_replace( ['[[NAME_SPACE]]', '[[MODEL_NAME]]', '[[MENU]]'], @@ -168,27 +177,33 @@ private function createEditController(string $modelName, array $fields): void $sample ); if (!Utils::writeFile($fileName, $template)) { - return; + return false; } Utils::echo('* ' . $fileName . " -> OK.\n"); $xmlPath = Utils::isCoreFolder() ? 'Core/XMLView/' : 'XMLView/'; $xmlFilename = $xmlPath . 'Edit' . $modelName . '.xml'; - Utils::createFolder($xmlPath); + if (false === Utils::createFolder($xmlPath)) { + return false; + } if (file_exists($xmlFilename)) { Utils::echo('* ' . $xmlFilename . " YA EXISTE\n"); - return; + return true; } - FileGenerator::createXMLViewByFields($xmlFilename, $fields, 'edit'); + if (!FileGenerator::createXMLViewByFields($xmlFilename, $fields, 'edit')) { + return false; + } Utils::echo('* ' . $xmlFilename . " -> OK.\n"); + + return true; } - private function createListController(string $modelName, array $fields): void + private function createListController(string $modelName, array $fields): bool { if (empty($modelName)) { Utils::echo('* No introdujo el nombre del ListController'); - return; + return false; } $menu = text( @@ -211,16 +226,18 @@ private function createListController(string $modelName, array $fields): void $filePath = Utils::isCoreFolder() ? 'Core/Controller/' : 'Controller/'; $fileName = $filePath . 'List' . $modelName . '.php'; - Utils::createFolder($filePath); + if (false === Utils::createFolder($filePath)) { + return false; + } if (file_exists($fileName)) { Utils::echo("El controlador " . $fileName . " YA EXISTE.\n"); - return; + return false; } $samplePath = dirname(__DIR__, 3) . "/samples/ListController.php.sample"; $sample = Utils::readFile($samplePath); if ($sample === false) { - return; + return false; } $template = str_replace( ['[[NAME_SPACE]]', '[[MODEL_NAME]]', '[[MENU]]', '[[TITLE]]'], @@ -228,19 +245,25 @@ private function createListController(string $modelName, array $fields): void $sample ); if (!Utils::writeFile($fileName, $template)) { - return; + return false; } Utils::echo('* ' . $fileName . " -> OK.\n"); $xmlPath = Utils::isCoreFolder() ? 'Core/XMLView/' : 'XMLView/'; $xmlFilename = $xmlPath . 'List' . $modelName . '.xml'; - Utils::createFolder($xmlPath); + if (false === Utils::createFolder($xmlPath)) { + return false; + } if (file_exists($xmlFilename)) { Utils::echo('* ' . $xmlFilename . " YA EXISTE\n"); - return; + return true; } - FileGenerator::createXMLViewByFields($xmlFilename, $fields, 'list'); + if (!FileGenerator::createXMLViewByFields($xmlFilename, $fields, 'list')) { + return false; + } Utils::echo('* ' . $xmlFilename . " -> OK.\n"); + + return true; } } diff --git a/src/Command/Migration/MigrationCommand.php b/src/Command/Migration/MigrationCommand.php index 7a5c279..b48933d 100644 --- a/src/Command/Migration/MigrationCommand.php +++ b/src/Command/Migration/MigrationCommand.php @@ -33,26 +33,26 @@ protected function execute(InputInterface $input, OutputInterface $output): int errorMessage: 'Inválido, debe empezar por mayúscula y solo puede contener letras, números y guiones bajos.' ); - $this->createMigration($name); - - return Command::SUCCESS; + return $this->createMigration($name) ? Command::SUCCESS : Command::FAILURE; } - private function createMigration(string $name): void + private function createMigration(string $name): bool { $folder = 'Migration/'; - Utils::createFolder($folder); + if (false === Utils::createFolder($folder)) { + return false; + } $fileName = $folder . $name . '.php'; if (file_exists($fileName)) { Utils::echo("* La migración " . $name . " YA EXISTE.\n"); - return; + return false; } $samplePath = dirname(__DIR__, 3) . "/samples/Migration.php.sample"; $sample = Utils::readFile($samplePath); if ($sample === false) { - return; + return false; } $migrationNameConst = strtolower(preg_replace('/(? OK.\n"); + if (!Utils::writeFile($fileName, $template)) { + return false; } + Utils::echo('* ' . $fileName . " -> OK.\n"); $newContentUse = InitEditor::addUse('use FacturaScripts\Core\Migrations;'); if ($newContentUse) { @@ -74,5 +75,7 @@ private function createMigration(string $name): void if ($newContentFunc) { InitEditor::setInitContent($newContentFunc); } + + return true; } } diff --git a/src/Command/Model/ModelCommand.php b/src/Command/Model/ModelCommand.php index b91cf60..1da1f80 100644 --- a/src/Command/Model/ModelCommand.php +++ b/src/Command/Model/ModelCommand.php @@ -53,14 +53,18 @@ protected function execute(InputInterface $input, OutputInterface $output): int } $fields = Column::askMulti(); - FileGenerator::createModelByFields($fileName, $tableName, $fields, $name, Utils::getNamespace()); + if (!FileGenerator::createModelByFields($fileName, $tableName, $fields, $name, Utils::getNamespace())) { + return Command::FAILURE; + } Utils::echo('* ' . $fileName . " -> OK.\n"); $tablePath = Utils::isCoreFolder() ? 'Core/Table/' : 'Table/'; $tableFilename = $tablePath . $tableName . '.xml'; Utils::createFolder($tablePath); if (false === file_exists($tableFilename)) { - FileGenerator::createTableXmlByFields($tableFilename, $tableName, $fields); + if (!FileGenerator::createTableXmlByFields($tableFilename, $tableName, $fields)) { + return Command::FAILURE; + } Utils::echo('* ' . $tableFilename . " -> OK.\n"); } else { Utils::echo("\n" . '* ' . $tableFilename . " YA EXISTE"); @@ -126,7 +130,9 @@ private function createEditController(string $modelName, array $fields): void return; } - FileGenerator::createXMLViewByFields($xmlFilename, $fields, 'edit'); + if (!FileGenerator::createXMLViewByFields($xmlFilename, $fields, 'edit')) { + return; + } Utils::echo('* ' . $xmlFilename . " -> OK.\n"); } @@ -186,7 +192,9 @@ private function createListController(string $modelName, array $fields): void return; } - FileGenerator::createXMLViewByFields($xmlFilename, $fields, 'list'); + if (!FileGenerator::createXMLViewByFields($xmlFilename, $fields, 'list')) { + return; + } Utils::echo('* ' . $xmlFilename . " -> OK.\n"); } }