Issues (2502)

RequestHandlers/AbstractModuleComponentPage.php (3 issues)

Labels
Severity
1
<?php
2
3
/**
4
 * webtrees: online genealogy
5
 * Copyright (C) 2025 webtrees development team
6
 * This program is free software: you can redistribute it and/or modify
7
 * it under the terms of the GNU General Public License as published by
8
 * the Free Software Foundation, either version 3 of the License, or
9
 * (at your option) any later version.
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
 * GNU General Public License for more details.
14
 * You should have received a copy of the GNU General Public License
15
 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16
 */
17
18
declare(strict_types=1);
19
20
namespace Fisharebest\Webtrees\Http\RequestHandlers;
21
22
use Fisharebest\Webtrees\Auth;
0 ignored issues
show
The type Fisharebest\Webtrees\Auth was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
23
use Fisharebest\Webtrees\Http\ViewResponseTrait;
24
use Fisharebest\Webtrees\Module\ModuleInterface;
25
use Fisharebest\Webtrees\Services\ModuleService;
0 ignored issues
show
The type Fisharebest\Webtrees\Services\ModuleService was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
26
use Fisharebest\Webtrees\Services\TreeService;
0 ignored issues
show
The type Fisharebest\Webtrees\Services\TreeService was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
27
use Fisharebest\Webtrees\Tree;
28
use Psr\Http\Message\ResponseInterface;
29
use Psr\Http\Server\RequestHandlerInterface;
30
31
abstract class AbstractModuleComponentPage implements RequestHandlerInterface
32
{
33
    use ViewResponseTrait;
34
35
    public function __construct(
36
        private readonly ModuleService $module_service,
37
        private readonly TreeService $tree_service,
38
    ) {
39
    }
40
41
    /**
42
     * @template T of ModuleInterface
43
     *
44
     * @param class-string<T> $interface
45
     */
46
    protected function listComponents(string $interface, string $title, string $description): ResponseInterface
47
    {
48
        $this->layout = 'layouts/administration';
49
50
        $modules      = $this->module_service->findByInterface($interface, true, true);
51
        $uses_access  = $this->module_service->componentsWithAccess()->containsStrict($interface);
52
        $uses_sorting = $this->module_service->componentsWithOrder()->containsStrict($interface);
53
54
        $access_summary = $modules
55
            ->mapWithKeys(function (ModuleInterface $module) use ($interface): array {
56
                $access_levels = $this->tree_service->all()
57
                    ->map(static fn (Tree $tree): int => $module->accessLevel($tree, $interface))
58
                    ->uniqueStrict()
59
                    ->values()
60
                    ->map(static fn (int $level): string => Auth::accessLevelNames()[$level])
61
                    ->all();
62
63
                return [$module->name() => $access_levels];
64
            })
65
            ->all();
66
67
        return $this->viewResponse('admin/components', [
68
            'description'    => $description,
69
            'interface'      => $interface,
70
            'modules'        => $modules,
71
            'title'          => $title,
72
            'trees'          => $this->tree_service->all(),
73
            'uses_access'    => $uses_access,
74
            'uses_sorting'   => $uses_sorting,
75
            'access_summary' => $access_summary,
76
        ]);
77
    }
78
}
79