Skip to content

Commit 89a2a86

Browse files
committed
fix: improve code formatting and type checks
1 parent f2b2094 commit 89a2a86

9 files changed

Lines changed: 40 additions & 26 deletions

File tree

src/Console/Command/AbstractCommand.php

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
use Laravel\Prompts\SelectPrompt;
88
use Magento\Framework\Console\Cli;
9-
use OpenForgeProject\MageForge\Service\ThemeSuggester;
109
use OpenForgeProject\MageForge\Model\ThemeList;
10+
use OpenForgeProject\MageForge\Service\ThemeSuggester;
1111
use Symfony\Component\Console\Command\Command;
1212
use Symfony\Component\Console\Input\InputInterface;
1313
use Symfony\Component\Console\Output\OutputInterface;
@@ -487,10 +487,8 @@ private function removeSecureEnvironmentValue(string $name): void
487487
* @param ThemeList $themeList
488488
* @return array<string>
489489
*/
490-
protected function resolveVendorThemes(
491-
array $themeCodes,
492-
ThemeList $themeList
493-
): array {
490+
protected function resolveVendorThemes(array $themeCodes, ThemeList $themeList): array
491+
{
494492
$resolved = [];
495493
$availableThemes = null;
496494

@@ -502,10 +500,7 @@ protected function resolveVendorThemes(
502500
if ($isExplicitWildcard || $isVendorOnly) {
503501
// Lazy-load themes only when needed
504502
if ($availableThemes === null) {
505-
$availableThemes = array_map(
506-
fn($theme) => $theme->getCode(),
507-
$themeList->getAllThemes()
508-
);
503+
$availableThemes = array_map(fn($theme) => $theme->getCode(), $themeList->getAllThemes());
509504
}
510505

511506
if ($isExplicitWildcard) {
@@ -514,10 +509,10 @@ protected function resolveVendorThemes(
514509
$prefix = $code . '/'; // e.g. "Vendor" -> "Vendor/"
515510
}
516511

517-
$matched = array_filter(
518-
$availableThemes,
519-
fn(string $availableCode) => \str_starts_with($availableCode, $prefix)
520-
);
512+
$matched = array_filter($availableThemes, fn(string $availableCode) => \str_starts_with(
513+
$availableCode,
514+
$prefix,
515+
));
521516

522517
if (empty($matched)) {
523518
$this->io->warning(sprintf("No themes found for vendor/prefix '%s'", $prefix));
@@ -532,7 +527,7 @@ protected function resolveVendorThemes(
532527
"Resolved vendor '%s' to %d theme(s): %s",
533528
$code,
534529
count($matched),
535-
implode(', ', $matched)
530+
implode(', ', $matched),
536531
));
537532

538533
foreach ($matched as $match) {

src/Console/Command/System/CheckCommand.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,12 @@ private function getLatestLtsNodeVersion(): string
164164

165165
/** @var array<int, array<string, mixed>> $nodes */
166166
foreach ($nodes as $node) {
167-
if (isset($node['lts']) && $node['lts'] !== false && isset($node['version']) && is_string($node['version'])) {
167+
if (
168+
isset($node['lts'])
169+
&& $node['lts'] !== false
170+
&& isset($node['version'])
171+
&& is_string($node['version'])
172+
) {
168173
return trim($node['version'], 'v');
169174
}
170175
}
@@ -669,8 +674,8 @@ private function getDiskSpace(): string
669674
$totalSpace = disk_total_space('.');
670675
$freeSpace = disk_free_space('.');
671676

672-
$totalGB = round((($totalSpace / 1024) / 1024) / 1024, 2);
673-
$freeGB = round((($freeSpace / 1024) / 1024) / 1024, 2);
677+
$totalGB = round($totalSpace / 1024 / 1024 / 1024, 2);
678+
$freeGB = round($freeSpace / 1024 / 1024 / 1024, 2);
674679
$usedGB = round($totalGB - $freeGB, 2);
675680
$usedPercent = round(($usedGB / $totalGB) * 100, 2);
676681

src/Console/Command/Theme/BuildCommand.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ protected function executeCommand(InputInterface $input, OutputInterface $output
9898
label: 'Select themes to build',
9999
options: fn(string $value) => empty($value)
100100
? $options
101-
: array_values(array_filter($options, fn($option) => stripos((string)$option, $value) !== false)),
101+
: array_values(array_filter($options, fn($option) => stripos((string) $option, $value) !== false)),
102102
placeholder: 'Type to search theme...',
103103
hint: 'Type to search, arrow keys to navigate, Space to toggle, Enter to confirm',
104104
required: false,
@@ -357,14 +357,14 @@ private function displayBuildSummary(SymfonyStyle $io, array $successList, float
357357
$io->success(sprintf(
358358
'🚀 Successfully built %d theme(s). Build process completed in %.2f seconds.',
359359
$successCount,
360-
$duration
360+
$duration,
361361
));
362362
$io->writeln('Summary:');
363363
$io->newLine();
364364
} else {
365365
$io->warning(sprintf(
366366
'Build process completed in %.2f seconds, but no themes were built successfully.',
367-
$duration
367+
$duration,
368368
));
369369
return;
370370
}

src/Console/Command/Theme/CleanCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ private function promptForThemes(array $options, array $themes): ?array
201201
label: 'Select themes to clean',
202202
options: fn(string $value) => empty($value)
203203
? $options
204-
: array_values(array_filter($options, fn($option) => stripos((string)$option, $value) !== false)),
204+
: array_values(array_filter($options, fn($option) => stripos((string) $option, $value) !== false)),
205205
placeholder: 'Type to search theme...',
206206
hint: 'Type to search, arrow keys to navigate, Space to toggle, Enter to confirm',
207207
required: false,

src/Console/Command/Theme/TokensCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ private function selectTheme(?string $themeCode): ?string
113113
label: 'Select theme to generate tokens for',
114114
options: fn(string $value) => empty($value)
115115
? $options
116-
: array_values(array_filter($options, fn($option) => stripos((string)$option, $value) !== false)),
116+
: array_values(array_filter($options, fn($option) => stripos((string) $option, $value) !== false)),
117117
placeholder: 'Type to search theme...',
118118
scroll: 10,
119119
hint: 'Type to search, arrow keys to navigate, Enter to confirm',

src/Console/Command/Theme/WatchCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ protected function executeCommand(InputInterface $input, OutputInterface $output
7777
label: 'Select theme to watch',
7878
options: fn(string $value) => empty($value)
7979
? $options
80-
: array_values(array_filter($options, fn($option) => stripos((string)$option, $value) !== false)),
80+
: array_values(array_filter($options, fn($option) => stripos((string) $option, $value) !== false)),
8181
placeholder: 'Type to search theme...',
8282
scroll: 10,
8383
hint: 'Type to search, arrow keys to navigate, Enter to confirm',

src/Service/Hyva/ModuleScanner.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,11 @@ private function isHyvaCompatibilityPackage(array $composerData): bool
121121
{
122122
// Check if this IS a Hyvä compatibility package
123123
$packageName = $composerData['name'] ?? '';
124-
if (is_string($packageName) && str_starts_with($packageName, 'hyva-themes/') && str_contains($packageName, '-compat')) {
124+
if (
125+
is_string($packageName)
126+
&& str_starts_with($packageName, 'hyva-themes/')
127+
&& str_contains($packageName, '-compat')
128+
) {
125129
return true;
126130
}
127131

src/Service/ThemeBuilder/HyvaThemes/Builder.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,12 @@ public function detect(string $themePath): bool
6868
if ($this->fileDriver->isExists($themePath . '/composer.json')) {
6969
$composerContent = $this->fileDriver->fileGetContents($themePath . '/composer.json');
7070
$composerJson = json_decode($composerContent, true);
71-
if (is_array($composerJson) && isset($composerJson['name']) && is_string($composerJson['name']) && str_contains($composerJson['name'], 'hyva')) {
71+
if (
72+
is_array($composerJson)
73+
&& isset($composerJson['name'])
74+
&& is_string($composerJson['name'])
75+
&& str_contains($composerJson['name'], 'hyva')
76+
) {
7277
return true;
7378
}
7479
}

src/Service/ThemeBuilder/TailwindCSS/Builder.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,12 @@ public function detect(string $themePath): bool
6868
if ($this->fileDriver->isExists($themePath . '/composer.json')) {
6969
$composerContent = $this->fileDriver->fileGetContents($themePath . '/composer.json');
7070
$composerJson = json_decode($composerContent, true);
71-
if (\is_array($composerJson) && isset($composerJson['name']) && \is_string($composerJson['name']) && !str_contains($composerJson['name'], 'hyva')) {
71+
if (
72+
\is_array($composerJson)
73+
&& isset($composerJson['name'])
74+
&& \is_string($composerJson['name'])
75+
&& !str_contains($composerJson['name'], 'hyva')
76+
) {
7277
return true;
7378
}
7479
}

0 commit comments

Comments
 (0)