Completed
Push — master ( 883139...5ac6b4 )
by Vuong
01:54
created

BankProvider   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 86
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 3
dl 0
loc 86
ccs 0
cts 20
cp 0
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A banks() 0 24 5
1
<?php
2
/**
3
 * @link https://github.com/yiiviet/yii2-payment
4
 * @copyright Copyright (c) 2017 Yii Viet
5
 * @license [New BSD License](http://www.opensource.org/licenses/bsd-license.php)
6
 */
7
8
9
namespace yiiviet\payment\baokim;
10
11
use Yii;
12
13
use yii\base\InvalidCallException;
14
15
use yiiviet\payment\BankProvider as BaseBankProvider;
16
17
/**
18
 * Lớp BankProvider
19
 *
20
 * @author Vuong Minh <[email protected]>
21
 * @since 1.0.3
22
 */
23
class BankProvider extends BaseBankProvider
24
{
25
    /**
26
     * Thẻ nội địa.
27
     */
28
    const TYPE_LOCAL_CARD = 1;
29
30
    /**
31
     * Thẻ tín dụng quốc tế.
32
     */
33
    const TYPE_CREDIT_CARD = 2;
34
35
    /**
36
     * Chuyển khoản online của các ngân hàng.
37
     */
38
    const TYPE_INTERNET_BANKING = 3;
39
40
    /**
41
     * Chuyển khoản ATM.
42
     */
43
    const TYPE_ATM_TRANSFER = 4;
44
45
    /**
46
     * Chuyển khoản truyền thống giữa các ngân hàng.
47
     */
48
    const TYPE_BANK_TRANSFER = 5;
49
50
    /**
51
     * @var int loại ngân hàng muốn lấy, ví dụ atm online, offline, giao dịch tại quầy...
52
     */
53
    public $type = self::TYPE_LOCAL_CARD;
54
55
    /**
56
     * @var mixed mã client dùng để truy xuất thông tin, nếu không chỉ định hệ thống sẽ tự động lấy theo client.
57
     */
58
    public $emailBusiness;
59
60
    /**
61
     * @var mixed mã client dùng để truy xuất thông tin, nếu không chỉ định hệ thống sẽ tự động lấy.
62
     */
63
    public $clientId;
64
65
    /**
66
     * @var PaymentGateway
67
     * @inheritdoc
68
     */
69
    protected $gateway;
70
71
    /**
72
     * @var null|array danh sách ngân hàng
73
     * @see [[banks()]]
74
     */
75
    private $_banks;
76
77
    /**
78
     * @return array
79
     * @throws \ReflectionException
80
     * @throws \yii\base\InvalidConfigException
81
     */
82
    public function banks(): array
83
    {
84
        if ($this->_banks === null) {
85
            $merchantData = $this->gateway->getMerchantData($this->emailBusiness, $this->clientId);
86
87
            if ($merchantData->isOk) {
0 ignored issues
show
Bug introduced by
Accessing isOk on the interface GatewayClients\DataInterface suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
88
                $banks = [];
89
90
                foreach ($merchantData['bank_payment_methods'] as $bank) {
91
                    if ($bank['payment_method_type'] == $this->type) {
92
                        $banks[$bank['id']] = $bank['name'];
93
                    }
94
                }
95
96
                natsort($banks);
97
98
                return $this->_banks = $banks;
99
            } else {
100
                throw new InvalidCallException('Can not get bank list!');
101
            }
102
        } else {
103
            return $this->_banks;
104
        }
105
    }
106
107
108
}
109