Passed
Push — master ( abd03a...b605c3 )
by Carlos
03:31
created

OpenPlatform::createAuthorizer()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 8
c 0
b 0
f 0
nc 1
nop 2
dl 0
loc 12
rs 9.4285
ccs 8
cts 8
cp 1
crap 1
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
 * OpenPlatform.php.
14
 *
15
 * Part of Overtrue\WeChat.
16
 *
17
 * For the full copyright and license information, please view the LICENSE
18
 * file that was distributed with this source code.
19
 *
20
 * @author    mingyoung <[email protected]>
21
 * @copyright 2016
22
 *
23
 * @see      https://github.com/overtrue
24
 * @see      http://overtrue.me
25
 */
26
27
namespace EasyWeChat\OpenPlatform;
28
29
use EasyWeChat\Support\Traits\PrefixedContainer;
30
31
/**
32
 * Class OpenPlatform.
33
 *
34
 * @property \EasyWeChat\OpenPlatform\Api\BaseApi $api
35
 * @property \EasyWeChat\OpenPlatform\Api\PreAuthorization $pre_auth
36
 * @property \EasyWeChat\OpenPlatform\Guard $server
37
 * @property \EasyWeChat\OpenPlatform\AccessToken $access_token
38
 *
39
 * @method \EasyWeChat\Support\Collection getAuthorizationInfo($authCode = null)
40
 * @method \EasyWeChat\Support\Collection getAuthorizerInfo($authorizerAppId)
41
 * @method \EasyWeChat\Support\Collection getAuthorizerOption($authorizerAppId, $optionName)
42
 * @method \EasyWeChat\Support\Collection setAuthorizerOption($authorizerAppId, $optionName, $optionValue)
43
 */
44
class OpenPlatform
45
{
46
    use PrefixedContainer;
47
48
    /**
49
     * Create an instance of the EasyWeChat for the given authorizer.
50
     *
51
     * @param string $appId        Authorizer AppId
52
     * @param string $refreshToken Authorizer refresh-token
53
     *
54
     * @return \EasyWeChat\Foundation\Application
55
     */
56 1
    public function createAuthorizerApplication($appId, $refreshToken)
57
    {
58 1
        $this->fetch('authorization')
59 1
            ->setAuthorizerAppId($appId)
60 1
            ->setAuthorizerRefreshToken($refreshToken);
61
62 1
        $application = $this->fetch('app');
63 1
        $application['access_token'] = $this->fetch('authorizer_access_token');
64 1
        $application['oauth'] = $this->fetch('oauth');
65
66 1
        return $application;
67
    }
68
69
    /**
70
     * Quick access to the base-api.
71
     *
72
     * @param string $method
73
     * @param array  $args
74
     *
75
     * @return mixed
76
     */
77
    public function __call($method, $args)
78
    {
79
        return call_user_func_array([$this->api, $method], $args);
80
    }
81
}
82