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

ChallengeResponseSpamCheck   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 2
dl 0
loc 22
rs 10
c 0
b 0
f 0

1 Method

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