-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCompatibilityCheckCommand.php
More file actions
401 lines (347 loc) · 14.2 KB
/
CompatibilityCheckCommand.php
File metadata and controls
401 lines (347 loc) · 14.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
<?php
declare(strict_types=1);
namespace OpenForgeProject\MageForge\Console\Command\Hyva;
use Laravel\Prompts\ConfirmPrompt;
use Laravel\Prompts\SelectPrompt;
use Magento\Framework\Console\Cli;
use OpenForgeProject\MageForge\Console\Command\AbstractCommand;
use OpenForgeProject\MageForge\Service\Hyva\CompatibilityChecker;
use Symfony\Component\Console\Helper\TableSeparator;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
/**
* Command to check Magento modules for Hyvä theme compatibility issues
*
* Scans modules for RequireJS, Knockout.js, jQuery, and UI Components usage
* that would be incompatible with Hyvä themes.
*
* @phpstan-import-type CheckResults from \OpenForgeProject\MageForge\Service\Hyva\CompatibilityChecker
* @phpstan-import-type CheckSummary from \OpenForgeProject\MageForge\Service\Hyva\CompatibilityChecker
* @phpstan-import-type ModuleEntry from \OpenForgeProject\MageForge\Service\Hyva\CompatibilityChecker
*/
class CompatibilityCheckCommand extends AbstractCommand
{
private const OPTION_SHOW_ALL = 'show-all';
private const OPTION_THIRD_PARTY_ONLY = 'third-party-only';
private const OPTION_INCLUDE_VENDOR = 'include-vendor';
private const OPTION_DETAILED = 'detailed';
private const DISPLAY_MODE_ISSUES = 'issues';
private const DISPLAY_MODE_INCOMPATIBLE_ONLY = 'incompatible-only';
private const DISPLAY_MODE_SHOW_ALL = 'show-all';
private const SCOPE_THIRD_PARTY = 'third-party';
private const SCOPE_ALL = 'all';
/**
* @param CompatibilityChecker $compatibilityChecker
*/
public function __construct(
private readonly CompatibilityChecker $compatibilityChecker,
) {
parent::__construct();
}
/**
* Configure command options.
*
* @return void
*/
protected function configure(): void
{
$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',
)
->addOption(
self::OPTION_THIRD_PARTY_ONLY,
't',
InputOption::VALUE_NONE,
'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)',
)
->addOption(
self::OPTION_DETAILED,
'd',
InputOption::VALUE_NONE,
'Show detailed file-level issues for incompatible modules',
);
}
/**
* Execute compatibility check command.
*
* @param InputInterface $input
* @param OutputInterface $output
* @return int
*/
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)
|| $input->getOption(self::OPTION_THIRD_PARTY_ONLY)
|| $input->getOption(self::OPTION_INCLUDE_VENDOR)
|| $input->getOption(self::OPTION_DETAILED);
if (!$hasOptions && $this->isInteractiveTerminal($output)) {
return $this->runInteractiveMode($input, $output);
}
return $this->runDirectMode($input, $output);
}
/**
* Run interactive mode with Laravel Prompts
*
* @param InputInterface $input
* @param OutputInterface $output
* @return int
*/
private function runInteractiveMode(InputInterface $input, OutputInterface $output): int
{
$this->io->title('Hyvä Theme Compatibility Check');
// Set environment variables for Laravel Prompts
$this->setPromptEnvironment();
try {
// Display mode selection
$displayModePrompt = new SelectPrompt(
label: 'What modules do you want to see?',
options: [
self::DISPLAY_MODE_ISSUES => 'Modules with any issues (warnings or critical)',
self::DISPLAY_MODE_INCOMPATIBLE_ONLY => 'Only modules with critical issues',
self::DISPLAY_MODE_SHOW_ALL => 'All modules including compatible ones',
],
default: self::DISPLAY_MODE_ISSUES,
);
$displayMode = $displayModePrompt->prompt();
// Module scope selection
$scopePrompt = new SelectPrompt(
label: 'Which modules to scan?',
options: [
self::SCOPE_THIRD_PARTY => 'Third-party modules only (exclude Magento_*)',
self::SCOPE_ALL => 'All modules including Magento core',
],
default: self::SCOPE_THIRD_PARTY,
);
$scope = $scopePrompt->prompt();
// Detailed view confirmation
$detailedPrompt = new ConfirmPrompt(label: 'Show detailed file-level issues?', default: false);
$detailed = (bool) $detailedPrompt->prompt();
// Map selected options to flags
$showAll = $displayMode === self::DISPLAY_MODE_SHOW_ALL;
$incompatibleOnly = $displayMode === self::DISPLAY_MODE_INCOMPATIBLE_ONLY;
$includeVendor = $scope === self::SCOPE_ALL;
$thirdPartyOnly = false; // Not needed in interactive mode
// Show selected configuration
$this->io->newLine();
$config = [];
if ($showAll) {
$config[] = 'Show all modules';
} elseif ($incompatibleOnly) {
$config[] = 'Show incompatible only';
} else {
$config[] = 'Show modules with issues';
}
$config[] = $includeVendor ? 'Include Magento core' : 'Third-party modules only';
if ($detailed) {
$config[] = 'Detailed issues';
}
$this->io->comment('Configuration: ' . implode(', ', $config));
$this->io->newLine();
// Run scan with selected options
return $this->runScan($showAll, $thirdPartyOnly, $includeVendor, $detailed, $incompatibleOnly, $output);
} catch (\Throwable $e) {
$this->io->error('Interactive mode failed: ' . $e->getMessage());
$this->io->info('Falling back to default scan (third-party modules only)...');
$this->io->newLine();
return $this->runDirectMode($input, $output);
} finally {
\Laravel\Prompts\Prompt::terminal()->restoreTty();
$this->resetPromptEnvironment();
}
}
/**
* Run direct mode with command line options
*
* @param InputInterface $input
* @param OutputInterface $output
* @return int
*/
private function runDirectMode(InputInterface $input, OutputInterface $output): int
{
$showAll = (bool) $input->getOption(self::OPTION_SHOW_ALL);
$thirdPartyOnly = (bool) $input->getOption(self::OPTION_THIRD_PARTY_ONLY);
$includeVendor = (bool) $input->getOption(self::OPTION_INCLUDE_VENDOR);
$detailed = (bool) $input->getOption(self::OPTION_DETAILED);
$this->io->title('Hyvä Theme Compatibility Check');
return $this->runScan($showAll, $thirdPartyOnly, $includeVendor, $detailed, false, $output);
}
/**
* Run the actual compatibility scan
*
* @param bool $showAll
* @param bool $thirdPartyOnly
* @param bool $includeVendor
* @param bool $detailed
* @param bool $incompatibleOnly
* @param OutputInterface $output
* @return int
*/
private function runScan(
bool $showAll,
bool $thirdPartyOnly,
bool $includeVendor,
bool $detailed,
bool $incompatibleOnly,
OutputInterface $output,
): int {
// Determine filter logic:
// - thirdPartyOnly: Only scan non-Magento_* modules (default behavior)
// - includeVendor: Also scan Magento_* core modules
// - excludeVendor: Whether to exclude vendor/ directory (always false for now)
$scanThirdPartyOnly = !$includeVendor;
$excludeVendor = false;
// Run the compatibility check
$results = $this->compatibilityChecker->check(
$this->io,
$output,
$showAll,
$scanThirdPartyOnly,
$excludeVendor,
);
// Determine display mode:
// showAll = show all modules including compatible ones
// incompatibleOnly = show only modules with critical issues
// default = show modules with any issues (critical or warnings)
$displayShowAll = $showAll && !$incompatibleOnly;
// Display results
$this->displayResults($results, $displayShowAll);
// Display detailed issues if requested
if ($detailed && $results['hasIncompatibilities']) {
$this->displayDetailedIssues($results);
}
// Display summary
$this->displaySummary($results);
// Display recommendations if there are issues
if ($results['hasIncompatibilities']) {
$this->displayRecommendations();
}
// Add spacing before exit
$this->io->newLine();
// Return appropriate exit code
return $results['summary']['criticalIssues'] > 0 ? Cli::RETURN_FAILURE : Cli::RETURN_SUCCESS;
}
/**
* Display compatibility check results
*
* @param array $results
* @phpstan-param CheckResults $results
* @param bool $showAll
*/
private function displayResults(array $results, bool $showAll): void
{
$this->io->section('Compatibility Results');
$tableData = $this->compatibilityChecker->formatResultsForDisplay($results, $showAll);
if (empty($tableData)) {
$this->io->success('All scanned modules are compatible with Hyvä!');
return;
}
$this->io->table(['Module', 'Status', 'Issues'], $tableData);
}
/**
* Display detailed file-level issues
*
* @param array $results
* @phpstan-param CheckResults $results
*/
private function displayDetailedIssues(array $results): void
{
$this->io->section('Detailed Issues');
foreach ($results['modules'] as $moduleName => $moduleData) {
// Only show modules with issues
if ($moduleData['compatible'] && !$moduleData['hasWarnings']) {
continue;
}
$this->io->text(sprintf('<fg=cyan>%s</>', $moduleName));
$detailedIssues = $this->compatibilityChecker->getDetailedIssues($moduleName, $moduleData);
foreach ($detailedIssues as $fileData) {
$this->io->text(sprintf(' <fg=yellow>%s</>', $fileData['file']));
foreach ($fileData['issues'] as $issue) {
$color = $issue['severity'] === 'critical' ? 'red' : 'yellow';
$symbol = $issue['severity'] === 'critical' ? '✗' : '⚠';
$this->io->text(sprintf(
' <fg=%s>%s</> Line %d: %s',
$color,
$symbol,
$issue['line'],
$issue['description'],
));
}
}
$this->io->newLine();
}
}
/**
* Display summary statistics
*
* @param array $results
* @phpstan-param array{summary: CheckSummary} $results
*/
private function displaySummary(array $results): void
{
$summary = $results['summary'];
$this->io->section('Summary');
$summaryData = [
['Total Modules Scanned', $summary['total']],
new TableSeparator(),
['Compatible', sprintf('<fg=green>%d</>', $summary['compatible'])],
['Incompatible', sprintf('<fg=red>%d</>', $summary['incompatible'])],
['Hyvä-Aware Modules', sprintf('<fg=cyan>%d</>', $summary['hyvaAware'])],
new TableSeparator(),
['Critical Issues', sprintf('<fg=red>%d</>', $summary['criticalIssues'])],
['Warnings', sprintf('<fg=yellow>%d</>', $summary['warningIssues'])],
];
$this->io->table([], $summaryData);
// Final message
if ($summary['criticalIssues'] > 0) {
$this->io->newLine();
$this->io->writeln(sprintf(
'<fg=red>⚠</> Found <fg=red;options=bold>%d critical compatibility issue(s)</> in %d scanned modules.',
$summary['criticalIssues'],
$summary['total'],
));
$this->io->writeln('These modules require modifications to work with Hyvä themes.');
} elseif ($summary['warningIssues'] > 0) {
$this->io->newLine();
$this->io->writeln(sprintf(
'<fg=yellow>ℹ</> Found <fg=yellow;options=bold>%d warning(s)</> in %d scanned modules.',
$summary['warningIssues'],
$summary['total'],
));
$this->io->writeln('Review these modules for potential compatibility issues.');
} else {
$this->io->success('All scanned modules are Hyvä compatible!');
}
}
/**
* Display helpful recommendations
*/
private function displayRecommendations(): void
{
$this->io->section('Recommendations');
$recommendations = [
'• Check if Hyvä compatibility packages exist for incompatible modules',
'• Review <fg=cyan>https://hyva.io/compatibility</> for known solutions',
'• Consider refactoring RequireJS/Knockout code to Alpine.js',
'• Contact module vendors for Hyvä-compatible versions',
];
foreach ($recommendations as $recommendation) {
$this->io->text($recommendation);
}
}
}