OtpSend::sendOtp()   C
last analyzed

Complexity

Conditions 11
Paths 6

Size

Total Lines 32
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 16
CRAP Score 13.4538

Importance

Changes 0
Metric Value
cc 11
eloc 22
nc 6
nop 2
dl 0
loc 32
ccs 16
cts 22
cp 0.7272
crap 13.4538
rs 5.2653
c 0
b 0
f 0

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
namespace Sender\Otp;
3
4
use Sender\Deliver;
5
use Sender\Validation;
6
use Sender\MobileNumber;
7
use Sender\Config\Config as ConfigClass;
8
use Sender\ExceptionClass\ParameterException;
9
10
/**
11
 * This Class for send OTP
12
 *
13
 * @package    Sender\OtpSend
14
 * @author     VenkatS <[email protected]>
15
 * @link       https://github.com/tesark/msg91-php
16
 * @license    MIT
17
 */
18
19
class OtpSend extends OtpBuildClass
20
{
21
    /**
22
     * This function for send OTP
23
     *
24
     * @param array $dataArray
25
     * @param array $data
26
     *
27
     * @throws ParameterException missing parameters or return empty
28
     * @return string Msg91 Json response
29
     */
30 15
    public function sendOtp($dataArray, $data)
31
    {
32 15
        $this->inputData    = $dataArray;
33 15
        $this->sendData     = $data;
34 15
        if ($this->hasInputData() && $this->hasSendData()) {
35 15
            if ($this->checkAuthKey() && $this->checkMobile()) {
36 15
                $data = $this->sendData;
37
                //add sender on the Array
38 15
                $data = $this->addSender($this->inputData, $data);
39
                //add otp_expiry on the array
40 12
                $data = $this->addOtpExpiry($this->inputData, $data);
41
                //add otp_length on the array
42 9
                $data = $this->addOtpLength($this->inputData, $data);
43 5
                $checkOtp = $this->isKeyExists('otp', $this->inputData);
44 5
                $checkMsg = $this->isKeyExists('message', $this->inputData);
45 5
                if ($checkOtp && $checkMsg) {
46
                    //add message on array
47 3
                    $data = $this->addMessage($this->inputData, $data);
48
                    //add otp on the array
49 2
                    $data = $this->addOtp($this->inputData, $data);
50
                }
51 2
                if (($checkOtp && !$checkMsg) || (!$checkOtp && $checkMsg)) {
52 2
                    throw ParameterException::missinglogic("When using otp or message, unable to use seperately");
53
                }
54
            }
55
            $uri = "sendotp.php";
56
            $delivery = new Deliver();
57
            $response = $delivery->sendOtpGet($uri, $data);
58
            return $response;
59
        } else {
60
            $message = "Parameters not found";
61
            throw ParameterException::missinglogic($message);
62
        }
63
    }
64
}
65