Translate::get()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 12
Code Lines 7

Duplication

Lines 12
Ratio 100 %

Code Coverage

Tests 8
CRAP Score 3

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 12
loc 12
ccs 8
cts 8
cp 1
rs 9.4286
cc 3
eloc 7
nc 3
nop 1
crap 3
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/118.html
18
 */
19 View Code Duplication
class Translate extends Api
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...
20
{
21
    private $address_translate = 'http://apis.baidu.com/apistore/tranlateservice/translate?';
22
23
    /**
24
     * 目前词典接口只支持zh和en两种语言
25
     *
26
     * @param string|array $queryParams
27
     *
28
     * @return array
29
     */
30 2
    public function get($queryParams)
31
    {
32 2
        $_using_address = $this->address_translate;
33
34 2
        if (is_string($queryParams)) {
35 1
            $queryParams = ['query' => $queryParams, 'from' => 'auto', 'to' => 'auto'];
36 2
        } elseif (!isset($queryParams['query'])) {
37 1
            $queryParams = array_combine(['query', 'from', 'to'], $queryParams);
38 1
        }
39
40 2
        return $this->fetch($_using_address . http_build_query($queryParams));
41
    }
42
}
43