Skip to content

Commit

Permalink
Refactor BuildThemesCommand to improve file existence checks using is…
Browse files Browse the repository at this point in the history
…_file and add a helper method for directory checks
  • Loading branch information
dermatz committed Dec 20, 2024
1 parent f549144 commit 0fdcd27
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/Console/Command/BuildThemesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Check warning on line 124 in src/Console/Command/BuildThemesCommand.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

src/Console/Command/BuildThemesCommand.php#L124

The use of function is_dir() is discouraged
}

private function checkPackageJson(SymfonyStyle $io): bool
{
if (!file_exists('package.json')) {
if (!is_file('package.json')) {

Check warning on line 129 in src/Console/Command/BuildThemesCommand.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

src/Console/Command/BuildThemesCommand.php#L129

The use of function is_file() is discouraged
$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')) {

Check warning on line 131 in src/Console/Command/BuildThemesCommand.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

src/Console/Command/BuildThemesCommand.php#L131

The use of function is_file() is discouraged
$io->warning("The 'package.json.sample' file does not exist in the Magento root path.");
$io->error("Skipping this theme build.");
return false;
Expand All @@ -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.");
Expand All @@ -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)) {

Check warning on line 173 in src/Console/Command/BuildThemesCommand.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

src/Console/Command/BuildThemesCommand.php#L173

The use of function is_file() is discouraged
$io->warning("The '$file' file does not exist in the Magento root path.");
if (!file_exists($sampleFile)) {
if (!is_file($sampleFile)) {

Check warning on line 175 in src/Console/Command/BuildThemesCommand.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

src/Console/Command/BuildThemesCommand.php#L175

The use of function is_file() is discouraged
$io->warning("The '$sampleFile' file does not exist in the Magento root path.");
$io->error("Skipping this theme build.");
return false;
Expand Down

0 comments on commit 0fdcd27

Please sign in to comment.