Otp::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
namespace Sender;
3
4
use Sender\Deliver;
5
use Sender\Validation;
6
use Sender\Otp\OtpSend;
7
use Sender\Otp\OtpVerifyAndResend;
8
use Sender\Config\Config as ConfigClass;
9
use Sender\ExceptionClass\ParameterException;
10
11
/**
12
 * This Class provide OTP APIs
13
 *
14
 * @package    Sender\Otp
15
 * @author     VenkatS <[email protected]>
16
 * @link       https://github.com/tesark/msg91-php
17
 * @license    MIT
18
 */
19
20
class Otp
21
{
22
    /**
23
     * @var null|string $otpAuth
24
     */
25
    protected $otpAuth;
26
    /**
27
     * @var null|int $otp
28
     */
29
    public $otp;
30 20
    public function __construct($authkey = null)
31
    {
32 20
        $this->otpAuth = $authkey;
33 20
    }
34
    /**
35
     * This function for get Authkey from config file
36
     *
37
     */
38
    public function getAuthkey($otpAuthKey)
39
    {
40
        if (!$otpAuthKey) {
41
            // Get Envirionment variable and config file values
42 15
            $config      = new ConfigClass();
43
            $container   = $config->getDefaults();
44 15
            $common      = $container['common'];
45 15
            $otpAuthKey  = $common['otpAuthKey'];
46 15
        }
47 15
        return $otpAuthKey;
48
    }
49
    /**
50
     * @param int|string $mobileNumber
51
     * @param array $dataArray
52
     *
53
     * @return string
54 15
     */
55 15
    public function sendOtp($mobileNumber, $dataArray)
56 15
    {
57 15
        $data = [];
58
        $checkAuth = Validation::isAuthKey($this->otpAuth);
59
        $otpAuthKey = $this->getAuthkey($checkAuth);
60
        $data['authkey'] = $checkAuth ? $this->otpAuth : $otpAuthKey;
61
        $data['mobile']  = $mobileNumber;
62
        $otp             = new OtpSend();
63
        $response        = $otp->sendOtp($dataArray, $data);
64
        return $response;
65
    }
66
    /**
67
     * @param int $mobileNumber
68
     * @param int|string $oneTimePass
69
     *
70
     * @return string
71
     */
72
    public function verifyOtp($mobileNumber, $oneTimePass)
73
    {
74
        $checkAuth = Validation::isAuthKey($this->otpAuth);
75
        $otpAuthKey = $this->getAuthkey($checkAuth);
76
        $verifyAuth = $checkAuth ? $this->otpAuth : $otpAuthKey;
77
        $otp = new OtpVerifyAndResend();
78
        $verifyOtpResponse = $otp->otpApiCategory($mobileNumber, $oneTimePass, $verifyAuth, 1);
79
        return $verifyOtpResponse;
80
    }
81
    /**
82
     * @param int $mobileNumber
83 5
     * @param string $retrytype
84
     *
85 5
     * @return string
86 5
     */
87 5
    public function resendOtp($mobileNumber, $retrytype = null)
88
    {
89
        $checkAuth = Validation::isAuthKey($this->otpAuth);
90
        $otpAuthKey = $this->getAuthkey($checkAuth);
91
        $resendAuth = $checkAuth ? $this->otpAuth : $otpAuthKey;
92
        $otp        = new OtpVerifyAndResend();
93
        $resendOtpResponse = $otp->otpApiCategory($mobileNumber, $retrytype, $resendAuth, 0);
94
        return $resendOtpResponse;
95
    }
96
}
97