Passed
Pull Request — master (#697)
by
unknown
02:51
created

ClearQuota::clear()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 5
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 12
ccs 0
cts 9
cp 0
crap 6
rs 9.4285
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
 * Broadcast.php.
14
 *
15
 * @author    overtrue <[email protected]>
16
 * @copyright 2015 overtrue <[email protected]>
17
 *
18
 * @see      https://github.com/overtrue
19
 * @see      http://overtrue.me
20
 */
21
22
namespace EasyWeChat\ClearQuota;
23
24
use EasyWeChat\Core\AbstractAPI;
25
26
class ClearQuota extends AbstractAPI
27
{
28
    const API_CLEAR = 'https://api.weixin.qq.com/cgi-bin/clear_quota';
29
30
    public function clear($appId = '')
31
    {
32
        // appId defaults to the current appId
33
        if(! $appId)
34
        {
35
            $appId = $this->getAccessToken()->getAppId();
36
        }
37
38
        $options['appid'] = $appId;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$options was never initialized. Although not strictly required by PHP, it is generally a good practice to add $options = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
39
40
        return $this->parseJSON('json', [self::API_CLEAR, $options]);
41
    }
42
}
43