Completed
Push — issue#804 ( 62fcb8 )
by Guilherme
04:14
created

ChallengeFactory::create()   A

Complexity

Conditions 6
Paths 6

Size

Total Lines 19
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 6

Importance

Changes 0
Metric Value
cc 6
eloc 13
nc 6
nop 4
dl 0
loc 19
ccs 12
cts 12
cp 1
crap 6
rs 9.2222
c 0
b 0
f 0
1
<?php
2
/**
3
 * This file is part of the login-cidadao project or it's bundles.
4
 *
5
 * (c) Guilherme Donato <guilhermednt on github>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace PROCERGS\LoginCidadao\CpfVerificationBundle\Model;
12
13
class ChallengeFactory
14
{
15 11
    public static function create(
16
        string $challengeName,
17
        int $attemptsLeft,
18
        string $cpf,
19
        array $choices = null
20
    ): ChallengeInterface {
21
        switch ($challengeName) {
22 11
            case SelectMotherInitialsChallenge::CHALLENGE_NAME:
23 3
                return new SelectMotherInitialsChallenge($attemptsLeft, $cpf, $choices ?? []);
24 9
            case TypeBirthdayChallenge::CHALLENGE_NAME:
0 ignored issues
show
Coding Style introduced by
case statements should be defined using a colon.

As per the PSR-2 coding standard, case statements should not be wrapped in curly braces. There is no need for braces, since each case is terminated by the next break.

There is also the option to use a semicolon instead of a colon, this is discouraged because many programmers do not even know it works and the colon is universal between programming languages.

switch ($expr) {
    case "A": { //wrong
        doSomething();
        break;
    }
    case "B"; //wrong
        doSomething();
        break;
    case "C": //right
        doSomething();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
25 1
                return new TypeBirthdayChallenge($attemptsLeft, $cpf);
26 8
            case TypeMotherInitialsChallenge::CHALLENGE_NAME:
0 ignored issues
show
Coding Style introduced by
case statements should be defined using a colon.

As per the PSR-2 coding standard, case statements should not be wrapped in curly braces. There is no need for braces, since each case is terminated by the next break.

There is also the option to use a semicolon instead of a colon, this is discouraged because many programmers do not even know it works and the colon is universal between programming languages.

switch ($expr) {
    case "A": { //wrong
        doSomething();
        break;
    }
    case "B"; //wrong
        doSomething();
        break;
    case "C": //right
        doSomething();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
27 4
                return new TypeMotherInitialsChallenge($attemptsLeft, $cpf);
28 4
            case TypePostalCodeChallenge::CHALLENGE_NAME:
29 1
                return new TypePostalCodeChallenge($attemptsLeft, $cpf);
30 3
            case TypeVoterRegistrationChallenge::CHALLENGE_NAME:
31 2
                return new TypeVoterRegistrationChallenge($attemptsLeft, $cpf);
32
            default:
33 1
                throw new \InvalidArgumentException("Unsupported challenge '{$challengeName}'");
34
        }
35
    }
36
}
37