AccessToken::setTicket()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace YEntWeChat\Suite;
4
5
use YEntWeChat\Core\AccessToken as CoreAccessToken;
6
use YEntWeChat\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 = 'YEntWeChat.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;
0 ignored issues
show
Documentation Bug introduced by
It seems like $ticket of type object<YEntWeChat\Suite\Ticket> is incompatible with the declared type object<EntWeChat\Suite\Ticket> of property $ticket.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
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