MtnCollection::requestToPay()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 4
Ratio 100 %

Importance

Changes 0
Metric Value
dl 4
loc 4
c 0
b 0
f 0
rs 10
cc 1
nc 1
nop 2
1
<?php
2
3
namespace PatricPoba\MtnMomo;
4
5
use PatricPoba\MtnMomo\Exceptions\MtnMomoException;
6
7 View Code Duplication
class MtnCollection extends MtnMomo 
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
8
{
9
    const PRODUCT = 'collection';
10
 
11
12
    protected function requestUrl(string $endpointName, array $params = []) : string
13
    { 
14
        switch ($endpointName) {
15
            case 'token':  
16
                $urlSegment = '/collection/token/' ; // trailing slash mandatory
17
                break;
18
19
            case 'createTransaction': 
20
                $urlSegment = '/collection/v1_0/requesttopay';
21
                break;
22
                 
23
            case 'getTransaction': 
24
                $urlSegment = "/collection/v1_0/requesttopay/{$params['referenceId']}";
25
                break;
26
 
27
            case 'balance': 
28
                $urlSegment = '/collection/v1_0/account/balance';
29
                break;
30
 
31
            case 'accountholderActive': 
32
                $urlSegment = "/collection/v1_0/accountholder/MSISDN/{$params['accountHolderId']}/active";
33
                break;
34
            
35
            default:
36
                throw new MtnMomoException("Unknown Api endpoint - {$endpointName}.");
37
                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...
38
        }
39
 
40
        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...
41
    }
42
 
43
   
44
    public function requestToPay(array $data, string $transactionUuid = null)
45
    {
46
        return parent::createTransaction($data, $transactionUuid);
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (createTransaction() instead of requestToPay()). 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
}
50