Passed
Pull Request — master (#194)
by
unknown
14:54
created

CaptchaService::getCaptchaObject()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 4
Bugs 0 Features 0
Metric Value
eloc 4
dl 0
loc 11
rs 10
c 4
b 0
f 0
cc 2
nc 2
nop 0
1
<?php
2
3
namespace WebDevEtc\BlogEtc\Services;
4
5
use WebDevEtc\BlogEtc\Captcha\CaptchaAbstract;
6
use WebDevEtc\BlogEtc\Interfaces\CaptchaInterface;
7
8
/**
9
 * Class CaptchaService.
10
 */
11
class CaptchaService
12
{
13
    /**
14
     * Return either null (if captcha is not enabled), or the captcha object (which should implement
15
     * CaptchaInterface interface / extend the CaptchaAbstract class).
16
     *
17
     * @return CaptchaAbstract|null
18
     */
19
    public function getCaptchaObject(): ?CaptchaInterface
20
    {
21
        if (!config('blogetc.captcha.captcha_enabled')) {
22
            return null;
23
        }
24
25
        // else: captcha is enabled
26
        /** @var string $captchaClass */
27
        $captchaClass = config('blogetc.captcha.captcha_type');
28
29
        return new $captchaClass();
30
    }
31
}
32