Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
97.50% |
39 / 40 |
|
75.00% |
3 / 4 |
CRAP | |
0.00% |
0 / 1 |
| AboutRequirementsDataProvider | |
97.44% |
38 / 39 |
|
75.00% |
3 / 4 |
10 | |
0.00% |
0 / 1 |
| supports | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getDefaultSortColumn | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| fetchFacetedFilterOptions | |
100.00% |
13 / 13 |
|
100.00% |
1 / 1 |
3 | |||
| loadRows | |
100.00% |
24 / 24 |
|
100.00% |
1 / 1 |
5 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | /** @license For full copyright and license information, please see the LICENSE.md file. */ |
| 6 | |
| 7 | namespace App\Modules\About\Application\DataSource; |
| 8 | |
| 9 | defined('AMMONLY_APP') || exit('Direct script access is forbidden.'); |
| 10 | |
| 11 | use App\Core\Engine\Domain\DataSource\DynamicDataProviderInterface; |
| 12 | use App\Core\Engine\Domain\Model\ModuleMetadata; |
| 13 | use App\Core\Engine\Domain\Model\PermissionContext; |
| 14 | use App\Core\Grid\GridRequest; |
| 15 | use App\Core\Grid\GridResult; |
| 16 | use App\Modules\About\Application\Service\SystemDiagnosticsServiceInterface; |
| 17 | |
| 18 | /** |
| 19 | * About Requirements Dynamic Data Provider. |
| 20 | * |
| 21 | * Exposes system requirements and runtime environment diagnostics as DataGrid rows. |
| 22 | * |
| 23 | * @package App\Modules\About\Application\DataSource |
| 24 | */ |
| 25 | final readonly class AboutRequirementsDataProvider extends AbstractDiagnosticsDataProvider |
| 26 | { |
| 27 | /** {@inheritdoc} */ |
| 28 | public function supports(string $moduleName): bool |
| 29 | { |
| 30 | return $moduleName === 'about_requirements'; |
| 31 | } |
| 32 | |
| 33 | /** {@inheritdoc} */ |
| 34 | protected function getDefaultSortColumn(): string |
| 35 | { |
| 36 | return 'category'; |
| 37 | } |
| 38 | |
| 39 | /** {@inheritdoc} */ |
| 40 | public function fetchFacetedFilterOptions( |
| 41 | ModuleMetadata $module, |
| 42 | PermissionContext $context |
| 43 | ): array { |
| 44 | $rows = $this->loadRows(); |
| 45 | $categories = []; |
| 46 | |
| 47 | foreach ($rows as $row) { |
| 48 | $cat = (string) ($row['category'] ?? ''); |
| 49 | if ($cat !== '') { |
| 50 | $categories[$cat] = ['id' => $cat, 'label' => $cat]; |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | return [ |
| 55 | 'category' => array_values($categories), |
| 56 | 'status' => [ |
| 57 | ['id' => '1', 'label' => 'Passed (OK)'], |
| 58 | ['id' => '0', 'label' => 'Failed / Error'], |
| 59 | ], |
| 60 | ]; |
| 61 | } |
| 62 | |
| 63 | /** |
| 64 | * Evaluates diagnostics and returns structured flat rows. |
| 65 | * |
| 66 | * @return array<int, array<string, mixed>> List of diagnostic rows. |
| 67 | */ |
| 68 | protected function loadRows(): array |
| 69 | { |
| 70 | $report = $this->diagnosticsService->runDiagnostics(); |
| 71 | $categories = $report['categories'] ?? []; |
| 72 | $rows = []; |
| 73 | $id = 1; |
| 74 | |
| 75 | foreach ($categories as $catKey => $catData) { |
| 76 | if ($catKey === 'security') { |
| 77 | continue; |
| 78 | } |
| 79 | $catLabel = (string) ($catData['label'] ?? $catKey); |
| 80 | $checks = $catData['items'] ?? $catData['checks'] ?? []; |
| 81 | |
| 82 | foreach ($checks as $check) { |
| 83 | $statusPassed = ($check['status'] ?? '') === 'pass'; |
| 84 | |
| 85 | $rows[] = [ |
| 86 | 'id' => $id++, |
| 87 | 'category' => $catLabel, |
| 88 | 'parameter' => (string) ($check['label'] ?? $check['parameter'] ?? $check['name'] ?? ''), |
| 89 | 'required_value' => (string) ( |
| 90 | $check['recommended_value'] ?? $check['required'] ?? $check['minimum_value'] ?? '-' |
| 91 | ), |
| 92 | 'current_value' => (string) ($check['actual_value'] ?? $check['current'] ?? '-'), |
| 93 | 'status' => $statusPassed ? 1 : 0, |
| 94 | 'recommendation' => (string) ( |
| 95 | $check['description'] ?? $check['help'] ?? $check['recommendation'] ?? '' |
| 96 | ), |
| 97 | ]; |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | return $rows; |
| 102 | } |
| 103 | } |