Completed
Push — master ( 054192...eb3219 )
by Torben
02:56 queued 01:47
created

MiscUtility::getSpamCheckChallenge()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.9666
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
declare(strict_types=1);
3
namespace DERHANSEN\SfEventMgt\Utility;
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
use TYPO3\CMS\Core\Utility\GeneralUtility;
13
14
/**
15
 * Class MiscUtility
16
 */
17
class MiscUtility
18
{
19
    /**
20
     * Returns, if the current TYPO3 version it 9.5 LTS
21
     *
22
     * @return bool
23
     */
24
    public static function isV9Lts(): bool
25
    {
26
        return version_compare(TYPO3_branch, '9.5', '=');
27
    }
28
29
    /**
30
     * Returns, if the current TYPO3 version it 8.7 LTS
31
     *
32
     * @return bool
33
     */
34
    public static function isV8Lts(): bool
35
    {
36
        return version_compare(TYPO3_branch, '8.7', '=');
37
    }
38
39
    /**
40
     * Returns chars extracted from a hmac for the challenge/response spam check
41
     *
42
     * @param int $eventUid
43
     * @return string
44
     */
45
    public static function getSpamCheckChallenge(int $eventUid): string
46
    {
47
        $hmac = GeneralUtility::hmac('event-' . $eventUid, 'sf_event_mgt');
48
        $chars = preg_replace('/[0-9]+/', '', $hmac);
49
50
        return preg_replace_callback('/\w.?/', function ($m) {
51
            return ucfirst($m[0]);
52
        }, $chars);
53
    }
54
}
55