diff --git a/mago.toml b/mago.toml new file mode 100644 index 0000000..9c78d62 --- /dev/null +++ b/mago.toml @@ -0,0 +1,14 @@ +# Mago configuration for MageForge +# https://mago.carthage.software/ + +[source] +paths = ["src/"] +includes = ["../../"] +extensions = ["php", "phtml"] + +[parser] +enable-short-tags = false + +[formatter] +inline-empty-constructor-braces = false +inline-empty-classlike-braces = false diff --git a/src/Block/Inspector.php b/src/Block/Inspector.php index 25ed6dc..eaea02a 100644 --- a/src/Block/Inspector.php +++ b/src/Block/Inspector.php @@ -32,7 +32,7 @@ public function __construct( private readonly State $state, private readonly ScopeConfigInterface $scopeConfig, private readonly DevHelper $devHelper, - array $data = [] + array $data = [], ) { parent::__construct($context, $data); } diff --git a/src/Console/Command/AbstractCommand.php b/src/Console/Command/AbstractCommand.php index 357a123..152ee54 100644 --- a/src/Console/Command/AbstractCommand.php +++ b/src/Console/Command/AbstractCommand.php @@ -134,7 +134,7 @@ protected function isDebug(OutputInterface $output): bool protected function handleInvalidThemeWithSuggestions( string $invalidTheme, ThemeSuggester $themeSuggester, - OutputInterface $output + OutputInterface $output, ): ?string { $suggestions = $themeSuggester->findSimilarThemes($invalidTheme); @@ -169,7 +169,7 @@ protected function handleInvalidThemeWithSuggestions( label: 'Did you mean one of these themes?', options: $options, scroll: 10, - hint: 'Arrow keys to navigate, Enter to confirm' + hint: 'Arrow keys to navigate, Enter to confirm', ); try { @@ -375,7 +375,7 @@ private function sanitizeTermValue(string $value): ?string if ($sanitized === null) { return null; } - return (strlen($sanitized) > 0 && strlen($sanitized) <= 50) ? $sanitized : null; + return strlen($sanitized) > 0 && strlen($sanitized) <= 50 ? $sanitized : null; } /** @@ -402,7 +402,7 @@ private function sanitizeAlphanumericValue(string $value): ?string if ($sanitized === null) { return null; } - return (strlen($sanitized) > 0 && strlen($sanitized) <= 255) ? $sanitized : null; + return strlen($sanitized) > 0 && strlen($sanitized) <= 255 ? $sanitized : null; } /** diff --git a/src/Console/Command/Dev/InspectorCommand.php b/src/Console/Command/Dev/InspectorCommand.php index a7824c2..7719e75 100644 --- a/src/Console/Command/Dev/InspectorCommand.php +++ b/src/Console/Command/Dev/InspectorCommand.php @@ -34,7 +34,7 @@ public function __construct( private readonly State $state, private readonly CacheManager $cacheManager, private readonly ScopeConfigInterface $scopeConfig, - ?string $name = null + ?string $name = null, ) { parent::__construct($name); } @@ -46,30 +46,29 @@ public function __construct( */ protected function configure(): void { - $this->setName($this->getCommandName('theme', 'inspector')) + $this + ->setName($this->getCommandName('theme', 'inspector')) ->setDescription('Manage MageForge Frontend Inspector (Actions: enable|disable|status)') ->addArgument( self::ARGUMENT_ACTION, InputArgument::REQUIRED, - 'Action to perform: enable, disable, or status' + 'Action to perform: enable, disable, or status', ) - ->setHelp( - <<%command.name% command manages the MageForge Frontend Inspector: + ->setHelp(<<%command.name% command manages the MageForge Frontend Inspector: - php %command.full_name% enable - Enable the inspector (requires developer mode) + php %command.full_name% enable + Enable the inspector (requires developer mode) - php %command.full_name% disable - Disable the inspector + php %command.full_name% disable + Disable the inspector - php %command.full_name% status - Show current inspector status + php %command.full_name% status + Show current inspector status -The inspector allows you to hover over frontend elements to see template paths, -block classes, modules, and other metadata. Activate with Ctrl+Shift+I. -HELP - ); + The inspector allows you to hover over frontend elements to see template paths, + block classes, modules, and other metadata. Activate with Ctrl+Shift+I. + HELP); parent::configure(); } @@ -83,14 +82,11 @@ protected function configure(): void */ protected function executeCommand(InputInterface $input, OutputInterface $output): int { - $action = strtolower((string)$input->getArgument(self::ARGUMENT_ACTION)); + $action = strtolower((string) $input->getArgument(self::ARGUMENT_ACTION)); // Validate action if (!in_array($action, ['enable', 'disable', 'status'], true)) { - $this->io->error(sprintf( - 'Invalid action "%s". Use: enable, disable, or status', - $action - )); + $this->io->error(sprintf('Invalid action "%s". Use: enable, disable, or status', $action)); return Cli::RETURN_FAILURE; } diff --git a/src/Console/Command/Hyva/CompatibilityCheckCommand.php b/src/Console/Command/Hyva/CompatibilityCheckCommand.php index a808045..4265c98 100644 --- a/src/Console/Command/Hyva/CompatibilityCheckCommand.php +++ b/src/Console/Command/Hyva/CompatibilityCheckCommand.php @@ -38,7 +38,7 @@ class CompatibilityCheckCommand extends AbstractCommand * @param CompatibilityChecker $compatibilityChecker */ public function __construct( - private readonly CompatibilityChecker $compatibilityChecker + private readonly CompatibilityChecker $compatibilityChecker, ) { parent::__construct(); } @@ -50,32 +50,33 @@ public function __construct( */ protected function configure(): void { - $this->setName($this->getCommandName('hyva', 'compatibility:check')) + $this + ->setName($this->getCommandName('hyva', 'compatibility:check')) ->setDescription('Check modules for Hyvä theme compatibility issues') ->setAliases(['hyva:check']) ->addOption( self::OPTION_SHOW_ALL, 'a', InputOption::VALUE_NONE, - 'Show all modules including compatible ones' + 'Show all modules including compatible ones', ) ->addOption( self::OPTION_THIRD_PARTY_ONLY, 't', InputOption::VALUE_NONE, - 'Check only third-party modules (exclude Magento_* modules)' + 'Check only third-party modules (exclude Magento_* modules)', ) ->addOption( self::OPTION_INCLUDE_VENDOR, null, InputOption::VALUE_NONE, - 'Include Magento core modules (default: third-party modules only)' + 'Include Magento core modules (default: third-party modules only)', ) ->addOption( self::OPTION_DETAILED, 'd', InputOption::VALUE_NONE, - 'Show detailed file-level issues for incompatible modules' + 'Show detailed file-level issues for incompatible modules', ); } @@ -89,7 +90,8 @@ protected function configure(): void protected function executeCommand(InputInterface $input, OutputInterface $output): int { // Check if we're in interactive mode (no options provided) - $hasOptions = $input->getOption(self::OPTION_SHOW_ALL) + $hasOptions = + $input->getOption(self::OPTION_SHOW_ALL) || $input->getOption(self::OPTION_THIRD_PARTY_ONLY) || $input->getOption(self::OPTION_INCLUDE_VENDOR) || $input->getOption(self::OPTION_DETAILED); @@ -142,10 +144,7 @@ private function runInteractiveMode(InputInterface $input, OutputInterface $outp $scope = $scopePrompt->prompt(); // Detailed view confirmation - $detailedPrompt = new ConfirmPrompt( - label: 'Show detailed file-level issues?', - default: false, - ); + $detailedPrompt = new ConfirmPrompt(label: 'Show detailed file-level issues?', default: false); $detailed = $detailedPrompt->prompt(); @@ -221,9 +220,8 @@ private function runScan( bool $includeVendor, bool $detailed, bool $incompatibleOnly, - OutputInterface $output + OutputInterface $output, ): int { - // Determine filter logic: // - thirdPartyOnly: Only scan non-Magento_* modules (default behavior) // - includeVendor: Also scan Magento_* core modules @@ -237,7 +235,7 @@ private function runScan( $output, $showAll, $scanThirdPartyOnly, - $excludeVendor + $excludeVendor, ); // Determine display mode: @@ -266,9 +264,7 @@ private function runScan( $this->io->newLine(); // Return appropriate exit code - return $results['summary']['criticalIssues'] > 0 - ? Cli::RETURN_FAILURE - : Cli::RETURN_SUCCESS; + return $results['summary']['criticalIssues'] > 0 ? Cli::RETURN_FAILURE : Cli::RETURN_SUCCESS; } /** @@ -289,10 +285,7 @@ private function displayResults(array $results, bool $showAll): void return; } - $this->io->table( - ['Module', 'Status', 'Issues'], - $tableData - ); + $this->io->table(['Module', 'Status', 'Issues'], $tableData); } /** @@ -327,7 +320,7 @@ private function displayDetailedIssues(array $results): void $color, $symbol, $issue['line'], - $issue['description'] + $issue['description'], )); } } @@ -367,7 +360,7 @@ private function displaySummary(array $results): void $this->io->writeln(sprintf( '⚠ Found %d critical compatibility issue(s) in %d scanned modules.', $summary['criticalIssues'], - $summary['total'] + $summary['total'], )); $this->io->writeln('These modules require modifications to work with Hyvä themes.'); } elseif ($summary['warningIssues'] > 0) { @@ -375,7 +368,7 @@ private function displaySummary(array $results): void $this->io->writeln(sprintf( 'ℹ Found %d warning(s) in %d scanned modules.', $summary['warningIssues'], - $summary['total'] + $summary['total'], )); $this->io->writeln('Review these modules for potential compatibility issues.'); } else { diff --git a/src/Console/Command/System/CheckCommand.php b/src/Console/Command/System/CheckCommand.php index 0d488b3..d8ec8f7 100644 --- a/src/Console/Command/System/CheckCommand.php +++ b/src/Console/Command/System/CheckCommand.php @@ -35,7 +35,7 @@ public function __construct( private readonly Escaper $escaper, private readonly ResourceConnection $resourceConnection, private readonly ClientFactory $httpClientFactory, - private readonly Shell $shell + private readonly Shell $shell, ) { parent::__construct(); } @@ -47,7 +47,8 @@ public function __construct( */ protected function configure(): void { - $this->setName($this->getCommandName('system', 'check')) + $this + ->setName($this->getCommandName('system', 'check')) ->setDescription('Displays system information like PHP version and Node.js version') ->setAliases(['system:check']); } @@ -85,34 +86,31 @@ protected function executeCommand(InputInterface $input, OutputInterface $output $dbDisplay = $dbType . ' ' . $mysqlVersion; $this->io->section('System Components'); - $this->io->table( - ['Component', 'Version/Status'], - [ - ['PHP', $phpVersion . ' (Memory limit: ' . $this->getPhpMemoryLimit() . ')'], - new TableSeparator(), - ['Composer', $composerVersion], - new TableSeparator(), - ['Node.js', $nodeVersionDisplay], - new TableSeparator(), - ['NPM', $npmVersion], - new TableSeparator(), - ['Git', $gitVersion], - new TableSeparator(), - ['Database', $dbDisplay], - new TableSeparator(), - ['Xdebug', $xdebugStatus], - new TableSeparator(), - ['Redis', $redisStatus], - new TableSeparator(), - ['Search Engine', $searchEngineStatus], - new TableSeparator(), - ['OS', $osInfo], - new TableSeparator(), - ['Disk Space', $diskSpace], - new TableSeparator(), - ['Magento', $magentoVersion] - ] - ); + $this->io->table(['Component', 'Version/Status'], [ + ['PHP', $phpVersion . ' (Memory limit: ' . $this->getPhpMemoryLimit() . ')'], + new TableSeparator(), + ['Composer', $composerVersion], + new TableSeparator(), + ['Node.js', $nodeVersionDisplay], + new TableSeparator(), + ['NPM', $npmVersion], + new TableSeparator(), + ['Git', $gitVersion], + new TableSeparator(), + ['Database', $dbDisplay], + new TableSeparator(), + ['Xdebug', $xdebugStatus], + new TableSeparator(), + ['Redis', $redisStatus], + new TableSeparator(), + ['Search Engine', $searchEngineStatus], + new TableSeparator(), + ['OS', $osInfo], + new TableSeparator(), + ['Disk Space', $diskSpace], + new TableSeparator(), + ['Magento', $magentoVersion], + ]); if (!empty($phpExtensions)) { $this->io->section('PHP Extensions'); @@ -511,19 +509,22 @@ private function getSearchEngineHosts(): array 'http://localhost:9200', 'http://127.0.0.1:9200', 'http://elasticsearch:9200', - 'http://opensearch:9200' + 'http://opensearch:9200', ]; $envHosts = [ - 'ELASTICSEARCH_HOST', 'ES_HOST', 'OPENSEARCH_HOST' + 'ELASTICSEARCH_HOST', + 'ES_HOST', + 'OPENSEARCH_HOST', ]; foreach ($envHosts as $envVar) { $hostValue = $this->getEnvironmentVariable($envVar); if (!empty($hostValue)) { - $port = $this->getEnvironmentVariable('ELASTICSEARCH_PORT') ?? - $this->getEnvironmentVariable('ES_PORT') ?? - $this->getEnvironmentVariable('OPENSEARCH_PORT') ?? '9200'; + $port = + $this->getEnvironmentVariable('ELASTICSEARCH_PORT') ?? $this->getEnvironmentVariable( + 'ES_PORT', + ) ?? $this->getEnvironmentVariable('OPENSEARCH_PORT') ?? '9200'; $elasticHosts[] = "http://{$hostValue}:{$port}"; } } @@ -617,8 +618,19 @@ private function getImportantPhpExtensions(): array { $extensions = []; $requiredExtensions = [ - 'curl', 'dom', 'fileinfo', 'gd', 'intl', 'json', 'mbstring', - 'openssl', 'pdo_mysql', 'simplexml', 'soap', 'xml', 'zip' + 'curl', + 'dom', + 'fileinfo', + 'gd', + 'intl', + 'json', + 'mbstring', + 'openssl', + 'pdo_mysql', + 'simplexml', + 'soap', + 'xml', + 'zip', ]; foreach ($requiredExtensions as $ext) { @@ -649,8 +661,8 @@ private function getDiskSpace(): string $totalSpace = disk_total_space('.'); $freeSpace = disk_free_space('.'); - $totalGB = round($totalSpace / 1024 / 1024 / 1024, 2); - $freeGB = round($freeSpace / 1024 / 1024 / 1024, 2); + $totalGB = round((($totalSpace / 1024) / 1024) / 1024, 2); + $freeGB = round((($freeSpace / 1024) / 1024) / 1024, 2); $usedGB = round($totalGB - $freeGB, 2); $usedPercent = round(($usedGB / $totalGB) * 100, 2); @@ -725,7 +737,7 @@ private function getValueFromDeploymentConfig($objectManager, string $name): ?st $deploymentConfig = $objectManager->get(\Magento\Framework\App\DeploymentConfig::class); $envValue = $deploymentConfig->get('system/default/environment/' . $name); if ($envValue !== null) { - return (string)$envValue; + return (string) $envValue; } } catch (\Exception $e) { if ($this->io->isVerbose()) { @@ -751,7 +763,7 @@ private function getValueFromEnvironmentService($objectManager, string $name): ? if (method_exists($environmentService, $method)) { $value = $environmentService->$method(); if ($value !== null) { - return (string)$value; + return (string) $value; } } } catch (\Exception $e) { @@ -773,7 +785,7 @@ private function getSystemEnvironmentValue(string $name): ?string { // Use ini_get for certain system variables as a safer alternative if (in_array($name, ['memory_limit', 'max_execution_time'])) { - $value = (string)ini_get($name); + $value = (string) ini_get($name); if ($value !== '') { return $value; } diff --git a/src/Console/Command/System/VersionCommand.php b/src/Console/Command/System/VersionCommand.php index b8bc456..9e58891 100644 --- a/src/Console/Command/System/VersionCommand.php +++ b/src/Console/Command/System/VersionCommand.php @@ -23,7 +23,7 @@ class VersionCommand extends AbstractCommand * @param File $fileDriver */ public function __construct( - private readonly File $fileDriver + private readonly File $fileDriver, ) { parent::__construct(); } @@ -35,7 +35,8 @@ public function __construct( */ protected function configure(): void { - $this->setName($this->getCommandName('system', 'version')) + $this + ->setName($this->getCommandName('system', 'version')) ->setDescription('Displays the module version and the latest version') ->setAliases(['system:version']); } @@ -56,7 +57,7 @@ protected function executeCommand(InputInterface $input, OutputInterface $output $this->io->section('Versions'); $this->io->listing([ "Module Version: $moduleVersion", - "Latest Version: $latestVersion" + "Latest Version: $latestVersion", ]); return Cli::RETURN_SUCCESS; @@ -70,9 +71,7 @@ protected function executeCommand(InputInterface $input, OutputInterface $output private function getModuleVersion(): string { try { - $composerJson = $this->fileDriver->fileGetContents( - __DIR__ . '/../../../../composer.json' - ); + $composerJson = $this->fileDriver->fileGetContents(__DIR__ . '/../../../../composer.json'); $composerData = json_decode($composerJson, true); return $composerData['version'] ?? self::UNKNOWN_VERSION; } catch (\Exception $e) { @@ -91,8 +90,8 @@ private function getLatestVersion(): string $client = new Client(); $response = $client->get(self::API_URL, [ 'headers' => [ - 'User-Agent' => 'MageForge-Version-Check' - ] + 'User-Agent' => 'MageForge-Version-Check', + ], ]); if ($response->getStatusCode() === 200) { diff --git a/src/Console/Command/Theme/BuildCommand.php b/src/Console/Command/Theme/BuildCommand.php index 19fd134..c80bd6f 100644 --- a/src/Console/Command/Theme/BuildCommand.php +++ b/src/Console/Command/Theme/BuildCommand.php @@ -33,7 +33,7 @@ public function __construct( private readonly ThemePath $themePath, private readonly ThemeList $themeList, private readonly BuilderPool $builderPool, - private readonly ThemeSuggester $themeSuggester + private readonly ThemeSuggester $themeSuggester, ) { parent::__construct(); } @@ -45,12 +45,13 @@ public function __construct( */ protected function configure(): void { - $this->setName($this->getCommandName('theme', 'build')) + $this + ->setName($this->getCommandName('theme', 'build')) ->setDescription('Builds a Magento theme') ->addArgument( 'themeCodes', InputArgument::IS_ARRAY, - 'Theme codes to build (format: Vendor/theme, Vendor/theme 2, ...)' + 'Theme codes to build (format: Vendor/theme, Vendor/theme 2, ...)', ) ->setAliases(['frontend:build']); } @@ -149,7 +150,7 @@ private function processBuildThemes( array $themeCodes, SymfonyStyle $io, OutputInterface $output, - bool $isVerbose + bool $isVerbose, ): int { $startTime = microtime(true); $successList = []; @@ -177,12 +178,12 @@ private function processBuildThemes( } // Show which theme is currently being built (with validated/corrected name) - $themeNameCyan = sprintf("%s", $validatedTheme); + $themeNameCyan = sprintf('%s', $validatedTheme); $spinner = new Spinner(sprintf( - "Building %s (%d of %d) ...", + 'Building %s (%d of %d) ...', $themeNameCyan, $currentTheme, - $totalThemes + $totalThemes, )); $success = false; @@ -194,18 +195,18 @@ private function processBuildThemes( if ($success) { // Show that the theme was successfully built $io->writeln(sprintf( - " Building %s (%d of %d) ... done", + ' Building %s (%d of %d) ... done', $themeNameCyan, $currentTheme, - $totalThemes + $totalThemes, )); } else { // Show that an error occurred while building the theme $io->writeln(sprintf( - " Building %s (%d of %d) ... failed", + ' Building %s (%d of %d) ... failed', $themeNameCyan, $currentTheme, - $totalThemes + $totalThemes, )); } } @@ -224,20 +225,13 @@ private function processBuildThemes( * @param OutputInterface $output * @return string|null Validated/corrected theme code or null if invalid/cancelled */ - private function validateAndCorrectTheme( - string $themeCode, - SymfonyStyle $io, - OutputInterface $output - ): ?string { + private function validateAndCorrectTheme(string $themeCode, SymfonyStyle $io, OutputInterface $output): ?string + { // Get theme path $themePath = $this->themePath->getPath($themeCode); if ($themePath === null) { // Try to suggest similar themes - $correctedTheme = $this->handleInvalidThemeWithSuggestions( - $themeCode, - $this->themeSuggester, - $output - ); + $correctedTheme = $this->handleInvalidThemeWithSuggestions($themeCode, $this->themeSuggester, $output); // If no theme was selected, return null if ($correctedTheme === null) { @@ -273,7 +267,7 @@ private function buildValidatedTheme( SymfonyStyle $io, OutputInterface $output, bool $isVerbose, - array &$successList + array &$successList, ): bool { $themePath = $this->themePath->getPath($themeCode); @@ -290,7 +284,7 @@ private function buildValidatedTheme( } if ($isVerbose) { - $io->section(sprintf("Building theme %s using %s builder", $themeCode, $builder->getName())); + $io->section(sprintf('Building theme %s using %s builder', $themeCode, $builder->getName())); } // Build the theme @@ -299,7 +293,7 @@ private function buildValidatedTheme( return false; } - $successList[] = sprintf("%s: Built successfully using %s builder", $themeCode, $builder->getName()); + $successList[] = sprintf('%s: Built successfully using %s builder', $themeCode, $builder->getName()); return true; } @@ -318,7 +312,7 @@ private function processTheme( SymfonyStyle $io, OutputInterface $output, bool $isVerbose, - array &$successList + array &$successList, ): bool { // Validate and correct theme $validatedTheme = $this->validateAndCorrectTheme($themeCode, $io, $output); @@ -341,11 +335,8 @@ private function processTheme( private function displayBuildSummary(SymfonyStyle $io, array $successList, float $duration): void { $io->newLine(); - $io->success(sprintf( - "🚀 Build process completed in %.2f seconds with the following results:", - $duration - )); - $io->writeln("Summary:"); + $io->success(sprintf('🚀 Build process completed in %.2f seconds with the following results:', $duration)); + $io->writeln('Summary:'); $io->newLine(); if (empty($successList)) { @@ -363,10 +354,10 @@ private function displayBuildSummary(SymfonyStyle $io, array $successList, float $details = str_replace( $matches[0], $matches[1] . '' . $matches[2] . '' . $matches[3], - $details + $details, ); } - $io->writeln(sprintf("✅ %s: %s", $themeName, $details)); + $io->writeln(sprintf('✅ %s: %s', $themeName, $details)); } else { $io->writeln("✅ $success"); } diff --git a/src/Console/Command/Theme/CleanCommand.php b/src/Console/Command/Theme/CleanCommand.php index a4ef033..c876e02 100644 --- a/src/Console/Command/Theme/CleanCommand.php +++ b/src/Console/Command/Theme/CleanCommand.php @@ -31,7 +31,7 @@ public function __construct( private readonly ThemeCleaner $themeCleaner, private readonly ThemeList $themeList, private readonly ThemePath $themePath, - private readonly ThemeSuggester $themeSuggester + private readonly ThemeSuggester $themeSuggester, ) { parent::__construct(); } @@ -43,24 +43,20 @@ public function __construct( */ protected function configure(): void { - $this->setName($this->getCommandName('theme', 'clean')) + $this + ->setName($this->getCommandName('theme', 'clean')) ->setDescription('Clean theme static files and cache directories') ->addArgument( 'themeCodes', InputArgument::IS_ARRAY, - 'Theme codes to clean (format: Vendor/theme, Vendor/theme 2, ...)' - ) - ->addOption( - 'all', - 'a', - InputOption::VALUE_NONE, - 'Clean all themes' + 'Theme codes to clean (format: Vendor/theme, Vendor/theme 2, ...)', ) + ->addOption('all', 'a', InputOption::VALUE_NONE, 'Clean all themes') ->addOption( 'dry-run', null, InputOption::VALUE_NONE, - 'Show what would be cleaned without actually deleting anything' + 'Show what would be cleaned without actually deleting anything', ) ->setAliases(['frontend:clean']); } @@ -269,11 +265,7 @@ private function validateTheme(string $themeName, array &$failedThemes, OutputIn if ($themePath === null) { // Try to suggest similar themes - $correctedTheme = $this->handleInvalidThemeWithSuggestions( - $themeName, - $this->themeSuggester, - $output - ); + $correctedTheme = $this->handleInvalidThemeWithSuggestions($themeName, $this->themeSuggester, $output); // If no theme was selected, mark as failed if ($correctedTheme === null) { @@ -309,9 +301,9 @@ private function validateTheme(string $themeName, array &$failedThemes, OutputIn private function displayThemeHeader(string $themeName, int $currentTheme, int $totalThemes): void { if ($totalThemes > 1) { - $this->io->section(sprintf("Cleaning theme %d of %d: %s", $currentTheme, $totalThemes, $themeName)); + $this->io->section(sprintf('Cleaning theme %d of %d: %s', $currentTheme, $totalThemes, $themeName)); } else { - $this->io->section(sprintf("Cleaning static files for theme: %s", $themeName)); + $this->io->section(sprintf('Cleaning static files for theme: %s', $themeName)); } } @@ -356,7 +348,7 @@ private function displayThemeResult(string $themeName, int $cleaned, bool $dryRu $action, $cleaned, $cleaned === 1 ? 'y' : 'ies', - $themeName + $themeName, )); } else { $this->io->writeln(sprintf(" ℹ No files to clean for theme '%s'", $themeName)); @@ -401,7 +393,7 @@ private function displaySingleThemeSummary(string $themeCode, int $totalCleaned, $action, $totalCleaned, $totalCleaned === 1 ? 'y' : 'ies', - $themeCode + $themeCode, )); } else { $this->io->info(sprintf("No files to clean for theme '%s'", $themeCode)); @@ -421,19 +413,19 @@ private function displayMultiThemeSummary( int $totalThemes, int $totalCleaned, array $failedThemes, - bool $dryRun + bool $dryRun, ): void { $successCount = $totalThemes - count($failedThemes); if ($successCount > 0 && $totalCleaned > 0) { $action = $dryRun ? 'Would clean' : 'Successfully cleaned'; $this->io->success(sprintf( - "%s %d director%s across %d theme%s", + '%s %d director%s across %d theme%s', $action, $totalCleaned, $totalCleaned === 1 ? 'y' : 'ies', $successCount, - $successCount === 1 ? '' : 's' + $successCount === 1 ? '' : 's', )); } else { $this->io->info('No files were cleaned.'); @@ -441,10 +433,10 @@ private function displayMultiThemeSummary( if (!empty($failedThemes)) { $this->io->warning(sprintf( - "Failed to process %d theme%s: %s", + 'Failed to process %d theme%s: %s', count($failedThemes), count($failedThemes) === 1 ? '' : 's', - implode(', ', $failedThemes) + implode(', ', $failedThemes), )); } } diff --git a/src/Console/Command/Theme/ListCommand.php b/src/Console/Command/Theme/ListCommand.php index a077433..b029f0f 100644 --- a/src/Console/Command/Theme/ListCommand.php +++ b/src/Console/Command/Theme/ListCommand.php @@ -32,7 +32,8 @@ public function __construct( */ protected function configure(): void { - $this->setName($this->getCommandName('theme', 'list')) + $this + ->setName($this->getCommandName('theme', 'list')) ->setDescription('Lists all available Magento themes') ->setAliases(['frontend:list']); } @@ -61,7 +62,7 @@ protected function executeCommand(InputInterface $input, OutputInterface $output $table->addRow([ sprintf('%s', $theme->getCode()), $theme->getThemeTitle(), - $path + $path, ]); } diff --git a/src/Console/Command/Theme/TokensCommand.php b/src/Console/Command/Theme/TokensCommand.php index 4313b86..d0ca49e 100644 --- a/src/Console/Command/Theme/TokensCommand.php +++ b/src/Console/Command/Theme/TokensCommand.php @@ -48,13 +48,14 @@ public function __construct( */ protected function configure(): void { - $this->setName($this->getCommandName('hyva', 'tokens')) + $this + ->setName($this->getCommandName('hyva', 'tokens')) ->setAliases(['hyva:tokens']) ->setDescription('Generate Hyvä design tokens from design.tokens.json or hyva.config.json') ->addArgument( 'themeCode', InputArgument::OPTIONAL, - 'Theme code to generate tokens for (format: Vendor/theme)' + 'Theme code to generate tokens for (format: Vendor/theme)', ); } @@ -136,11 +137,7 @@ private function validateHyvaTheme(string $themeCode, OutputInterface $output): $themePath = $this->themePath->getPath($themeCode); if ($themePath === null) { // Try to suggest similar themes - $correctedTheme = $this->handleInvalidThemeWithSuggestions( - $themeCode, - $this->themeSuggester, - $output - ); + $correctedTheme = $this->handleInvalidThemeWithSuggestions($themeCode, $this->themeSuggester, $output); // If no theme was selected, exit if ($correctedTheme === null) { diff --git a/src/Console/Command/Theme/WatchCommand.php b/src/Console/Command/Theme/WatchCommand.php index e15ea73..111019e 100644 --- a/src/Console/Command/Theme/WatchCommand.php +++ b/src/Console/Command/Theme/WatchCommand.php @@ -42,19 +42,11 @@ public function __construct( */ protected function configure(): void { - $this->setName($this->getCommandName('theme', 'watch')) + $this + ->setName($this->getCommandName('theme', 'watch')) ->setDescription('Watches theme files for changes and rebuilds them automatically') - ->addArgument( - 'themeCode', - InputArgument::OPTIONAL, - 'Theme to watch (format: Vendor/theme)' - ) - ->addOption( - 'theme', - 't', - InputOption::VALUE_OPTIONAL, - 'Theme to watch (format: Vendor/theme)' - ) + ->addArgument('themeCode', InputArgument::OPTIONAL, 'Theme to watch (format: Vendor/theme)') + ->addOption('theme', 't', InputOption::VALUE_OPTIONAL, 'Theme to watch (format: Vendor/theme)') ->setAliases(['frontend:watch']); } @@ -95,11 +87,7 @@ protected function executeCommand(InputInterface $input, OutputInterface $output $themePath = $this->themePath->getPath($themeCode); if ($themePath === null) { // Try to suggest similar themes - $correctedTheme = $this->handleInvalidThemeWithSuggestions( - $themeCode, - $this->themeSuggester, - $output - ); + $correctedTheme = $this->handleInvalidThemeWithSuggestions($themeCode, $this->themeSuggester, $output); // If no theme was selected, exit if ($correctedTheme === null) { diff --git a/src/Model/TemplateEngine/Decorator/InspectorHints.php b/src/Model/TemplateEngine/Decorator/InspectorHints.php index 00eb439..8691974 100644 --- a/src/Model/TemplateEngine/Decorator/InspectorHints.php +++ b/src/Model/TemplateEngine/Decorator/InspectorHints.php @@ -35,7 +35,7 @@ public function __construct( private readonly bool $showBlockHints, private readonly Random $random, private readonly BlockCacheCollector $cacheCollector, - private readonly File $fileDriver + private readonly File $fileDriver, ) { $this->magentoRoot = $this->resolveMagentoRoot(); } @@ -110,7 +110,7 @@ private function injectInspectorAttributes( string $html, BlockInterface $block, string $templateFile, - array $renderMetrics + array $renderMetrics, ): string { $wrapperId = 'mageforge-' . $this->random->getRandomString(16); @@ -162,7 +162,7 @@ private function injectInspectorAttributes( "\n%s\n", $jsonMetadata, $html, - $wrapperId + $wrapperId, ); return $wrappedHtml; diff --git a/src/Model/TemplateEngine/Plugin/InspectorHints.php b/src/Model/TemplateEngine/Plugin/InspectorHints.php index d715105..cbe07ee 100644 --- a/src/Model/TemplateEngine/Plugin/InspectorHints.php +++ b/src/Model/TemplateEngine/Plugin/InspectorHints.php @@ -34,7 +34,7 @@ public function __construct( private readonly StoreManagerInterface $storeManager, private readonly DevHelper $devHelper, private readonly InspectorHintsFactory $inspectorHintsFactory, - private readonly State $state + private readonly State $state, ) { } @@ -48,7 +48,7 @@ public function __construct( */ public function afterCreate( TemplateEngineFactory $subject, - TemplateEngineInterface $invocationResult + TemplateEngineInterface $invocationResult, ): TemplateEngineInterface { // Only activate in developer mode if ($this->state->getMode() !== State::MODE_DEVELOPER) { diff --git a/src/Model/ThemeList.php b/src/Model/ThemeList.php index f08a8b8..c3219d7 100644 --- a/src/Model/ThemeList.php +++ b/src/Model/ThemeList.php @@ -14,7 +14,7 @@ class ThemeList * @param MagentoThemeList $magentoThemeList */ public function __construct( - private readonly MagentoThemeList $magentoThemeList + private readonly MagentoThemeList $magentoThemeList, ) { } diff --git a/src/Model/ThemePath.php b/src/Model/ThemePath.php index 1048564..c78ce83 100644 --- a/src/Model/ThemePath.php +++ b/src/Model/ThemePath.php @@ -13,7 +13,7 @@ class ThemePath * @param ComponentRegistrarInterface $componentRegistrar */ public function __construct( - private readonly ComponentRegistrarInterface $componentRegistrar + private readonly ComponentRegistrarInterface $componentRegistrar, ) { } diff --git a/src/Service/CacheCleaner.php b/src/Service/CacheCleaner.php index fecfbb1..c89f79f 100644 --- a/src/Service/CacheCleaner.php +++ b/src/Service/CacheCleaner.php @@ -13,7 +13,7 @@ class CacheCleaner * @param Shell $shell */ public function __construct( - private readonly Shell $shell + private readonly Shell $shell, ) { } @@ -31,9 +31,7 @@ public function clean(SymfonyStyle $io, bool $isVerbose): bool $io->text('Cleaning cache...'); } - $this->shell->execute( - 'bin/magento cache:clean full_page block_html layout translate' - ); + $this->shell->execute('bin/magento cache:clean full_page block_html layout translate'); if ($isVerbose) { $io->success('Cache cleaned successfully.'); diff --git a/src/Service/DependencyChecker.php b/src/Service/DependencyChecker.php index 1367992..4f8e458 100644 --- a/src/Service/DependencyChecker.php +++ b/src/Service/DependencyChecker.php @@ -22,7 +22,7 @@ class DependencyChecker */ public function __construct( private readonly File $fileDriver, - private readonly Shell $shell + private readonly Shell $shell, ) { } @@ -61,7 +61,7 @@ private function checkPackageJson(SymfonyStyle $io, bool $isVerbose): bool if ($isVerbose) { $io->warning("The 'package.json.sample' file does not exist in the Magento root path."); } - $io->error("Skipping this theme build."); + $io->error('Skipping this theme build.'); return false; } else { if ($isVerbose) { @@ -108,7 +108,7 @@ private function checkNodeModules(SymfonyStyle $io, bool $isVerbose): bool return false; } } else { - $io->error("Skipping this theme build."); + $io->error('Skipping this theme build.'); return false; } } elseif ($isVerbose) { @@ -136,7 +136,7 @@ private function checkFile(SymfonyStyle $io, string $file, string $sampleFile, b if ($isVerbose) { $io->warning("The '$sampleFile' file does not exist in the Magento root path."); } - $io->error("Skipping this theme build."); + $io->error('Skipping this theme build.'); return false; } else { if ($isVerbose) { diff --git a/src/Service/GruntTaskRunner.php b/src/Service/GruntTaskRunner.php index 375cd5d..c9f69b9 100644 --- a/src/Service/GruntTaskRunner.php +++ b/src/Service/GruntTaskRunner.php @@ -16,7 +16,7 @@ class GruntTaskRunner * @param Shell $shell */ public function __construct( - private readonly Shell $shell + private readonly Shell $shell, ) { } @@ -28,11 +28,8 @@ public function __construct( * @param bool $isVerbose * @return bool */ - public function runTasks( - SymfonyStyle $io, - OutputInterface $output, - bool $isVerbose - ): bool { + public function runTasks(SymfonyStyle $io, OutputInterface $output, bool $isVerbose): bool + { try { if ($isVerbose) { $io->text('Running grunt clean...'); diff --git a/src/Service/Hyva/CompatibilityChecker.php b/src/Service/Hyva/CompatibilityChecker.php index 80fa0b6..de01676 100644 --- a/src/Service/Hyva/CompatibilityChecker.php +++ b/src/Service/Hyva/CompatibilityChecker.php @@ -23,7 +23,7 @@ class CompatibilityChecker */ public function __construct( private readonly ComponentRegistrarInterface $componentRegistrar, - private readonly ModuleScanner $moduleScanner + private readonly ModuleScanner $moduleScanner, ) { } @@ -44,7 +44,7 @@ public function check( OutputInterface $output, bool $showAll = false, bool $thirdPartyOnly = false, - bool $excludeVendor = true + bool $excludeVendor = true, ): array { $modules = $this->componentRegistrar->getPaths(ComponentRegistrar::MODULE); $results = [ @@ -60,10 +60,7 @@ public function check( 'hasIncompatibilities' => false, ]; - $io->text(sprintf( - 'Scanning %d modules for Hyvä compatibility...', - count($modules) - )); + $io->text(sprintf('Scanning %d modules for Hyvä compatibility...', count($modules))); $io->newLine(); foreach ($modules as $moduleName => $modulePath) { @@ -110,10 +107,7 @@ public function check( $results['summary']['criticalIssues'] += (int) $scanResult['criticalIssues']; // Calculate warnings explicitly to support future severity levels - $warningCount = max( - 0, - (int) $scanResult['totalIssues'] - (int) $scanResult['criticalIssues'] - ); + $warningCount = max(0, (int) $scanResult['totalIssues'] - (int) $scanResult['criticalIssues']); $results['summary']['warningIssues'] += (int) $warningCount; } diff --git a/src/Service/Hyva/IncompatibilityDetector.php b/src/Service/Hyva/IncompatibilityDetector.php index e914ac5..5edce53 100644 --- a/src/Service/Hyva/IncompatibilityDetector.php +++ b/src/Service/Hyva/IncompatibilityDetector.php @@ -98,7 +98,7 @@ class IncompatibilityDetector * @param File $fileDriver */ public function __construct( - private readonly File $fileDriver + private readonly File $fileDriver, ) { } diff --git a/src/Service/Hyva/ModuleScanner.php b/src/Service/Hyva/ModuleScanner.php index 1dc81f4..2fb17bc 100644 --- a/src/Service/Hyva/ModuleScanner.php +++ b/src/Service/Hyva/ModuleScanner.php @@ -23,7 +23,7 @@ class ModuleScanner */ public function __construct( private readonly File $fileDriver, - private readonly IncompatibilityDetector $incompatibilityDetector + private readonly IncompatibilityDetector $incompatibilityDetector, ) { } diff --git a/src/Service/Inspector/Cache/BlockCacheCollector.php b/src/Service/Inspector/Cache/BlockCacheCollector.php index a09df5b..d977e97 100644 --- a/src/Service/Inspector/Cache/BlockCacheCollector.php +++ b/src/Service/Inspector/Cache/BlockCacheCollector.php @@ -46,7 +46,7 @@ class BlockCacheCollector * @param LayoutInterface $layout */ public function __construct( - private readonly LayoutInterface $layout + private readonly LayoutInterface $layout, ) { } @@ -116,7 +116,7 @@ private function resolveCacheLifetime(BlockInterface $block): int|null|false return null; // Unlimited } - if (is_numeric($lifetimeRaw) && (int)$lifetimeRaw === 0) { + if (is_numeric($lifetimeRaw) && (int) $lifetimeRaw === 0) { return null; // Unlimited } diff --git a/src/Service/NodePackageManager.php b/src/Service/NodePackageManager.php index 4a960da..30129f1 100644 --- a/src/Service/NodePackageManager.php +++ b/src/Service/NodePackageManager.php @@ -19,7 +19,7 @@ class NodePackageManager */ public function __construct( private readonly Shell $shell, - private readonly FileDriver $fileDriver + private readonly FileDriver $fileDriver, ) { } diff --git a/src/Service/NodeSetupValidator.php b/src/Service/NodeSetupValidator.php index 25bfced..1aa4fca 100644 --- a/src/Service/NodeSetupValidator.php +++ b/src/Service/NodeSetupValidator.php @@ -6,6 +6,7 @@ use Magento\Framework\Filesystem\Driver\File as FileDriver; use Symfony\Component\Console\Style\SymfonyStyle; + use function Laravel\Prompts\confirm; /** @@ -40,7 +41,7 @@ class NodeSetupValidator */ public function __construct( private readonly FileDriver $fileDriver, - private readonly NodePackageManager $nodePackageManager + private readonly NodePackageManager $nodePackageManager, ) { } @@ -153,7 +154,7 @@ private function restoreGeneratedFilesAutomatically( string $rootPath, array $missing, SymfonyStyle $io, - bool $isVerbose + bool $isVerbose, ): bool { if ($isVerbose) { $io->note('Detected missing generated files/directories. Installing automatically...'); @@ -176,9 +177,7 @@ private function promptUserForRestoration(array $missing, SymfonyStyle $io): boo // Display missing files $io->warning('The following required files/directories are missing:'); foreach ($missing as $item) { - $suffix = $this->isGeneratedFileOrDirectory($item) - ? ' (will be generated by npm install)' - : ''; + $suffix = $this->isGeneratedFileOrDirectory($item) ? ' (will be generated by npm install)' : ''; $io->writeln(" - {$item}{$suffix}"); } $io->newLine(); @@ -187,7 +186,7 @@ private function promptUserForRestoration(array $missing, SymfonyStyle $io): boo return confirm( label: 'Would you like to restore missing files from Magento base?', default: true, - hint: 'This will copy the standard Magento files to your project root.' + hint: 'This will copy the standard Magento files to your project root.', ); } @@ -200,12 +199,8 @@ private function promptUserForRestoration(array $missing, SymfonyStyle $io): boo * @param bool $isVerbose Whether to show verbose output * @return bool True if restoration was successful */ - private function restoreMissingFiles( - string $rootPath, - array $missing, - SymfonyStyle $io, - bool $isVerbose - ): bool { + private function restoreMissingFiles(string $rootPath, array $missing, SymfonyStyle $io, bool $isVerbose): bool + { if (empty($missing)) { return true; } @@ -213,10 +208,7 @@ private function restoreMissingFiles( $basePath = self::MAGENTO_BASE_PATH; if (!$this->fileDriver->isDirectory($basePath)) { - $io->error(sprintf( - 'Magento base directory not found at: %s', - $basePath - )); + $io->error(sprintf('Magento base directory not found at: %s', $basePath)); return false; } @@ -277,19 +269,11 @@ private function restoreMissingFiles( private function displayRestorationSummary(array $restored, array $failed, SymfonyStyle $io): void { if (!empty($restored)) { - $io->success(sprintf( - 'Restored %d file(s): %s', - count($restored), - implode(', ', $restored) - )); + $io->success(sprintf('Restored %d file(s): %s', count($restored), implode(', ', $restored))); } if (!empty($failed)) { - $io->warning(sprintf( - 'Failed to restore %d file(s): %s', - count($failed), - implode(', ', $failed) - )); + $io->warning(sprintf('Failed to restore %d file(s): %s', count($failed), implode(', ', $failed))); } } diff --git a/src/Service/StandardThemeBuilder.php b/src/Service/StandardThemeBuilder.php index f6e0980..36e3c30 100644 --- a/src/Service/StandardThemeBuilder.php +++ b/src/Service/StandardThemeBuilder.php @@ -4,8 +4,8 @@ namespace OpenForgeProject\MageForge\Service; -use Symfony\Component\Console\Style\SymfonyStyle; use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Console\Style\SymfonyStyle; class StandardThemeBuilder { @@ -19,7 +19,7 @@ class StandardThemeBuilder public function __construct( private readonly DependencyChecker $dependencyChecker, private readonly GruntTaskRunner $gruntTaskRunner, - private readonly StaticContentDeployer $staticContentDeployer + private readonly StaticContentDeployer $staticContentDeployer, ) { } @@ -38,7 +38,7 @@ public function build( SymfonyStyle $io, OutputInterface $output, bool $isVerbose, - array &$successList + array &$successList, ): bool { // Check dependencies if (!$this->dependencyChecker->checkDependencies($io, $isVerbose)) { @@ -52,7 +52,7 @@ public function build( if (!$this->gruntTaskRunner->runTasks($io, $output, $isVerbose)) { return false; } - $successList[] = "Global: Grunt tasks executed"; + $successList[] = 'Global: Grunt tasks executed'; $gruntTasksRun = true; } diff --git a/src/Service/StaticContentCleaner.php b/src/Service/StaticContentCleaner.php index eacaa60..09f5566 100644 --- a/src/Service/StaticContentCleaner.php +++ b/src/Service/StaticContentCleaner.php @@ -23,7 +23,7 @@ class StaticContentCleaner */ public function __construct( private readonly State $state, - private readonly ThemeCleaner $themeCleaner + private readonly ThemeCleaner $themeCleaner, ) { } @@ -36,12 +36,8 @@ public function __construct( * @param bool $isVerbose Whether to show verbose output * @return bool True if cleaning was performed or not needed, false on error */ - public function cleanIfNeeded( - string $themeCode, - SymfonyStyle $io, - OutputInterface $output, - bool $isVerbose - ): bool { + public function cleanIfNeeded(string $themeCode, SymfonyStyle $io, OutputInterface $output, bool $isVerbose): bool + { try { // Only clean in developer mode if ($this->state->getMode() !== State::MODE_DEVELOPER) { @@ -57,7 +53,7 @@ public function cleanIfNeeded( if ($isVerbose) { $io->note(sprintf( "Developer mode detected: Cleaning existing static files for theme '%s'...", - $themeCode + $themeCode, )); } @@ -65,7 +61,7 @@ public function cleanIfNeeded( $cleanedStatic = $this->themeCleaner->cleanPubStatic($themeCode, $io, false, $isVerbose); $cleanedPreprocessed = $this->themeCleaner->cleanViewPreprocessed($themeCode, $io, false, $isVerbose); - return ($cleanedStatic > 0 || $cleanedPreprocessed > 0); + return $cleanedStatic > 0 || $cleanedPreprocessed > 0; } catch (\Exception $e) { $io->error('Failed to check/clean static content: ' . $e->getMessage()); return false; diff --git a/src/Service/StaticContentDeployer.php b/src/Service/StaticContentDeployer.php index 13c7a19..f59d561 100644 --- a/src/Service/StaticContentDeployer.php +++ b/src/Service/StaticContentDeployer.php @@ -17,7 +17,7 @@ class StaticContentDeployer */ public function __construct( private readonly Shell $shell, - private readonly State $state + private readonly State $state, ) { } @@ -30,12 +30,8 @@ public function __construct( * @param bool $isVerbose * @return bool */ - public function deploy( - string $themeCode, - SymfonyStyle $io, - OutputInterface $output, - bool $isVerbose - ): bool { + public function deploy(string $themeCode, SymfonyStyle $io, OutputInterface $output, bool $isVerbose): bool + { try { // Only deploy if not in developer mode if ($this->state->getMode() === State::MODE_DEVELOPER) { @@ -49,17 +45,13 @@ public function deploy( $io->text('Deploying static content...'); } - $shellOutput = $this->shell->execute( - "php bin/magento setup:static-content:deploy -t %s -f --quiet", - [$themeCode] - ); + $shellOutput = $this->shell->execute('php bin/magento setup:static-content:deploy -t %s -f --quiet', [ + $themeCode, + ]); if ($isVerbose) { $output->writeln($shellOutput); - $io->success(sprintf( - "Static content deployed for theme '%s'.", - $themeCode - )); + $io->success(sprintf("Static content deployed for theme '%s'.", $themeCode)); } return true; diff --git a/src/Service/SymlinkCleaner.php b/src/Service/SymlinkCleaner.php index be44f0d..84dfde8 100644 --- a/src/Service/SymlinkCleaner.php +++ b/src/Service/SymlinkCleaner.php @@ -23,7 +23,7 @@ class SymlinkCleaner */ public function __construct( private readonly File $fileDriver, - private readonly State $state + private readonly State $state, ) { } @@ -35,11 +35,8 @@ public function __construct( * @param bool $isVerbose Whether to show verbose output * @return bool True on success or if no action needed, false on error */ - public function cleanSymlinks( - string $themePath, - SymfonyStyle $io, - bool $isVerbose - ): bool { + public function cleanSymlinks(string $themePath, SymfonyStyle $io, bool $isVerbose): bool + { try { // Only clean symlinks in developer mode if ($this->state->getMode() !== State::MODE_DEVELOPER) { @@ -63,19 +60,13 @@ public function cleanSymlinks( $deletedCount++; if ($isVerbose) { - $io->writeln(sprintf( - ' ⚠ Removed symlink: %s', - $this->getBasename($item) - )); + $io->writeln(sprintf(' ⚠ Removed symlink: %s', $this->getBasename($item))); } } } if ($deletedCount > 0 && $isVerbose) { - $io->success(sprintf( - 'Removed %d symlink(s) from web/css/', - $deletedCount - )); + $io->success(sprintf('Removed %d symlink(s) from web/css/', $deletedCount)); } return true; @@ -83,10 +74,7 @@ public function cleanSymlinks( // Don't fail the build process if symlink cleanup fails // Just warn the user and continue if ($isVerbose) { - $io->warning(sprintf( - 'Could not clean symlinks: %s', - $e->getMessage() - )); + $io->warning(sprintf('Could not clean symlinks: %s', $e->getMessage())); } return true; } diff --git a/src/Service/ThemeBuilder/BuilderInterface.php b/src/Service/ThemeBuilder/BuilderInterface.php index 266f3cb..6490e91 100644 --- a/src/Service/ThemeBuilder/BuilderInterface.php +++ b/src/Service/ThemeBuilder/BuilderInterface.php @@ -32,7 +32,7 @@ public function build( string $themePath, SymfonyStyle $io, OutputInterface $output, - bool $isVerbose + bool $isVerbose, ): bool; /** @@ -51,12 +51,7 @@ public function getName(): string; * @param bool $isVerbose * @return bool */ - public function autoRepair( - string $themePath, - SymfonyStyle $io, - OutputInterface $output, - bool $isVerbose - ): bool; + public function autoRepair(string $themePath, SymfonyStyle $io, OutputInterface $output, bool $isVerbose): bool; /** * Run the theme watch process. @@ -73,6 +68,6 @@ public function watch( string $themePath, SymfonyStyle $io, OutputInterface $output, - bool $isVerbose + bool $isVerbose, ): bool; } diff --git a/src/Service/ThemeBuilder/BuilderPool.php b/src/Service/ThemeBuilder/BuilderPool.php index 04259ff..11c11b8 100644 --- a/src/Service/ThemeBuilder/BuilderPool.php +++ b/src/Service/ThemeBuilder/BuilderPool.php @@ -10,7 +10,7 @@ class BuilderPool * @param BuilderInterface[] $builders */ public function __construct( - private readonly array $builders = [] + private readonly array $builders = [], ) { } diff --git a/src/Service/ThemeBuilder/HyvaThemes/Builder.php b/src/Service/ThemeBuilder/HyvaThemes/Builder.php index 6c49816..4cb8ab0 100644 --- a/src/Service/ThemeBuilder/HyvaThemes/Builder.php +++ b/src/Service/ThemeBuilder/HyvaThemes/Builder.php @@ -36,7 +36,7 @@ public function __construct( private readonly StaticContentCleaner $staticContentCleaner, private readonly CacheCleaner $cacheCleaner, private readonly SymlinkCleaner $symlinkCleaner, - private readonly NodePackageManager $nodePackageManager + private readonly NodePackageManager $nodePackageManager, ) { } @@ -91,19 +91,14 @@ public function build( string $themePath, SymfonyStyle $io, OutputInterface $output, - bool $isVerbose + bool $isVerbose, ): bool { if (!$this->detect($themePath)) { return false; } // Clean static content if in developer mode - if (!$this->staticContentCleaner->cleanIfNeeded( - $themeCode, - $io, - $output, - $isVerbose - )) { + if (!$this->staticContentCleaner->cleanIfNeeded($themeCode, $io, $output, $isVerbose)) { return false; } @@ -125,12 +120,7 @@ public function build( } // Deploy static content - if (!$this->staticContentDeployer->deploy( - $themeCode, - $io, - $output, - $isVerbose - )) { + if (!$this->staticContentDeployer->deploy($themeCode, $io, $output, $isVerbose)) { return false; } @@ -213,11 +203,7 @@ public function autoRepair(string $themePath, SymfonyStyle $io, OutputInterface if ($isVerbose) { $io->warning('Node modules out of sync or missing. Installing dependencies...'); } - if (!$this->nodePackageManager->installNodeModules( - $tailwindPath, - $io, - $isVerbose - )) { + if (!$this->nodePackageManager->installNodeModules($tailwindPath, $io, $isVerbose)) { return false; } } @@ -245,19 +231,14 @@ public function watch( string $themePath, SymfonyStyle $io, OutputInterface $output, - bool $isVerbose + bool $isVerbose, ): bool { if (!$this->detect($themePath)) { return false; } // Clean static content if in developer mode - if (!$this->staticContentCleaner->cleanIfNeeded( - $themeCode, - $io, - $output, - $isVerbose - )) { + if (!$this->staticContentCleaner->cleanIfNeeded($themeCode, $io, $output, $isVerbose)) { return false; } @@ -281,17 +262,15 @@ public function watch( $process = new Process(['npm', 'run', 'watch'], $tailwindPath); $process->setTimeout(null); - $isTty = defined('STDIN') && function_exists('stream_isatty') - && stream_isatty(STDIN); // phpcs:ignore Magento2.Functions.DiscouragedFunction.Discouraged + // phpcs:disable Magento2.Functions.DiscouragedFunction.Discouraged + $isTty = defined('STDIN') && function_exists('stream_isatty') && stream_isatty(STDIN); + // phpcs:enable Magento2.Functions.DiscouragedFunction.Discouraged if ($isTty && Process::isTtySupported()) { try { $process->setTty(true); } catch (\RuntimeException $exception) { if ($isVerbose) { - $io->warning( - 'TTY is not supported in this environment; ' . - 'continuing without TTY.' - ); + $io->warning('TTY is not supported in this environment; continuing without TTY.'); } } } diff --git a/src/Service/ThemeBuilder/MagentoStandard/Builder.php b/src/Service/ThemeBuilder/MagentoStandard/Builder.php index 0d5564a..bf18a2b 100644 --- a/src/Service/ThemeBuilder/MagentoStandard/Builder.php +++ b/src/Service/ThemeBuilder/MagentoStandard/Builder.php @@ -38,7 +38,7 @@ public function __construct( private readonly CacheCleaner $cacheCleaner, private readonly SymlinkCleaner $symlinkCleaner, private readonly NodePackageManager $nodePackageManager, - private readonly GruntTaskRunner $gruntTaskRunner + private readonly GruntTaskRunner $gruntTaskRunner, ) { } @@ -55,8 +55,10 @@ public function detect(string $themePath): bool // Check if this is a standard Magento theme by looking for theme.xml // and ensuring it's not a Hyva theme (no tailwind directory) - return $this->fileDriver->isExists($themePath . '/theme.xml') - && !$this->fileDriver->isExists($themePath . '/web/tailwind'); + return ( + $this->fileDriver->isExists($themePath . '/theme.xml') + && !$this->fileDriver->isExists($themePath . '/web/tailwind') + ); } /** @@ -74,19 +76,14 @@ public function build( string $themePath, SymfonyStyle $io, OutputInterface $output, - bool $isVerbose + bool $isVerbose, ): bool { if (!$this->detect($themePath)) { return false; } // Clean static content if in developer mode - if (!$this->staticContentCleaner->cleanIfNeeded( - $themeCode, - $io, - $output, - $isVerbose - )) { + if (!$this->staticContentCleaner->cleanIfNeeded($themeCode, $io, $output, $isVerbose)) { return false; } @@ -130,7 +127,7 @@ private function processNodeSetup( string $themePath, SymfonyStyle $io, OutputInterface $output, - bool $isVerbose + bool $isVerbose, ): bool { // Check if Node/Grunt setup exists if (!$this->autoRepair($themePath, $io, $output, $isVerbose)) { @@ -250,7 +247,7 @@ public function watch( string $themePath, SymfonyStyle $io, OutputInterface $output, - bool $isVerbose + bool $isVerbose, ): bool { if (!$this->detect($themePath)) { return false; @@ -258,10 +255,8 @@ public function watch( // Vendor themes cannot be watched (read-only) if ($this->isVendorTheme($themePath)) { - $io->error( - 'Watch mode is not supported for vendor themes. Vendor themes are read-only and ' - . 'should have pre-built assets.' - ); + $io->error('Watch mode is not supported for vendor themes. Vendor themes are read-only and ' + . 'should have pre-built assets.'); return false; } @@ -269,18 +264,13 @@ public function watch( if (!$this->hasNodeSetup()) { $io->error( 'Watch mode requires Node.js/Grunt setup. No package.json, package-lock.json, ' - . 'node_modules, or grunt-config.json found.' + . 'node_modules, or grunt-config.json found.', ); return false; } // Clean static content if in developer mode - if (!$this->staticContentCleaner->cleanIfNeeded( - $themeCode, - $io, - $output, - $isVerbose - )) { + if (!$this->staticContentCleaner->cleanIfNeeded($themeCode, $io, $output, $isVerbose)) { return false; } diff --git a/src/Service/ThemeBuilder/TailwindCSS/Builder.php b/src/Service/ThemeBuilder/TailwindCSS/Builder.php index 51ca303..ed8789d 100644 --- a/src/Service/ThemeBuilder/TailwindCSS/Builder.php +++ b/src/Service/ThemeBuilder/TailwindCSS/Builder.php @@ -36,7 +36,7 @@ public function __construct( private readonly StaticContentCleaner $staticContentCleaner, private readonly CacheCleaner $cacheCleaner, private readonly SymlinkCleaner $symlinkCleaner, - private readonly NodePackageManager $nodePackageManager + private readonly NodePackageManager $nodePackageManager, ) { } @@ -91,19 +91,14 @@ public function build( string $themePath, SymfonyStyle $io, OutputInterface $output, - bool $isVerbose + bool $isVerbose, ): bool { if (!$this->detect($themePath)) { return false; } // Clean static content if in developer mode - if (!$this->staticContentCleaner->cleanIfNeeded( - $themeCode, - $io, - $output, - $isVerbose - )) { + if (!$this->staticContentCleaner->cleanIfNeeded($themeCode, $io, $output, $isVerbose)) { return false; } @@ -139,12 +134,7 @@ public function build( } // Deploy static content - if (!$this->staticContentDeployer->deploy( - $themeCode, - $io, - $output, - $isVerbose - )) { + if (!$this->staticContentDeployer->deploy($themeCode, $io, $output, $isVerbose)) { return false; } @@ -165,12 +155,8 @@ public function build( * @param bool $isVerbose * @return bool */ - public function autoRepair( - string $themePath, - SymfonyStyle $io, - OutputInterface $output, - bool $isVerbose - ): bool { + public function autoRepair(string $themePath, SymfonyStyle $io, OutputInterface $output, bool $isVerbose): bool + { $tailwindPath = rtrim($themePath, '/') . '/web/tailwind'; // Check if node_modules is in sync with package-lock.json @@ -178,11 +164,7 @@ public function autoRepair( if ($isVerbose) { $io->warning('Node modules out of sync or missing. Installing npm dependencies...'); } - if (!$this->nodePackageManager->installNodeModules( - $tailwindPath, - $io, - $isVerbose - )) { + if (!$this->nodePackageManager->installNodeModules($tailwindPath, $io, $isVerbose)) { return false; } } @@ -220,19 +202,14 @@ public function watch( string $themePath, SymfonyStyle $io, OutputInterface $output, - bool $isVerbose + bool $isVerbose, ): bool { if (!$this->detect($themePath)) { return false; } // Clean static content if in developer mode - if (!$this->staticContentCleaner->cleanIfNeeded( - $themeCode, - $io, - $output, - $isVerbose - )) { + if (!$this->staticContentCleaner->cleanIfNeeded($themeCode, $io, $output, $isVerbose)) { return false; } @@ -261,10 +238,7 @@ public function watch( $process->setTty(true); } catch (\RuntimeException $exception) { if ($isVerbose) { - $io->warning( - 'TTY mode is not supported in this environment; ' . - 'running watch without TTY.' - ); + $io->warning('TTY mode is not supported in this environment; running watch without TTY.'); } } } diff --git a/src/Service/ThemeCleaner.php b/src/Service/ThemeCleaner.php index 866bc07..8e6610d 100644 --- a/src/Service/ThemeCleaner.php +++ b/src/Service/ThemeCleaner.php @@ -20,7 +20,7 @@ class ThemeCleaner * @param Filesystem $filesystem */ public function __construct( - private readonly Filesystem $filesystem + private readonly Filesystem $filesystem, ) { } @@ -37,7 +37,7 @@ public function cleanViewPreprocessed( string $themeCode, SymfonyStyle $io, bool $dryRun = false, - bool $isVerbose = false + bool $isVerbose = false, ): int { $cleaned = 0; $varDirectory = $this->filesystem->getDirectoryWrite(DirectoryList::VAR_DIR); @@ -71,11 +71,7 @@ public function cleanViewPreprocessed( $cleaned++; } catch (\Exception $e) { if ($isVerbose) { - $io->writeln(sprintf( - ' ✗ Failed to clean: var/%s - %s', - $path, - $e->getMessage() - )); + $io->writeln(sprintf(' ✗ Failed to clean: var/%s - %s', $path, $e->getMessage())); } } } @@ -97,7 +93,7 @@ public function cleanPubStatic( string $themeCode, SymfonyStyle $io, bool $dryRun = false, - bool $isVerbose = false + bool $isVerbose = false, ): int { $cleaned = 0; $staticDirectory = $this->filesystem->getDirectoryWrite(DirectoryList::STATIC_VIEW); @@ -130,7 +126,7 @@ public function cleanPubStatic( $io->writeln(sprintf( ' ✗ Failed to clean: pub/static/%s - %s', $pathToClean, - $e->getMessage() + $e->getMessage(), )); } } @@ -147,11 +143,8 @@ public function cleanPubStatic( * @param bool $isVerbose Whether to show verbose output * @return int Number of directories cleaned */ - public function cleanPageCache( - SymfonyStyle $io, - bool $dryRun = false, - bool $isVerbose = false - ): int { + public function cleanPageCache(SymfonyStyle $io, bool $dryRun = false, bool $isVerbose = false): int + { $cleaned = 0; $varDirectory = $this->filesystem->getDirectoryWrite(DirectoryList::VAR_DIR); @@ -167,10 +160,7 @@ public function cleanPageCache( $cleaned++; } catch (\Exception $e) { if ($isVerbose) { - $io->writeln(sprintf( - ' ✗ Failed to clean: var/page_cache - %s', - $e->getMessage() - )); + $io->writeln(sprintf(' ✗ Failed to clean: var/page_cache - %s', $e->getMessage())); } } } @@ -186,11 +176,8 @@ public function cleanPageCache( * @param bool $isVerbose Whether to show verbose output * @return int Number of directories cleaned */ - public function cleanVarTmp( - SymfonyStyle $io, - bool $dryRun = false, - bool $isVerbose = false - ): int { + public function cleanVarTmp(SymfonyStyle $io, bool $dryRun = false, bool $isVerbose = false): int + { $cleaned = 0; $varDirectory = $this->filesystem->getDirectoryWrite(DirectoryList::VAR_DIR); @@ -206,10 +193,7 @@ public function cleanVarTmp( $cleaned++; } catch (\Exception $e) { if ($isVerbose) { - $io->writeln(sprintf( - ' ✗ Failed to clean: var/tmp - %s', - $e->getMessage() - )); + $io->writeln(sprintf(' ✗ Failed to clean: var/tmp - %s', $e->getMessage())); } } } @@ -225,11 +209,8 @@ public function cleanVarTmp( * @param bool $isVerbose Whether to show verbose output * @return int Number of directories cleaned */ - public function cleanGenerated( - SymfonyStyle $io, - bool $dryRun = false, - bool $isVerbose = false - ): int { + public function cleanGenerated(SymfonyStyle $io, bool $dryRun = false, bool $isVerbose = false): int + { $cleaned = 0; $generatedDirectory = $this->filesystem->getDirectoryWrite(DirectoryList::GENERATED); @@ -244,10 +225,7 @@ public function cleanGenerated( $deletedCount++; } catch (\Exception $e) { if ($isVerbose) { - $io->writeln(sprintf( - ' ✗ Failed to clean: generated/code - %s', - $e->getMessage() - )); + $io->writeln(sprintf(' ✗ Failed to clean: generated/code - %s', $e->getMessage())); } } } @@ -262,7 +240,7 @@ public function cleanGenerated( if ($isVerbose) { $io->writeln(sprintf( ' ✗ Failed to clean: generated/metadata - %s', - $e->getMessage() + $e->getMessage(), )); } } @@ -277,10 +255,7 @@ public function cleanGenerated( } } catch (\Exception $e) { if ($isVerbose) { - $io->writeln(sprintf( - ' ✗ Failed to clean: generated - %s', - $e->getMessage() - )); + $io->writeln(sprintf(' ✗ Failed to clean: generated - %s', $e->getMessage())); } } diff --git a/src/Service/ThemeSuggester.php b/src/Service/ThemeSuggester.php index dd2f086..c036cfc 100644 --- a/src/Service/ThemeSuggester.php +++ b/src/Service/ThemeSuggester.php @@ -24,7 +24,7 @@ class ThemeSuggester * @param ThemeList $themeList */ public function __construct( - private readonly ThemeList $themeList + private readonly ThemeList $themeList, ) { } diff --git a/src/registration.php b/src/registration.php index 06a62f1..32cd763 100644 --- a/src/registration.php +++ b/src/registration.php @@ -4,8 +4,4 @@ use Magento\Framework\Component\ComponentRegistrar; -ComponentRegistrar::register( - ComponentRegistrar::MODULE, - 'OpenForgeProject_MageForge', - __DIR__ -); +ComponentRegistrar::register(ComponentRegistrar::MODULE, 'OpenForgeProject_MageForge', __DIR__); diff --git a/src/view/frontend/templates/inspector.phtml b/src/view/frontend/templates/inspector.phtml index b1d9eb0..1b2bccd 100644 --- a/src/view/frontend/templates/inspector.phtml +++ b/src/view/frontend/templates/inspector.phtml @@ -1,4 +1,5 @@ escapeHtmlAttr($block->getTheme()) ?>"> - -