OtpBuildTrait::isParameterPresent()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3.2098

Importance

Changes 0
Metric Value
cc 3
eloc 8
nc 3
nop 1
dl 0
loc 11
ccs 5
cts 7
cp 0.7143
crap 3.2098
rs 9.4285
c 0
b 0
f 0
1
<?php
2
namespace Sender\Traits;
3
4
use Sender\Validation;
5
use Sender\MobileNumber;
6
use Sender\Otp\OtpBuildClass;
7
use Sender\Otp\OtpDefineClass;
8
use Sender\ExceptionClass\ParameterException;
9
10
/**
11
 * This trait for OTP FUNCTIONS
12
 *
13
 * @package    Msg91 SMS&OTP package
14
 * @author     VenkatS <[email protected]>
15
 * @link       https://github.com/tesark/msg91-php
16
 * @license    MIT
17
 */
18
19
trait OtpBuildTrait
20
{
21
    /**
22
     * Check Authkey and mobile
23
     * @param string $parameter
24
     *
25
     * @throws ParameterException missing parameters or return empty
26
     * @return bool
27
     */
28 20
    public function isParameterPresent($parameter)
29
    {
30 20
        if ($this->isKeyExists($parameter, $this->sendData)) {
0 ignored issues
show
Bug Best Practice introduced by
The property sendData does not exist on Sender\Traits\OtpBuildTrait. Did you maybe forget to declare it?
Loading history...
Bug introduced by
It seems like isKeyExists() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

30
        if ($this->/** @scrutinizer ignore-call */ isKeyExists($parameter, $this->sendData)) {
Loading history...
31 20
            if ($parameter === 'authkey') {
32 20
                return $this->hasAuthKey($parameter);
0 ignored issues
show
Bug introduced by
It seems like hasAuthKey() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

32
                return $this->/** @scrutinizer ignore-call */ hasAuthKey($parameter);
Loading history...
33
            } else {
34 20
                return $this->hasMobile($parameter);
0 ignored issues
show
Bug introduced by
It seems like hasMobile() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

34
                return $this->/** @scrutinizer ignore-call */ hasMobile($parameter);
Loading history...
35
            }
36
        } else {
37
            $message = "Parameter ".$parameter." missing";
38
            throw ParameterException::missinglogic($message);
39
        }
40
    }
41
    /**
42
     * Check Authkey
43
     *
44
     * @return bool
45
     */
46 20
    public function checkAuthKey()
47
    {
48 20
        return $this->isParameterPresent('authkey');
49
    }
50
    /**
51
     * Check mobile
52
     *
53
     * @return bool
54
     */
55 20
    public function checkMobile()
56
    {
57 20
        return $this->isParameterPresent('mobile');
58
    }
59
}
60