Passed
Push — 2.x ( a2237c...c5863b )
by Terry
02:56
created

ItemImageCaptcha::get()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 22
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 14
nc 4
nop 1
dl 0
loc 22
rs 9.7998
c 1
b 0
f 0
1
<?php
2
/*
3
 * This file is part of the Shieldon package.
4
 *
5
 * (c) Terry L. <[email protected]>
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
declare(strict_types=1);
12
13
namespace Shieldon\Firewall\Firewall\Captcha;
14
15
use Shieldon\Firewall\Captcha\CaptchaInterface;
16
use Shieldon\Firewall\Captcha\ImageCaptcha;
17
18
/**
19
 * Get File driver.
20
 */
21
class ItemImageCaptcha
22
{
23
    /**
24
     * Initialize and get the instance.
25
     *
26
     * @param array $setting The configuration of that driver.
27
     *
28
     * @return CaptchaInterface
29
     */
30
    public static function get(array $setting): CaptchaInterface
31
    {
32
        $type = $setting['config']['type'] ?? 'alnum';
33
        $length = $setting['config']['length'] ?? 8;
34
35
        switch ($type) {
36
            case 'numeric':
37
                $imageCaptchaConfig['pool'] = '0123456789';
0 ignored issues
show
Comprehensibility Best Practice introduced by
$imageCaptchaConfig was never initialized. Although not strictly required by PHP, it is generally a good practice to add $imageCaptchaConfig = array(); before regardless.
Loading history...
38
                break;
39
40
            case 'alpha':
41
                $imageCaptchaConfig['pool'] = '0123456789abcdefghijklmnopqrstuvwxyz';
42
                break;
43
44
            case 'alnum':
45
            default:
46
                $imageCaptchaConfig['pool'] = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
47
        }
48
49
        $imageCaptchaConfig['word_length'] = $length;
50
51
        return new ImageCaptcha($imageCaptchaConfig);
52
    }
53
}