Passed
Push — feature/code-analysis ( e964aa...4fe35d )
by Jonathan
14:33
created

AdminConfigPage   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 12
dl 0
loc 34
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A handle() 0 11 2
1
<?php
2
3
/**
4
 * webtrees-lib: MyArtJaub library for webtrees
5
 *
6
 * @package MyArtJaub\Webtrees
7
 * @subpackage Hooks
8
 * @author Jonathan Jaubart <[email protected]>
9
 * @copyright Copyright (c) 2011-2022, Jonathan Jaubart
10
 * @license http://www.gnu.org/licenses/gpl.html GNU General Public License, version 3
11
 */
12
13
declare(strict_types=1);
14
15
namespace MyArtJaub\Webtrees\Module\Hooks\Http\RequestHandlers;
16
17
use Fisharebest\Webtrees\I18N;
18
use Fisharebest\Webtrees\Http\Exceptions\HttpNotFoundException;
19
use Fisharebest\Webtrees\Http\ViewResponseTrait;
20
use Fisharebest\Webtrees\Services\ModuleService;
21
use MyArtJaub\Webtrees\Module\Hooks\HooksModule;
22
use MyArtJaub\Webtrees\Module\Hooks\Services\HookService;
23
use Psr\Http\Message\ResponseInterface;
24
use Psr\Http\Message\ServerRequestInterface;
25
use Psr\Http\Server\RequestHandlerInterface;
26
27
/**
28
 * Request handler for displaying configuration of the module
29
 */
30
class AdminConfigPage implements RequestHandlerInterface
31
{
32
    use ViewResponseTrait;
33
34
    private ?HooksModule $module;
35
    private HookService $hook_service;
36
37
    /**
38
     * Constructor for AdminConfigPage Request Handler
39
     *
40
     * @param ModuleService $module_service
41
     * @param HookService $hook_service
42
     */
43
    public function __construct(ModuleService $module_service, HookService $hook_service)
44
    {
45
        $this->module = $module_service->findByInterface(HooksModule::class)->first();
46
        $this->hook_service = $hook_service;
47
    }
48
49
    /**
50
     * {@inheritDoc}
51
     * @see \Psr\Http\Server\RequestHandlerInterface::handle()
52
     */
53
    public function handle(ServerRequestInterface $request): ResponseInterface
54
    {
55
        $this->layout = 'layouts/administration';
56
57
        if ($this->module === null) {
58
            throw new HttpNotFoundException(I18N::translate('The attached module could not be found.'));
59
        }
60
61
        return $this->viewResponse($this->module->name() . '::admin/config', [
62
            'title'                 =>  $this->module->title(),
63
            'hook_interfaces_list'  =>  $this->hook_service->all(true)
64
        ]);
65
    }
66
}
67