HmacViewHelper   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 10
dl 0
loc 27
rs 10
c 2
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A initializeArguments() 0 4 1
A injectHashService() 0 3 1
A render() 0 9 2
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Extension "sf_event_mgt" for TYPO3 CMS.
7
 *
8
 * For the full copyright and license information, please read the
9
 * LICENSE.txt file that was distributed with this source code.
10
 */
11
12
namespace DERHANSEN\SfEventMgt\ViewHelpers\Registration;
13
14
use DERHANSEN\SfEventMgt\Domain\Model\Registration;
15
use DERHANSEN\SfEventMgt\Security\HashScope;
16
use TYPO3\CMS\Core\Crypto\HashService;
17
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
18
19
/**
20
 * Hmac ViewHelper for registrations
21
 */
22
class HmacViewHelper extends AbstractViewHelper
23
{
24
    protected HashService $hashService;
25
26
    public function injectHashService(HashService $hashService): void
27
    {
28
        $this->hashService = $hashService;
29
    }
30
31
    public function initializeArguments(): void
32
    {
33
        parent::initializeArguments();
34
        $this->registerArgument('registration', 'object', 'Registration', true);
35
    }
36
37
    /**
38
     * Returns the hmac for the given registration in order to cancel the registration
39
     */
40
    public function render(): string
41
    {
42
        $registration = $this->arguments['registration'];
43
        $result = '';
44
        if (is_a($registration, Registration::class)) {
45
            $result = $this->hashService->hmac('reg-' . $registration->getUid(), HashScope::RegistrationUid->value);
46
        }
47
48
        return $result;
49
    }
50
}
51