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

SosaIconHook   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 12
dl 0
loc 48
rs 10
c 0
b 0
f 0
wmc 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A recordNameAppend() 0 9 3
A recordNamePrepend() 0 3 1
A __construct() 0 4 1
A module() 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) 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\Sosa\Hooks;
16
17
use Fisharebest\Webtrees\Auth;
18
use Fisharebest\Webtrees\GedcomRecord;
19
use Fisharebest\Webtrees\Individual;
20
use Fisharebest\Webtrees\Module\ModuleInterface;
21
use MyArtJaub\Webtrees\Contracts\Hooks\RecordNameTextExtenderInterface;
22
use MyArtJaub\Webtrees\Module\Sosa\Services\SosaRecordsService;
23
24
/**
25
 * Hook for displaying an icon next to Sosa ancestors' display name.
26
 */
27
class SosaIconHook implements RecordNameTextExtenderInterface
28
{
29
    private ModuleInterface $module;
30
    private SosaRecordsService $sosa_records_service;
31
32
    /**
33
     * Constructor for SosaIconHook
34
     *
35
     * @param ModuleInterface $module
36
     * @param SosaRecordsService $sosa_records_service
37
     */
38
    public function __construct(ModuleInterface $module, SosaRecordsService $sosa_records_service)
39
    {
40
        $this->module = $module;
41
        $this->sosa_records_service = $sosa_records_service;
42
    }
43
44
    /**
45
     * {@inheritDoc}
46
     * @see \MyArtJaub\Webtrees\Contracts\Hooks\HookInterface::module()
47
     */
48
    public function module(): ModuleInterface
49
    {
50
        return $this->module;
51
    }
52
53
    /**
54
     * {@inheritDoc}
55
     * @see \MyArtJaub\Webtrees\Contracts\Hooks\RecordNameTextExtenderInterface::recordNamePrepend()
56
     */
57
    public function recordNamePrepend(GedcomRecord $record, bool $use_long = false, string $size = ''): string
58
    {
59
        return '';
60
    }
61
62
    /**
63
     * {@inheritDoc}
64
     * @see \MyArtJaub\Webtrees\Contracts\Hooks\RecordNameTextExtenderInterface::recordNameAppend()
65
     */
66
    public function recordNameAppend(GedcomRecord $record, bool $use_long = false, string $size = ''): string
67
    {
68
        if (
69
            $record instanceof Individual &&
70
            $this->sosa_records_service->isSosa($record->tree(), Auth::user(), $record)
71
        ) {
72
            return view($this->module->name() . '::icons/sosa', [ 'size_style' => $size ]);
73
        }
74
        return '';
75
    }
76
}
77