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

SosaComputeModal   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 35
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A handle() 0 14 2
A __construct() 0 3 1
1
<?php
2
3
/**
4
 * webtrees-lib: MyArtJaub library for webtrees
5
 *
6
 * @package MyArtJaub\Webtrees
7
 * @subpackage Sosa
8
 * @author Jonathan Jaubart <[email protected]>
9
 * @copyright Copyright (c) 2009-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\Sosa\Http\RequestHandlers;
16
17
use Fig\Http\Message\StatusCodeInterface;
18
use Fisharebest\Webtrees\I18N;
19
use Fisharebest\Webtrees\Tree;
20
use Fisharebest\Webtrees\Validator;
21
use Fisharebest\Webtrees\Services\ModuleService;
22
use MyArtJaub\Webtrees\Module\Sosa\SosaModule;
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 the modal window for computing Sosa ancestors
29
 */
30
class SosaComputeModal implements RequestHandlerInterface
31
{
32
    /**
33
     * @var SosaModule|null $module
34
     */
35
    private $module;
36
37
    /**
38
     * Constructor for SosaComputeModal Request Handler
39
     *
40
     * @param ModuleService $module_service
41
     */
42
    public function __construct(ModuleService $module_service)
43
    {
44
        $this->module = $module_service->findByInterface(SosaModule::class)->first();
45
    }
46
47
    /**
48
     * {@inheritDoc}
49
     * @see \Psr\Http\Server\RequestHandlerInterface::handle()
50
     */
51
    public function handle(ServerRequestInterface $request): ResponseInterface
52
    {
53
        if ($this->module === null) {
54
            return response(view('modals/error', [
55
                'title' => I18N::translate('Error'),
56
                'error' => I18N::translate('The attached module could not be found.')
57
            ]));
58
        }
59
60
        $tree = Validator::attributes($request)->tree();
61
62
        return response(view($this->module->name() . '::modals/sosa-compute', [
63
            'tree'          => $tree,
64
            'xref'          => Validator::attributes($request)->isXref()->string('xref', '')
65
        ]));
66
    }
67
}
68