Completed
Push — master ( 8f5b55...c52b56 )
by frey
04:17 queued 01:50
created

Web   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 84
Duplicated Lines 14.29 %

Coupling/Cohesion

Components 2
Dependencies 3

Importance

Changes 0
Metric Value
dl 12
loc 84
rs 10
c 0
b 0
f 0
wmc 7
lcom 2
cbo 3

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getSSOUrl() 0 4 1
A getLoginUrl() 0 10 1
A user() 12 12 3
A getAuthUrl() 0 12 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\Auth;
4
5
use EntWeChat\Core\Exceptions\InvalidStateException;
6
7
/**
8
 * Class Web.
9
 */
10
class Web extends AbstractAuthentication
11
{
12
    const AUTH_URL = 'https://qy.weixin.qq.com/cgi-bin/loginpage';
13
14
    const API_GET_LOGIN_INFO = 'https://qyapi.weixin.qq.com/cgi-bin/service/get_login_info';
15
    const API_GET_LOGIN_URL = 'https://qyapi.weixin.qq.com/cgi-bin/service/get_login_url';
16
17
    /**
18
     * Indicates if the session state should be utilized.
19
     *
20
     * @var bool
21
     */
22
    protected $stateless = true;
23
24
    /**
25
     * Get the SSO URL.
26
     *
27
     * @param string   $loginTicket
28
     * @param string   $target
29
     * @param int|null $agentId
30
     *
31
     * @return \EntWeChat\Support\Collection
32
     */
33
    public function getSSOUrl($loginTicket, $target, $agentId = null)
34
    {
35
        return $this->getLoginUrl($loginTicket, $target, $agentId);
36
    }
37
38
    /**
39
     * Get the Login URL.
40
     *
41
     * @param string   $loginTicket
42
     * @param string   $target
43
     * @param int|null $agentId
44
     *
45
     * @return \EntWeChat\Support\Collection
46
     */
47
    public function getLoginUrl($loginTicket, $target, $agentId = null)
48
    {
49
        $params = [
50
            'login_ticket' => $loginTicket,
51
            'target'       => $target,
52
            'agentid'      => $agentId,
53
        ];
54
55
        return $this->parseJSON('json', [self::API_GET_LOGIN_URL, $params]);
56
    }
57
58
    /**
59
     * @param string|null $authCode
60
     *
61
     * @throws InvalidStateException
62
     *
63
     * @return \EntWeChat\Support\Collection
64
     */
65 View Code Duplication
    public function user($authCode = null)
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...
66
    {
67
        if ($this->hasInvalidState()) {
68
            throw new InvalidStateException();
69
        }
70
71
        $params = [
72
            'auth_code' => $authCode ?: $this->request->get('auth_code'),
73
        ];
74
75
        return $this->parseJSON('json', [self::API_GET_LOGIN_INFO, $params]);
76
    }
77
78
    /**
79
     * {@inheritdoc}.
80
     */
81
    protected function getAuthUrl($state = null)
82
    {
83
        $params = array_merge([
84
            'corp_id'      => $this->clientId,
85
            'redirect_uri' => $this->redirectUrl,
86
            'state'        => $state ?: md5(time()),
87
        ], ['usertype' => 'admin'], $this->parameters);
88
89
        $query = http_build_query($params, '', '&', $this->encodingType);
90
91
        return self::AUTH_URL.'?'.$query;
92
    }
93
}
94