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

ChallengeFactory   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 14
dl 0
loc 21
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0
wmc 6

1 Method

Rating   Name   Duplication   Size   Complexity  
A create() 0 19 6
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