Currency   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 3
c 3
b 0
f 0
lcom 1
cbo 1
dl 0
loc 47
ccs 7
cts 7
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A get() 0 8 2
A getTypes() 0 4 1
1
<?php
2
3
/*
4
 * This file is part of the light/apistore.
5
 *
6
 * (c) lichunqiang <[email protected]>
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace light\apistore\apis;
13
14
/**
15
 * 汇率转换.
16
 *
17
 * @see http://apistore.baidu.com/apiworks/servicedetail/119.html
18
 */
19
class Currency extends Api
20
{
21
    /**
22
     * @var string 汇率转换地址
23
     */
24
    private $address = 'http://apis.baidu.com/apistore/currencyservice/currency?';
25
26
    /**
27
     * @var string 币种查询地址
28
     */
29
    private $fetchTypesUrl = 'http://apis.baidu.com/apistore/currencyservice/type?';
30
31
    /**
32
     * 获取汇率转换结果.
33
     *
34
     * @param array $queryParams
35
     *
36
     * ~~~
37
     * $queryParams = [
38
     *     'fromCurrency' => 'CNY', //待转化的币种
39
     *     'toCurrency' => 'USD',   //转化后的币种
40
     *     'amount' => 2            //转化金额
41
     * ];
42
     * ~~~
43
     *
44
     * 或者
45
     *
46
     * ~~~
47
     * $queryParams = ['CNY', 'USD', 2];
48
     * ~~~
49
     *
50
     * @return array
51
     */
52 3
    public function get($queryParams)
53
    {
54 3
        if (!isset($queryParams['fromCurrency'])) {
55 3
            $queryParams = array_combine(['fromCurrency', 'toCurrency', 'amount'], $queryParams);
56 3
        }
57
58 3
        return $this->fetch($this->address . http_build_query($queryParams));
59
    }
60
61 1
    public function getTypes()
62
    {
63 1
        return $this->fetch($this->fetchTypesUrl);
64
    }
65
}
66