Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
95.00% covered (success)
95.00%
19 / 20
83.33% covered (warning)
83.33%
5 / 6
CRAP
0.00% covered (danger)
0.00%
0 / 1
AboutLicensesDataProvider
94.74% covered (success)
94.74%
18 / 19
83.33% covered (warning)
83.33%
5 / 6
9.01
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 supports
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getDefaultSortColumn
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 loadRows
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 matchFilter
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 fetchFacetedFilterOptions
100.00% covered (success)
100.00%
14 / 14
100.00% covered (success)
100.00%
1 / 1
4
1<?php
2
3declare(strict_types=1);
4
5/** @license For full copyright and license information, please see the LICENSE.md file. */
6
7namespace App\Modules\About\Application\DataSource;
8
9defined('AMMONLY_APP') || exit('Direct script access is forbidden.');
10
11use App\Core\Engine\Domain\DataSource\DynamicDataProviderInterface;
12use App\Core\Engine\Domain\Model\ModuleMetadata;
13use App\Core\Engine\Domain\Model\PermissionContext;
14use App\Core\Grid\GridRequest;
15use App\Core\Grid\GridResult;
16use App\Modules\About\Application\Service\ComposerPackagesLoader;
17
18/**
19 * About Licenses Dynamic Data Provider.
20 *
21 * Provides in-memory Composer packages DataGrid dataset with filtering, sorting, and pagination.
22 *
23 * @package App\Modules\About\Application\DataSource
24 */
25final readonly class AboutLicensesDataProvider extends AbstractInMemoryDataProvider
26{
27    /**
28     * AboutLicensesDataProvider constructor.
29     *
30     * @param string|null $installedJsonPath Optional explicit path to installed.json.
31     */
32    public function __construct(
33        private ?string $installedJsonPath = null
34    ) {
35    }
36
37    /** {@inheritdoc} */
38    public function supports(string $moduleName): bool
39    {
40        return $moduleName === 'about_licenses';
41    }
42
43    /** {@inheritdoc} */
44    protected function getDefaultSortColumn(): string
45    {
46        return 'name';
47    }
48
49    /** {@inheritdoc} */
50    protected function loadRows(): array
51    {
52        return ComposerPackagesLoader::load($this->installedJsonPath);
53    }
54
55    /** {@inheritdoc} */
56    protected function matchFilter(array $row, string $column, string $filterValue): bool
57    {
58        return ComposerPackagesLoader::matchPackageFilter($row, $column, $filterValue);
59    }
60
61    /** {@inheritdoc} */
62    public function fetchFacetedFilterOptions(
63        ModuleMetadata    $module,
64        PermissionContext $context
65    ): array {
66        $packages = $this->loadRows();
67        $licenses = [];
68        $types    = [];
69
70        foreach ($packages as $pkg) {
71            $lic = (string) ($pkg['license'] ?? '');
72            if ($lic !== '') {
73                $licenses[$lic] = ['id' => $lic, 'label' => $lic];
74            }
75            $typ = (string) ($pkg['type'] ?? '');
76            if ($typ !== '') {
77                $types[$typ] = ['id' => $typ, 'label' => $typ];
78            }
79        }
80
81        return [
82            'license' => array_values($licenses),
83            'type'    => array_values($types),
84        ];
85    }
86}