Passed
Push — master ( 48f748...8ce03c )
by Nathan
06:40 queued 03:18
created

EditViewHelper   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 16
dl 0
loc 42
rs 10
c 0
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A render() 0 15 3
A initializeArguments() 0 11 1
1
<?php
2
3
/*
4
 * Copyright (C) 2018
5
 * Nathan Boiron <[email protected]>
6
 * Romain Canon <[email protected]>
7
 *
8
 * This file is part of the TYPO3 NotiZ project.
9
 * It is free software; you can redistribute it and/or modify it
10
 * under the terms of the GNU General Public License, either
11
 * version 3 of the License, or any later version.
12
 *
13
 * For the full copyright and license information, see:
14
 * http://www.gnu.org/licenses/gpl-3.0.html
15
 */
16
17
namespace CuyZ\Notiz\ViewHelpers\Notification\Link;
18
19
use CuyZ\Notiz\Core\Notification\Editable;
20
use CuyZ\Notiz\Core\Notification\Notification;
21
use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractTagBasedViewHelper;
22
23
class EditViewHelper extends AbstractTagBasedViewHelper
24
{
25
    /**
26
     * @var string
27
     */
28
    protected $tagName = 'a';
29
30
    /**
31
     * @inheritdoc
32
     */
33
    public function initializeArguments()
34
    {
35
        parent::initializeArguments();
36
37
        $this->registerUniversalTagAttributes();
38
39
        $this->registerArgument(
40
            'notification',
41
            Notification::class,
42
            '',
43
            true
44
        );
45
    }
46
47
    /**
48
     * @inheritdoc
49
     */
50
    public function render()
51
    {
52
        /** @var Notification $notification */
53
        $notification = $this->arguments['notification'];
54
55
        if (!$notification instanceof Editable
56
            || !$notification->isEditable()
57
        ) {
58
            return '';
59
        }
60
61
        $this->tag->addAttribute('href', $notification->getEditionUri());
62
        $this->tag->setContent($this->renderChildren());
63
64
        return $this->tag->render();
65
    }
66
}
67