GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Push — master ( b87887...138d7a )
by t
62:54 queued 27s
created

DataCrypt   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 15
c 1
b 0
f 0
dl 0
loc 26
rs 10
wmc 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
A decrypt() 0 19 5
A __construct() 0 3 1
1
<?php
2
3
namespace icy2003\php\iapis\wechat\miniprogram;
4
5
use Exception;
6
use icy2003\php\iapis\Api;
7
use icy2003\php\ihelpers\Json;
8
9
class DataCrypt extends Api
10
{
11
    public function __construct($appid)
12
    {
13
        $this->setOption('appid', $appid);
14
    }
15
16
    public function decrypt($encryptedData, $iv, $sessionKey)
17
    {
18
        if (24 !== strlen($sessionKey)) {
19
            throw new Exception('错误的 session key');
20
        }
21
        if (24 !== strlen($iv)) {
22
            throw new Exception('错误的 iv');
23
        }
24
        $aesKey = base64_decode($sessionKey);
25
        $aesIv = base64_decode($iv);
26
        $aesCipher = base64_decode($encryptedData);
27
        $this->_result = Json::decode(openssl_decrypt($aesCipher, 'aes-128-cbc', $aesKey, OPENSSL_RAW_DATA, $aesIv));
0 ignored issues
show
Documentation Bug introduced by
It seems like icy2003\php\ihelpers\Jso...NSSL_RAW_DATA, $aesIv)) can also be of type false. However, the property $_result is declared as type array. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
28
        if (null === $this->_result) {
29
            throw new Exception('错误的 encryptedData');
30
        }
31
        if ($this->_result['watermark']['appid'] !== $this->_options['appid']) {
32
            throw new Exception('错误的 appid');
33
        }
34
        return $this;
35
    }
36
}
37