Passed
Push — master ( e38f5c...931b65 )
by Carlos
06:23 queued 02:38
created

OpenPlatform::createAuthorizer()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 7
nc 1
nop 2
dl 0
loc 11
ccs 7
cts 7
cp 1
crap 1
rs 9.4285
c 0
b 0
f 0
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\PreAuthorization $pre_auth
35
 * @property \EasyWeChat\OpenPlatform\Guard $server
36
 * @property \EasyWeChat\OpenPlatform\AccessToken $access_token
37
 *
38
 * @method \EasyWeChat\Support\Collection getAuthorizationInfo($authCode = null)
39
 * @method \EasyWeChat\Support\Collection getAuthorizationToken($authorizerAppId, $authorizerRefreshToken)
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 createAuthorizer($appId, $refreshToken)
57
    {
58 1
        $this->authorization->setAuthorizerAppId($appId);
0 ignored issues
show
Documentation introduced by
The property authorization does not exist on object<EasyWeChat\OpenPlatform\OpenPlatform>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
59 1
        $this->authorization->setAuthorizerRefreshToken($refreshToken);
0 ignored issues
show
Documentation introduced by
The property authorization does not exist on object<EasyWeChat\OpenPlatform\OpenPlatform>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
60
61 1
        $application = $this->app;
0 ignored issues
show
Bug introduced by
The property app does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
62 1
        $application['access_token'] = $this->authorizer_token;
0 ignored issues
show
Bug introduced by
The property authorizer_token does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
63 1
        $application['oauth'] = $this->oauth;
0 ignored issues
show
Bug introduced by
The property oauth does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
64
65 1
        return $application;
66
    }
67
68
    /**
69
     * Quick access to the base-api.
70
     *
71
     * @param string $method
72
     * @param array  $args
73
     *
74
     * @return mixed
75
     */
76
    public function __call($method, $args)
77
    {
78
        return call_user_func_array([$this->api, $method], $args);
0 ignored issues
show
Documentation introduced by
The property api does not exist on object<EasyWeChat\OpenPlatform\OpenPlatform>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
79
    }
80
}
81