OtpVerifyAndResend   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Test Coverage

Coverage 58.62%

Importance

Changes 0
Metric Value
dl 0
loc 60
ccs 17
cts 29
cp 0.5862
rs 10
c 0
b 0
f 0
wmc 7

2 Methods

Rating   Name   Duplication   Size   Complexity  
B otpApiCategory() 0 24 4
A otpFinalVerifyAndResend() 0 16 3
1
<?php
2
namespace Sender\Otp;
3
4
use Sender\Deliver;
5
use Sender\Validation;
6
use Sender\MobileNumber;
7
use Sender\Otp\OtpDefineClass;
8
use Sender\Otp\OtpBuildClass;
9
use Sender\Config\Config as ConfigClass;
10
use Sender\ExceptionClass\ParameterException;
11
12
/**
13
 * This Class for verify OTP
14
 *
15
 * @package    Sender\OtpVerify
16
 * @author     VenkatS <[email protected]>
17
 * @link       https://github.com/tesark/msg91-php
18
 * @license    MIT
19
 */
20
21
class OtpVerifyAndResend extends OtpBuildClass
22
{
23
    /**
24
     * This function used for verify and resend OTP content
25
     * @param int $mobileNumber
26
     * @param int|string $value
27
     * @param string $otpAuthKey
28
     * @param int $apiCategory
29
     *
30
     * @return string
31
     */
32 5
    public function otpApiCategory($mobileNumber, $value, $AuthKey, $apiCategory)
33
    {
34 5
        $data = [];
35 5
        $otpAuthKey = null;
36 5
        $checkAuth = Validation::isAuthKey($AuthKey);
37 5
        if (!$checkAuth) {
38
            // Get Envirionment variable and config file values
39
            $config = new ConfigClass();
40
            $container = $config->getDefaults();
41
            $common = $container['common'];
42
            $otpAuthKey = $common['otpAuthKey'];
43
        }
44 5
        $data['authkey'] = $checkAuth ? $AuthKey : $otpAuthKey;
45 5
        $data['mobile'] = $mobileNumber;
46 5
        if ($apiCategory === 1) {
47
            $data['otp'] = $value;
48
            $uri = "verifyRequestOTP.php";
49
            $response = $this->otpFinalVerifyAndResend($data, $uri);
50
        } else {
51 5
            $data['retrytype'] = $value;
52 5
            $uri = 'retryotp.php';
53 5
            $response = $this->otpFinalVerifyAndResend($data, $uri);
54
        }
55
        return $response;
56
    }
57
    /**
58
     * This function for retry and verify OTP
59
     * @param int    $category
60
     * @param array  $data
61
     *
62
     * @throws ParameterException missing parameters or return empty
63
     * @return string Msg91 Json response
64
     */
65 5
    protected function otpFinalVerifyAndResend($data, $uri)
66
    {
67 5
        $this->sendData = $data;
68 5
        if ($this->checkAuthKey() && $this->checkMobile()) {
69 5
            $data = $this->sendData;
70 4
            //add retry type on array
71
            $data = $this->addRetryType($data);
72 4
            //add otp on array
73
            $data = $this->addOneTimePass($data);
74
        } else {
75
            $message = "The parameters Authkey or Mobile missing";
76
            throw ParameterException::missinglogic($message);
77
        }
78
        $delivery = new Deliver();
79
        $response = $delivery->sendOtpGet($uri, $data);
80
        return $response;
81
    }
82
}
83