From 0fdcd27a9c152ed8120ccea3bbd3ed5eb23121a6 Mon Sep 17 00:00:00 2001 From: Mathias Elle Date: Sat, 21 Dec 2024 00:02:36 +0100 Subject: [PATCH] Refactor BuildThemesCommand to improve file existence checks using is_file and add a helper method for directory checks --- src/Console/Command/BuildThemesCommand.php | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/Console/Command/BuildThemesCommand.php b/src/Console/Command/BuildThemesCommand.php index 09a233b..d538d09 100644 --- a/src/Console/Command/BuildThemesCommand.php +++ b/src/Console/Command/BuildThemesCommand.php @@ -119,11 +119,16 @@ protected function execute(InputInterface $input, OutputInterface $output): int return Command::SUCCESS; } + private function isDirectory(string $path): bool + { + return is_dir($path); + } + private function checkPackageJson(SymfonyStyle $io): bool { - if (!file_exists('package.json')) { + if (!is_file('package.json')) { $io->warning("The 'package.json' file does not exist in the Magento root path."); - if (!file_exists('package.json.sample')) { + if (!is_file('package.json.sample')) { $io->warning("The 'package.json.sample' file does not exist in the Magento root path."); $io->error("Skipping this theme build."); return false; @@ -142,7 +147,7 @@ private function checkPackageJson(SymfonyStyle $io): bool private function checkNodeModules(SymfonyStyle $io): bool { - if (!is_dir('node_modules')) { + if (!$this->isDirectory('node_modules')) { $io->warning("The 'node_modules' folder does not exist in the Magento root path."); if ($io->confirm("Run 'npm install' to install the dependencies?", false)) { $io->section("Running 'npm install'... Please wait."); @@ -165,9 +170,9 @@ private function checkNodeModules(SymfonyStyle $io): bool private function checkFile(SymfonyStyle $io, string $file, string $sampleFile): bool { - if (!file_exists($file)) { + if (!is_file($file)) { $io->warning("The '$file' file does not exist in the Magento root path."); - if (!file_exists($sampleFile)) { + if (!is_file($sampleFile)) { $io->warning("The '$sampleFile' file does not exist in the Magento root path."); $io->error("Skipping this theme build."); return false;