Skip to content

Commit 732dc97

Browse files
committed
fix: update phpstan types and annotations for compatibility
1 parent d85bd05 commit 732dc97

4 files changed

Lines changed: 32 additions & 13 deletions

File tree

src/Console/Command/Hyva/CompatibilityCheckCommand.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919
*
2020
* Scans modules for RequireJS, Knockout.js, jQuery, and UI Components usage
2121
* that would be incompatible with Hyvä themes.
22+
*
23+
* @phpstan-import-type CheckResults from \OpenForgeProject\MageForge\Service\Hyva\CompatibilityChecker
24+
* @phpstan-import-type CheckSummary from \OpenForgeProject\MageForge\Service\Hyva\CompatibilityChecker
25+
* @phpstan-import-type ModuleEntry from \OpenForgeProject\MageForge\Service\Hyva\CompatibilityChecker
2226
*/
2327
class CompatibilityCheckCommand extends AbstractCommand
2428
{
@@ -271,7 +275,7 @@ private function runScan(
271275
* Display compatibility check results
272276
*
273277
* @param array $results
274-
* @phpstan-param array{modules: array<string, array{compatible: bool, hasWarnings: bool, scanResult: array{files: array<string, array<int, array{description: string, severity: string, line: int, pattern: string}>>, totalIssues: int, criticalIssues: int}, moduleInfo: array{name: string, version: string, isHyvaAware: bool}}>, hasIncompatibilities: bool} $results
278+
* @phpstan-param CheckResults $results
275279
* @param bool $showAll
276280
*/
277281
private function displayResults(array $results, bool $showAll): void
@@ -292,7 +296,7 @@ private function displayResults(array $results, bool $showAll): void
292296
* Display detailed file-level issues
293297
*
294298
* @param array $results
295-
* @phpstan-param array{modules: array<string, array{compatible: bool, hasWarnings: bool, scanResult: array{files: array<string, array<int, array{description: string, severity: string, line: int, pattern: string}>>, totalIssues: int, criticalIssues: int}, moduleInfo: array{name: string, version: string, isHyvaAware: bool}}>, hasIncompatibilities: bool} $results
299+
* @phpstan-param CheckResults $results
296300
*/
297301
private function displayDetailedIssues(array $results): void
298302
{
@@ -333,7 +337,7 @@ private function displayDetailedIssues(array $results): void
333337
* Display summary statistics
334338
*
335339
* @param array $results
336-
* @phpstan-param array{summary: array{total: int, compatible: int, incompatible: int, hyvaAware: int, criticalIssues: int, warningIssues: int}} $results
340+
* @phpstan-param array{summary: CheckSummary} $results
337341
*/
338342
private function displaySummary(array $results): void
339343
{

src/Service/Hyva/CompatibilityChecker.php

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,21 @@
99
use Symfony\Component\Console\Output\OutputInterface;
1010
use Symfony\Component\Console\Style\SymfonyStyle;
1111

12+
// phpcs:disable Generic.Files.LineLength.TooLong
1213
/**
1314
* Service that orchestrates Hyvä compatibility checking across Magento modules
1415
*
1516
* This service scans modules, detects incompatibilities with Hyvä theme framework,
1617
* and provides formatted results with summary statistics.
18+
*
19+
* @phpstan-import-type ScanIssue from IncompatibilityDetector
20+
* @phpstan-import-type ScanResult from ModuleScanner
21+
* @phpstan-import-type ModuleInfo from ModuleScanner
22+
* @phpstan-type ModuleEntry array{compatible: bool, hasWarnings: bool, scanResult: ScanResult, moduleInfo: ModuleInfo}
23+
* @phpstan-type CheckSummary array{total: int, compatible: int, incompatible: int, hyvaAware: int, criticalIssues: int, warningIssues: int}
24+
* @phpstan-type CheckResults array{modules: array<string, ModuleEntry>, summary: CheckSummary, hasIncompatibilities: bool}
1725
*/
26+
// phpcs:enable Generic.Files.LineLength.TooLong
1827
class CompatibilityChecker
1928
{
2029
/**
@@ -37,7 +46,7 @@ public function __construct(
3746
* @param bool $excludeVendor Whether to exclude modules from the vendor/ directory
3847
* @return array<string, mixed> Results with structure: ['modules' => [], 'summary' => [],
3948
* 'hasIncompatibilities' => bool]
40-
* @phpstan-return array{modules: array<string, array{compatible: bool, hasWarnings: bool, scanResult: array{files: array<string, array<int, array{description: string, severity: string, line: int, pattern: string}>>, totalIssues: int, criticalIssues: int}, moduleInfo: array{name: string, version: string, isHyvaAware: bool}}>, summary: array{total: int, compatible: int, incompatible: int, hyvaAware: int, criticalIssues: int, warningIssues: int}, hasIncompatibilities: bool}
49+
* @phpstan-return CheckResults
4150
*/
4251
public function check(
4352
SymfonyStyle $io,
@@ -140,7 +149,7 @@ private function isMagentoModule(string $moduleName): bool
140149
* Format results for display
141150
*
142151
* @param array $results
143-
* @phpstan-param array{modules: array<string, array{compatible: bool, hasWarnings: bool, scanResult: array{files: array<string, array<int, array{description: string, severity: string, line: int, pattern: string}>>, totalIssues: int, criticalIssues: int}, moduleInfo: array{name: string, version: string, isHyvaAware: bool}}>} $results
152+
* @phpstan-param CheckResults $results
144153
* @param bool $showAll
145154
* @return array<int, array<int, string>>
146155
*/
@@ -168,7 +177,7 @@ public function formatResultsForDisplay(array $results, bool $showAll = false):
168177
* Get status display string with colors
169178
*
170179
* @param array $moduleData
171-
* @phpstan-param array{compatible: bool, hasWarnings: bool, scanResult: array<string, mixed>, moduleInfo: array<string, mixed>} $moduleData
180+
* @phpstan-param ModuleEntry $moduleData
172181
* @return string
173182
*/
174183
private function getStatusDisplay(array $moduleData): string
@@ -192,7 +201,7 @@ private function getStatusDisplay(array $moduleData): string
192201
* Get issues display string
193202
*
194203
* @param array $moduleData
195-
* @phpstan-param array{compatible: bool, hasWarnings: bool, scanResult: array{totalIssues: int, criticalIssues: int}, moduleInfo: array<string, mixed>} $moduleData
204+
* @phpstan-param ModuleEntry $moduleData
196205
* @return string
197206
*/
198207
private function getIssuesDisplay(array $moduleData): string
@@ -223,8 +232,8 @@ private function getIssuesDisplay(array $moduleData): string
223232
*
224233
* @param string $moduleName
225234
* @param array $moduleData
226-
* @phpstan-param array{compatible: bool, hasWarnings: bool, scanResult: array{files: array<string, array<int, array{description: string, severity: string, line: int, pattern: string}>>, totalIssues: int, criticalIssues: int}, moduleInfo: array{name: string, version: string, isHyvaAware: bool}} $moduleData
227-
* @return array<int, array{file: string, issues: array<int, array{description: string, severity: string, line: int, pattern: string}>}>
235+
* @phpstan-param ModuleEntry $moduleData
236+
* @return array<int, array{file: string, issues: array<int, ScanIssue>}>
228237
*/
229238
public function getDetailedIssues(string $moduleName, array $moduleData): array
230239
{

src/Service/Hyva/IncompatibilityDetector.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
*
1212
* Uses pattern matching to identify RequireJS, Knockout.js, jQuery, and UI Components
1313
* usage that would be problematic in a Hyvä environment.
14+
*
15+
* @phpstan-type ScanIssue array{description: string, severity: string, line: int, pattern: string}
1416
*/
1517
class IncompatibilityDetector
1618
{
@@ -107,7 +109,7 @@ public function __construct(
107109
*
108110
* @param string $filePath
109111
* @return array<int, array<string, mixed>> Array of issues with keys: pattern, description, severity, line
110-
* @phpstan-return array<int, array{description: string, severity: string, line: int, pattern: string}>
112+
* @phpstan-return array<int, ScanIssue>
111113
*/
112114
public function detectInFile(string $filePath): array
113115
{
@@ -154,7 +156,7 @@ private function mapExtensionToType(string $extension): string
154156
* @param array $lines
155157
* @param array $patterns
156158
* @return array<int, array<string, mixed>>
157-
* @phpstan-return array<int, array{description: string, severity: string, line: int, pattern: string}>
159+
* @phpstan-return array<int, ScanIssue>
158160
* @phpstan-param array<int, string> $lines
159161
* @phpstan-param array<int, array{pattern: string, description: string, severity: string}> $patterns
160162
*/

src/Service/Hyva/ModuleScanner.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
*
1212
* Recursively scans JavaScript, XML, and PHTML files within module directories
1313
* to identify patterns that may be incompatible with Hyvä themes.
14+
*
15+
* @phpstan-import-type ScanIssue from IncompatibilityDetector
16+
* @phpstan-type ScanResult array{files: array<string, array<int, ScanIssue>>, totalIssues: int, criticalIssues: int}
17+
* @phpstan-type ModuleInfo array{name: string, version: string, isHyvaAware: bool}
1418
*/
1519
class ModuleScanner
1620
{
@@ -32,7 +36,7 @@ public function __construct(
3236
*
3337
* @param string $modulePath
3438
* @return array<string, mixed> Array with structure: ['files' => [], 'totalIssues' => int, 'criticalIssues' => int]
35-
* @phpstan-return array{files: array<string, array<int, array{description: string, severity: string, line: int, pattern: string}>>, totalIssues: int, criticalIssues: int}
39+
* @phpstan-return ScanResult
3640
*/
3741
public function scanModule(string $modulePath): array
3842
{
@@ -176,7 +180,7 @@ public function hasHyvaCompatibilityPackage(string $modulePath): bool
176180
*
177181
* @param string $modulePath
178182
* @return array<string, mixed>
179-
* @phpstan-return array{name: string, version: string, isHyvaAware: bool}
183+
* @phpstan-return ModuleInfo
180184
*/
181185
public function getModuleInfo(string $modulePath): array
182186
{

0 commit comments

Comments
 (0)