Issues (60)

src/services/IdVerification.php (22 issues)

1
<?php
2
3
namespace Bytesfield\SimpleKyc\Services;
4
5
use Noodlehaus\Config;
6
use Mpociot\Pipeline\Pipeline;
7
use Bytesfield\SimpleKyc\Pipes\Smile;
8
use Bytesfield\SimpleKyc\Pipes\Appruve;
9
use Bytesfield\SimpleKyc\Classes\IdFilter;
10
use Bytesfield\SimpleKyc\Classes\Validation;
11
use Bytesfield\SimpleKyc\Pipes\Credequity;
12
13
class IdVerification
14
{
15
16
    public function __construct($data)
17
    {
18
        $this->country = filterCountry($data->country);
0 ignored issues
show
Bug Best Practice introduced by
The property country does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
19
        $this->id_type = strtoupper($data->id_type) ?? null;
0 ignored issues
show
Bug Best Practice introduced by
The property id_type does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
20
        $this->id_number = $data->id ?? null;
0 ignored issues
show
Bug Best Practice introduced by
The property id_number does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
21
        $this->first_name = $data->first_name ?? null;
0 ignored issues
show
Bug Best Practice introduced by
The property first_name does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
22
        $this->last_name = $data->last_name ?? null;
0 ignored issues
show
Bug Best Practice introduced by
The property last_name does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
23
        $this->middle_name = $data->middle_name ?? null;
0 ignored issues
show
Bug Best Practice introduced by
The property middle_name does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
24
        $this->date_of_birth = $data->date_of_birth ?? null;
0 ignored issues
show
Bug Best Practice introduced by
The property date_of_birth does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
25
        $this->phone = $data->phone_number ?? null;
0 ignored issues
show
Bug Best Practice introduced by
The property phone does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
26
        $this->pin = $data->pin ?? null;
0 ignored issues
show
Bug Best Practice introduced by
The property pin does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
27
        $this->tin = $data->tin ?? null;
0 ignored issues
show
Bug Best Practice introduced by
The property tin does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
28
        $this->gender = $data->gender ?? null;
0 ignored issues
show
Bug Best Practice introduced by
The property gender does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
29
        $this->full_name = $this->first_name . ' ' . $this->last_name;
0 ignored issues
show
Bug Best Practice introduced by
The property full_name does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
30
        $this->user_id = $data->user_id ?? null;
0 ignored issues
show
Bug Best Practice introduced by
The property user_id does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
31
        $this->company = $data->company ?? null;
0 ignored issues
show
Bug Best Practice introduced by
The property company does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
32
        $this->registration_number = $data->registration_number ?? null;
0 ignored issues
show
Bug Best Practice introduced by
The property registration_number does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
33
34
        $this->config = new Config(__DIR__ . '/../config');
0 ignored issues
show
Bug Best Practice introduced by
The property config does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
35
36
        $this->appruveHandler = $this->config->get('appruve.handler');
0 ignored issues
show
Bug Best Practice introduced by
The property appruveHandler does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
37
        $this->smileHandler = $this->config->get('smile.handler');
0 ignored issues
show
Bug Best Practice introduced by
The property smileHandler does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
38
        $this->credequityHandler = $this->config->get('credequity.handler');
0 ignored issues
show
Bug Best Practice introduced by
The property credequityHandler does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
39
    }
40
41
    public function verify()
42
    {
43
        $IdFilter = new IdFilter(
44
            $this->country,
45
            $this->id_type,
46
            $this->id_number,
47
            $this->first_name,
48
            $this->last_name,
49
            $this->middle_name,
50
            $this->date_of_birth,
51
            $this->phone,
52
            $this->pin,
53
            $this->tin,
54
            $this->gender,
55
            $this->full_name,
56
            $this->user_id,
57
            $this->company,
58
            $this->registration_number
59
60
        );
61
62
        $response = null;
0 ignored issues
show
The assignment to $response is dead and can be removed.
Loading history...
63
        $pipes = [Smile::class, Appruve::class, Credequity::class,];
64
65
        $response = (new Pipeline)->send($IdFilter)
66
            ->through($pipes)
67
            ->then(function ($result) {
68
                return $result;
69
            });
70
71
        $executedHandler = strtoupper($IdFilter->getHandler());
72
73
        $validation = new Validation();
74
75
        //Validate Appruve Handler result
76
        if ($executedHandler == strtoupper($this->appruveHandler)) {
0 ignored issues
show
It seems like $this->appruveHandler can also be of type null; however, parameter $string of strtoupper() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

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

76
        if ($executedHandler == strtoupper(/** @scrutinizer ignore-type */ $this->appruveHandler)) {
Loading history...
77
78
            return $validation->validateAppruve($response, $IdFilter);
79
        }
80
81
        //Validate Smile Handler result
82
        if ($executedHandler == strtoupper($this->smileHandler)) {
83
            return $validation->validateSmile($response, $IdFilter);
0 ignored issues
show
The call to Bytesfield\SimpleKyc\Cla...dation::validateSmile() has too many arguments starting with $IdFilter. ( Ignorable by Annotation )

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

83
            return $validation->/** @scrutinizer ignore-call */ validateSmile($response, $IdFilter);

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
84
        }
85
86
        //Validate Credequity Handler result
87
        if ($executedHandler == strtoupper($this->credequityHandler)) {
88
            return $validation->validateCredequity($response, $IdFilter);
89
        }
90
91
        return $response;
92
    }
93
}
94