Validation   A
last analyzed

Complexity

Total Complexity 34

Size/Duplication

Total Lines 191
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 34
eloc 63
c 1
b 0
f 0
dl 0
loc 191
rs 9.68

6 Methods

Rating   Name   Duplication   Size   Complexity  
C validateAppruve() 0 51 14
A validateSmile() 0 8 2
A verifyAppruve() 0 17 4
A validateCredequity() 0 6 2
A verifySmile() 0 7 2
B verifyCredequity() 0 37 10
1
<?php
2
3
namespace Bytesfield\SimpleKyc\Classes;
4
5
use Bytesfield\SimpleKyc\Classes\IdFilter;
6
use Bytesfield\SimpleKyc\Exceptions\NotValidException;
7
use Bytesfield\SimpleKyc\Exceptions\DataMismatchException;
8
use Bytesfield\SimpleKyc\Exceptions\NotFoundException;
9
10
class Validation
11
{
12
    /**
13
     * Validate Appruve information
14
     *
15
     * @param array $response
16
     * @param \Bytesfield\SimpleKyc\Classes\IdFilter
17
     * 
18
     * @return array
19
     */
20
    public function validateAppruve(array $response, IdFilter $IdFilter): array
21
    {
22
        $idType = $IdFilter->getIDType();
23
24
        if ($IdFilter->getCountry() == IdFilter::COUNTRIES['GHANA']) {
25
26
            if ($idType == IdFilter::IDVALUES['TYPE_VOTER_CARD']) {
27
                return $response;
28
            } //Exclude Appruve Field Verification for this
29
30
            if ($idType == IdFilter::IDVALUES['TYPE_TIN']) {
31
                if (!$response['data']['is_valid']) {
32
                    throw new NotValidException('Tin is not valid');
33
                }
34
35
                return $response;
36
            } //Exclude Appruve Field Verification for this
37
38
            if ($idType == IdFilter::IDVALUES['TYPE_DRIVERS_LICENSE']) {
39
                if (!$response['data']['is_full_name_match']) {
40
                    throw new DataMismatchException('Fullname does not match');
41
                }
42
43
                if (!$response['data']['is_date_of_birth_match']) {
44
                    throw new DataMismatchException('Date of birth does not match');
45
                }
46
                return $response;
47
            } //Exclude Appruve Field Verification for this
48
49
            if ($idType == IdFilter::IDVALUES['TYPE_SSNIT']) {
50
                if (!$response['data']['is_full_name_match']) {
51
                    throw new DataMismatchException('Fullname does not match');
52
                }
53
54
                return $response;
55
            } //Exclude Appruve Field Verification for this
56
57
        }
58
59
        if (
60
            $idType == IdFilter::IDVALUES['TYPE_TIN']
61
            || $idType == IdFilter::IDVALUES['TYPE_KRA']
62
            || $idType == IdFilter::IDVALUES['TELCO_SUBSCRIBER']
63
        ) {
64
            return $response;
65
        } //Exclude Appruve Field Verification for this
66
67
        $isVerified = $this->verifyAppruve($response);
68
69
        if ($isVerified == true) {
0 ignored issues
show
introduced by
The condition $isVerified == true is always true.
Loading history...
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
70
            return $response;
71
        }
0 ignored issues
show
Bug Best Practice introduced by
The function implicitly returns null when the if condition on line 69 is false. This is incompatible with the type-hinted return array. Consider adding a return statement or allowing null as return value.

For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example:

interface ReturnsInt {
    public function returnsIntHinted(): int;
}

class MyClass implements ReturnsInt {
    public function returnsIntHinted(): int
    {
        if (foo()) {
            return 123;
        }
        // here: null is implicitly returned
    }
}
Loading history...
72
    }
73
74
    /**
75
     * Verify Appruve information
76
     *
77
     * @param array result
0 ignored issues
show
Bug introduced by
The type Bytesfield\SimpleKyc\Classes\result was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
78
     * 
79
     * @throws \Bytesfield\SimpleKyc\Exceptions\DataMismatchException
80
     * 
81
     * @return bool
82
     */
83
    private function verifyAppruve($result): bool
84
    {
85
        $data = $result['data'];
86
87
        if (!$data['is_first_name_match']) {
88
            throw new DataMismatchException('Firstname does not match');
89
        }
90
91
        if (!$data['is_last_name_match']) {
92
            throw new DataMismatchException('Lastname does not match');
93
        }
94
95
        if (!$data['is_date_of_birth_match']) {
96
            throw new DataMismatchException('Date of birth does not match');
97
        }
98
99
        return true;
100
    }
101
102
    /**
103
     * Validate Credequity information
104
     *
105
     * @param array $response
106
     * @param \Bytesfield\SimpleKyc\Classes\IdFilter
107
     * 
108
     * @return array
109
     */
110
    public function validateCredequity($response, IdFilter $IdFilter): array
111
    {
112
        $isVerified = $this->verifyCredequity($response, $IdFilter);
113
114
        if ($isVerified == true) {
0 ignored issues
show
introduced by
The condition $isVerified == true is always true.
Loading history...
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
115
            return $response;
116
        }
0 ignored issues
show
Bug Best Practice introduced by
The function implicitly returns null when the if condition on line 114 is false. This is incompatible with the type-hinted return array. Consider adding a return statement or allowing null as return value.

For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example:

interface ReturnsInt {
    public function returnsIntHinted(): int;
}

class MyClass implements ReturnsInt {
    public function returnsIntHinted(): int
    {
        if (foo()) {
            return 123;
        }
        // here: null is implicitly returned
    }
}
Loading history...
117
    }
118
119
    /**
120
     * Verify Credequity information
121
     *
122
     * @param array result
123
     * @param Bytesfield\SimpleKyc\Classes\IdFilter
124
     * 
125
     * @throws \Bytesfield\SimpleKyc\Exceptions\DataMismatchException
126
     * 
127
     * @return bool
128
     */
129
    private function verifyCredequity($result, $IdFilter): bool
130
    {
131
        $data = $result['data'];
132
        $idType = $IdFilter->getIDType();
133
134
        if ($idType == IdFilter::IDVALUES['TYPE_BVN']) {
135
136
            if (strtoupper($data['firstName']) !== strtoupper($IdFilter->getFirstName())) {
137
                throw new DataMismatchException('Firstname does not match');
138
            }
139
140
            if (strtoupper($data['lastName']) !== strtoupper($IdFilter->getLastName())) {
141
                throw new DataMismatchException('Lastname does not match');
142
            }
143
144
            if ($data['dateOfBirth'] !== $IdFilter->getDOB()) {
145
                throw new DataMismatchException('Date of birth does not match');
146
            }
147
        }
148
149
        if ($idType == IdFilter::IDVALUES['TYPE_DRIVERS_LICENSE']) {
150
            if ($data['Birthdate'] !== $IdFilter->getDOB()) {
151
                throw new DataMismatchException('Date of birth does not match');
152
            }
153
        }
154
155
        if ($idType == IdFilter::IDVALUES['TYPE_NIN']) {
156
            if (strtoupper($data['firstname']) !== strtoupper($IdFilter->getFirstName())) {
157
                throw new DataMismatchException('Firstname does not match');
158
            }
159
160
            if ($data['birthdate'] !== $IdFilter->getDOB()) {
161
                throw new DataMismatchException('Date of birth does not match');
162
            }
163
        }
164
165
        return true;
166
    }
167
168
    /**
169
     * Validate Smile response
170
     *
171
     * @param array $response
172
     * 
173
     * @throws \Bytesfield\SimpleKyc\Exceptions\NotFoundException
174
     * 
175
     * @return array
176
     */
177
    public function validateSmile(array $response): array
178
    {
179
        $isVerified = $this->verifySmile($response);
180
181
        if ($isVerified === false) {
182
            throw new NotFoundException("{$response['data']['ResultText']}");
183
        }
184
        return $response;
185
    }
186
187
    /**
188
     * Verify Smile response
189
     *
190
     * @param array $response
191
     * 
192
     * @return bool
193
     */
194
    private function verifySmile($response): bool
195
    {
196
        if (($response['data']['Actions']['Verify_ID_Number'] !== 'Verified')) {
197
            return false;
198
        }
199
200
        return true;
201
    }
202
}
203