Completed
Push — master ( 017947...8f5b55 )
by frey
13s
created

AccessToken   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 63
Duplicated Lines 28.57 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
dl 18
loc 63
rs 10
c 0
b 0
f 0
wmc 3
lcom 1
cbo 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setTicket() 0 6 1
A getTokenFromServer() 18 18 2

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
namespace EntWeChat\Suite;
4
5
use EntWeChat\Core\AccessToken as CoreAccessToken;
6
use EntWeChat\Core\Exceptions\HttpException;
7
8
class AccessToken extends CoreAccessToken
9
{
10
    /**
11
     * API.
12
     */
13
    const API_TOKEN_GET = 'https://qyapi.weixin.qq.com/cgi-bin/service/get_suite_token';
14
    /**
15
     * Ticket.
16
     *
17
     * @var \EntWeChat\Suite\Ticket
18
     */
19
    protected $ticket;
20
    /**
21
     * {@inheritdoc}.
22
     */
23
    protected $queryName = 'suite_access_token';
24
25
    /**
26
     * {@inheritdoc}.
27
     */
28
    protected $tokenJsonKey = 'suite_access_token';
29
30
    /**
31
     * {@inheritdoc}.
32
     */
33
    protected $prefix = 'EntWeChat.suite.suite_access_token.';
34
35
    /**
36
     * Set VerifyTicket.
37
     *
38
     * @param \EntWeChat\Suite\Ticket $ticket
39
     *
40
     * @return $this
41
     */
42
    public function setTicket(Ticket $ticket)
43
    {
44
        $this->ticket = $ticket;
45
46
        return $this;
47
    }
48
49
    /**
50
     * {@inheritdoc}.
51
     */
52 View Code Duplication
    public function getTokenFromServer()
0 ignored issues
show
Duplication introduced by
This method 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...
53
    {
54
        $data = [
55
            'suite_id'     => $this->id,
56
            'suite_secret' => $this->secret,
57
            'suite_ticket' => $this->ticket->getTicket(),
58
        ];
59
60
        $http = $this->getHttp();
61
62
        $token = $http->parseJSON($http->json(self::API_TOKEN_GET, $data));
63
64
        if (empty($token[$this->tokenJsonKey])) {
65
            throw new HttpException('Request SuiteAccessToken fail. response: '.json_encode($token, JSON_UNESCAPED_UNICODE));
66
        }
67
68
        return $token;
69
    }
70
}
71