EndpointsRepository   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 91.67%

Importance

Changes 0
Metric Value
dl 0
loc 53
ccs 11
cts 12
cp 0.9167
rs 10
c 0
b 0
f 0
wmc 5
lcom 0
cbo 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getEndpoint() 0 19 2
A getUrl() 0 8 2
A build() 0 4 1
1
<?php
2
3
namespace Samerior\MobileMoney\Mpesa\Repositories;
4
5
use Samerior\MobileMoney\Mpesa\Exceptions\MpesaException;
6
7
/**
8
 * Class EndpointsRepository
9
 *
10
 * @package Samerior\MobileMoney\Mpesa\Repositories
11
 */
12
class EndpointsRepository
13
{
14
15
    /**
16
     * @param string $section
17
     * @return string
18
     * @throws \Exception
19
     * @throws MpesaException
20
     */
21 2
    private static function getEndpoint($section): string
22
    {
23
        $list = [
24 2
            'auth' => 'oauth/v1/generate?grant_type=client_credentials',
25
            'id_check' => 'mpesa/checkidentity/v1/query',
26
            'register' => 'mpesa/c2b/v1/registerurl',
27
            'stk_push' => 'mpesa/stkpush/v1/processrequest',
28
            'stk_status' => 'mpesa/stkpushquery/v1/query',
29
            'b2c' => 'mpesa/b2c/v1/paymentrequest',
30
            'transaction_status' => 'mpesa/transactionstatus/v1/query',
31
            'account_balance' => 'mpesa/accountbalance/v1/query',
32
            'b2b' => 'mpesa/b2b/v1/paymentrequest',
33
            'simulate' => 'mpesa/c2b/v1/simulate',
34
        ];
35 2
        if ($item = $list[$section]) {
36 2
            return self::getUrl($item);
37
        }
38
        throw new MpesaException('Unknown endpoint');
39
    }
40
41
    /**
42
     * @param string $suffix
43
     * @return string
44
     */
45 2
    private static function getUrl($suffix): string
46
    {
47 2
        $baseEndpoint = 'https://api.safaricom.co.ke/';
48 2
        if (\config('samerior.mpesa.sandbox')) {
49 1
            $baseEndpoint = 'https://sandbox.safaricom.co.ke/';
50
        }
51 2
        return $baseEndpoint . $suffix;
52
    }
53
54
    /**
55
     * @param $endpoint
56
     * @return string
57
     * @throws \Exception
58
     * @throws MpesaException
59
     */
60 2
    public static function build($endpoint)
61
    {
62 2
        return self::getEndpoint($endpoint);
63
    }
64
}
65