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

FactSourceTextExtenderCollector   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 14
dl 0
loc 53
rs 10
c 0
b 0
f 0
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A hookInterface() 0 3 1
A description() 0 3 1
A title() 0 3 1
A factSourceAppend() 0 7 1
A factSourcePrepend() 0 7 1
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\Hooks;
16
17
use Fisharebest\Webtrees\I18N;
18
use Fisharebest\Webtrees\Tree;
19
use MyArtJaub\Webtrees\Common\Hooks\AbstractHookCollector;
20
use MyArtJaub\Webtrees\Contracts\Hooks\FactSourceTextExtenderInterface;
21
22
/**
23
 * Hook collector for hooks implementing FactSourceTextExtenderInterface.
24
 * Used to extend the title of source citations.
25
 *
26
 * @extends AbstractHookCollector<FactSourceTextExtenderInterface>
27
 */
28
class FactSourceTextExtenderCollector extends AbstractHookCollector implements FactSourceTextExtenderInterface
29
{
30
    /**
31
     * {@inheritDoc}
32
     * @see \MyArtJaub\Webtrees\Common\Hooks\AbstractHookCollector::title()
33
     */
34
    public function title(): string
35
    {
36
        return I18N::translate('Text extender for source citations’ title');
37
    }
38
39
    /**
40
     * {@inheritDoc}
41
     * @see \MyArtJaub\Webtrees\Common\Hooks\AbstractHookCollector::description()
42
     */
43
    public function description(): string
44
    {
45
        return I18N::translate('Extends the title of source citations with additional text or icons.');
46
    }
47
48
    /**
49
     * {@inheritDoc}
50
     * @see \MyArtJaub\Webtrees\Common\Hooks\AbstractHookCollector::hookInterface()
51
     */
52
    public function hookInterface(): string
53
    {
54
        return FactSourceTextExtenderInterface::class;
55
    }
56
57
    /**
58
     * {@inheritDoc}
59
     * @see \MyArtJaub\Webtrees\Contracts\Hooks\FactSourceTextExtenderInterface::factSourcePrepend()
60
     */
61
    public function factSourcePrepend(Tree $tree, $fact): string
62
    {
63
        return $this->hooks()
64
            ->map(
65
                fn(FactSourceTextExtenderInterface $hook) =>
66
                    $hook->factSourcePrepend($tree, $fact)
67
            )->implode('');
68
    }
69
70
    /**
71
     * {@inheritDoc}
72
     * @see \MyArtJaub\Webtrees\Contracts\Hooks\FactSourceTextExtenderInterface::factSourceAppend()
73
     */
74
    public function factSourceAppend(Tree $tree, $fact): string
75
    {
76
        return $this->hooks()
77
            ->map(
78
                fn(FactSourceTextExtenderInterface $hook) =>
79
                    $hook->factSourcePrepend($tree, $fact)
80
            )->implode('');
81
    }
82
}
83