Passed
Push — main ( cb0dfb...09414e )
by Miaad
10:52
created

callback::encodeData()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 2
rs 10
1
<?php
2
3
namespace BPT\receiver;
4
use BPT\BPT;
5
use BPT\constants\callbackTypes;
6
use BPT\constants\codecAction;
7
use BPT\pay\crypto;
8
use BPT\settings;
9
use BPT\tools\tools;
10
11
class callback {
12
    public static function encodeData (array $data): string {
13
        return tools::codec(codecAction::ENCRYPT, json_encode($data), md5(settings::$token), 'SguQgUvvKRLvmCyq')['hash'];
14
    }
15
16
    public static function decodeData (string $data): array {
17
        return json_decode(tools::codec(codecAction::DECRYPT, $data, md5(settings::$token), 'SguQgUvvKRLvmCyq'), true);
0 ignored issues
show
Bug introduced by
It seems like BPT\tools\tools::codec(B...n), 'SguQgUvvKRLvmCyq') can also be of type array<string,string>; however, parameter $json of json_decode() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

17
        return json_decode(/** @scrutinizer ignore-type */ tools::codec(codecAction::DECRYPT, $data, md5(settings::$token), 'SguQgUvvKRLvmCyq'), true);
Loading history...
18
    }
19
20
    public static function process () {
21
        if (!settings::$handler || settings::$receiver != \BPT\constants\receiver::WEBHOOK || settings::$multi || !(isset($_GET['data']) || isset($_POST['data']))) {
22
            return false;
23
        }
24
25
        $input = $_GET['data'] ?? $_POST['data'];
26
27
        if (!($data = self::decodeData($input))) {
28
            return false;
29
        }
30
31
        if (!is_array($data)) {
0 ignored issues
show
introduced by
The condition is_array($data) is always true.
Loading history...
32
            return false;
33
        }
34
35
        if ($data['type'] === callbackTypes::CRYPTO) {
36
            return crypto::callbackProcess($data);
37
        }
38
39
        return false;
40
    }
41
42
    public static function callHandler (string $handler_name, $input) {
43
        if (method_exists(BPT::$handler, $handler_name)) {
44
            BPT::$handler->$handler_name($input);
45
        }
46
    }
47
}