MtnRemittance::requestUrl()   B
last analyzed

Complexity

Conditions 6
Paths 6

Size

Total Lines 31

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 31
c 0
b 0
f 0
rs 8.8017
cc 6
nc 6
nop 2
1
<?php
2
3
namespace PatricPoba\MtnMomo;
4
5
use PatricPoba\MtnMomo\Exceptions\MtnMomoException;
6
7
class MtnRemittance extends MtnMomo 
8
{
9
    const PRODUCT = 'remittance';
10
11
12
    protected function requestUrl(string $endpointName, array $params = []) : string
13
    { 
14
        switch ($endpointName) {
15
            case 'token':  
16
                $urlSegment = '/remittance/token/' ;
17
                break;
18
19
            case 'postTransaction': 
20
                $urlSegment = '/remittance/v1_0/transfer';
21
                break;
22
                 
23
            case 'getTransaction': 
24
                $urlSegment = "/remittance/v1_0/transfer/{$params['referenceId']}";
25
                break;
26
 
27
            case 'balance': 
28
                $urlSegment = '/remittance/v1_0/account/balance';
29
                break;
30
 
31
            case 'accountholder':
32
                $accountHolderIdType = $params['accountHolderIdType'] ?? 'MSISDN';
33
                $urlSegment = "/remittance/v1_0/accountholder/{$accountHolderIdType}/{$params['accountHolderId']}/active";
34
                break;
35
            
36
            default:
37
                throw new MtnMomoException("Unknown api endpoint - {$endpointName}.");
38
                break;
0 ignored issues
show
Unused Code introduced by
break; does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
39
        }
40
 
41
        return $this->config->baseUrl . $urlSegment;
0 ignored issues
show
Bug introduced by
The property config does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
42
    }
43
44
    public function transfer(array $params, string $transactionUuid = null)
45
    {
46
        return parent::createTransaction($params, $transactionUuid);
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (createTransaction() instead of transfer()). Are you sure this is correct? If so, you might want to change this to $this->createTransaction().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
47
    }
48
}
49