Completed
Pull Request — master (#18)
by Tomas Norre
03:41
created

getIdentifierValue()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 5.1576

Importance

Changes 0
Metric Value
dl 0
loc 12
ccs 7
cts 12
cp 0.5833
rs 9.8666
c 0
b 0
f 0
cc 4
nc 3
nop 0
crap 5.1576
1
<?php
2
namespace Aoe\FeloginBruteforceProtection\Domain\Service;
3
4
/***************************************************************
5
 *  Copyright notice
6
 *
7
 *  (c) 2019 AOE GmbH <[email protected]>
8
 *
9
 *  All rights reserved
10
 *
11
 *  This script is part of the TYPO3 project. The TYPO3 project is
12
 *  free software; you can redistribute it and/or modify
13
 *  it under the terms of the GNU General Public License as published by
14
 *  the Free Software Foundation; either version 3 of the License, or
15
 *  (at your option) any later version.
16
 *
17
 *  The GNU General Public License can be found at
18
 *  http://www.gnu.org/copyleft/gpl.html.
19
 *
20
 *  This script is distributed in the hope that it will be useful,
21
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
22
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23
 *  GNU General Public License for more details.
24
 *
25
 *  This copyright notice MUST APPEAR in all copies of the script!
26
 ***************************************************************/
27
28
use TYPO3\CMS\Frontend\Authentication\FrontendUserAuthentication;
29
30
/**
31
 * @package Aoe\FeloginBruteforceProtection\Domain\Service
32
 * @author Patrick Roos <[email protected]>
33
 */
34
class RestrictionIdentifierFrontendName extends RestrictionIdentifierAbstract
35
{
36
    /**
37
     * @var FrontendUserAuthentication
38
     */
39
    protected $frontendUserAuthentication;
40
41
    /**
42
     * the value of the restriction identifier
43
     * @return string
44
     */
45 8
    public function getIdentifierValue()
46
    {
47 8
        if (!isset($this->identifierValue)) {
48 8
            $loginFormData = $this->frontendUserAuthentication->getLoginFormData();
49 8
            if (isset($loginFormData['uname']) &&  !empty($loginFormData['uname'])) {
50 4
                $this->identifierValue = $loginFormData['uname'];
0 ignored issues
show
Documentation Bug introduced by
The property $identifierValue was declared of type string, but $loginFormData['uname'] is of type integer. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
51
            } else {
52 4
                $this->identifierValue = '';
53
            }
54
        }
55 8
        return $this->identifierValue;
56
    }
57
58
    /**
59
     * no precondition for frontend name
60
     * @return boolean
61
     */
62 2
    public function checkPreconditions()
63
    {
64 2
        return true;
65
    }
66
67
    /**
68
     * @param FrontendUserAuthentication $frontendUserAuthentication
69
     * @return void
70
     **/
71 11
    public function setFrontendUserAuthentication(FrontendUserAuthentication $frontendUserAuthentication)
72
    {
73 11
        $this->frontendUserAuthentication = $frontendUserAuthentication;
74 11
    }
75
}
76