ChallengeResponseSpamCheck   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 9
c 0
b 0
f 0
dl 0
loc 19
rs 10
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A isFailed() 0 14 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\SpamChecks;
13
14
use DERHANSEN\SfEventMgt\Utility\MiscUtility;
15
16
class ChallengeResponseSpamCheck extends AbstractSpamCheck
17
{
18
    /**
19
     * Checks, if the cr-response field matches the expected ROT13 encrypted/obfuscated string.
20
     */
21
    public function isFailed(): bool
22
    {
23
        if (!isset($this->arguments['registration']['cr-response'])) {
24
            return true;
25
        }
26
27
        $challenge =  MiscUtility::getSpamCheckChallenge((int)$this->arguments['event']);
28
        $originalChallenge = ($this->configuration['prefix'] ?? 'SfEventMgt') .
29
            $challenge . ($this->configuration['postfix'] ?? 'TYPO3');
30
31
        $expectedResponse = str_rot13($originalChallenge);
32
        $response = $this->arguments['registration']['cr-response'] ?? '';
33
34
        return $expectedResponse !== $response;
35
    }
36
}
37