Completed
Pull Request — master (#445)
by Carlos
06:52 queued 02:55
created

Session   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 78
Duplicated Lines 23.08 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 1 Features 0
Metric Value
c 3
b 1
f 0
dl 18
loc 78
ccs 16
cts 16
cp 1
rs 10
wmc 5
lcom 1
cbo 1

5 Methods

Rating   Name   Duplication   Size   Complexity  
A lists() 0 4 1
A waiters() 0 4 1
A create() 9 9 1
A close() 9 9 1
A get() 0 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
/*
4
 * This file is part of the overtrue/wechat.
5
 *
6
 * (c) overtrue <[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
/**
13
 * Session.php.
14
 *
15
 * @author    overtrue <[email protected]>
16
 * @copyright 2015 overtrue <[email protected]>
17
 *
18
 * @link      https://github.com/overtrue
19
 * @link      http://overtrue.me
20
 */
21
namespace EasyWeChat\Staff;
22
23
use EasyWeChat\Core\AbstractAPI;
24
25
/**
26
 * Class Session.
27
 */
28
class Session extends AbstractAPI
29
{
30
    const API_CREATE = 'https://api.weixin.qq.com/customservice/kfsession/create';
31
    const API_CLOSE = 'https://api.weixin.qq.com/customservice/kfsession/close';
32
    const API_GET = 'https://api.weixin.qq.com/customservice/kfsession/getsession';
33
    const API_LISTS = 'https://api.weixin.qq.com/customservice/kfsession/getsessionlist';
34
    const API_WAITERS = 'https://api.weixin.qq.com/customservice/kfsession/getwaitcase';
35
36
    /**
37
     * List all sessions of $account.
38
     *
39
     * @param string $account
40
     *
41
     * @return array
42
     */
43 1
    public function lists($account)
44
    {
45 1
        return $this->parseJSON('get', [self::API_LISTS, ['kf_account' => $account]]);
46
    }
47
48
    /**
49
     * List all waiters of $account.
50
     *
51
     * @return array
52
     */
53 1
    public function waiters()
54
    {
55 1
        return $this->parseJSON('get', [self::API_WAITERS]);
56
    }
57
58
    /**
59
     * Create a session.
60
     *
61
     * @param string $account
62
     * @param string $openid
0 ignored issues
show
Documentation introduced by
There is no parameter named $openid. Did you maybe mean $openId?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.

Consider the following example. The parameter $ireland is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $ireland
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was changed, but the annotation was not.

Loading history...
63
     *
64
     * @return bool
65
     */
66 1 View Code Duplication
    public function create($account, $openId)
67
    {
68
        $params = [
69 1
                   'kf_account' => $account,
70 1
                   'openid' => $openId,
71 1
                  ];
72
73 1
        return $this->parseJSON('json', [self::API_CREATE, $params]);
74
    }
75
76
    /**
77
     * Close a session.
78
     *
79
     * @param string $account
80
     * @param string $openId
81
     *
82
     * @return bool
83
     */
84 1 View Code Duplication
    public function close($account, $openId)
85
    {
86
        $params = [
87 1
                   'kf_account' => $account,
88 1
                   'openid' => $openId,
89 1
                  ];
90
91 1
        return $this->parseJSON('json', [self::API_CLOSE, $params]);
92
    }
93
94
    /**
95
     * Get a session.
96
     *
97
     * @param string $openId
98
     *
99
     * @return bool
100
     */
101 1
    public function get($openId)
102
    {
103 1
        return $this->parseJSON('get', [self::API_GET, ['openid' => $openId]]);
104
    }
105
}
106