Passed
Push — main ( 2ad3f1...bfb9d3 )
by Miaad
01:30
created

webhook::processUpdate()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 7
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 0
1
<?php
2
3
namespace BPT\receiver;
4
5
use BPT\BPT;
6
use BPT\lock;
7
use BPT\logger;
8
use BPT\settings;
9
use BPT\tools;
10
use BPT\types\update;
11
12
class webhook {
13
    public static function init () {
14
        if (lock::exist('BPT-HOOK')) {
15
            self::telegramVerify();
16
            BPT::$update = self::processUpdate();
17
        }
18
        else {
19
            self::deleteOldLocks();
20
        }
21
    }
22
23
    public static function telegramVerify() {
24
        if (settings::$telegram_verify) {
25
            if (!tools::isTelegram($_SERVER['REMOTE_ADDR'])) {
26
                logger::write('not authorized access denied. IP : '.$_SERVER['REMOTE_ADDR'],'error');
27
                BPT::close();
28
            }
29
        }
30
    }
31
32
    public static function processUpdate(): update {
33
        $update = json_decode(file_get_contents("php://input"));
34
        if ($update) {
35
            return new update($update);
36
        }
37
        else {
38
            BPT::close();
0 ignored issues
show
Bug Best Practice introduced by
In this branch, the function will implicitly return null which is incompatible with the type-hinted return BPT\types\update. Consider adding a return statement or allowing null as return value.

For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example:

interface ReturnsInt {
    public function returnsIntHinted(): int;
}

class MyClass implements ReturnsInt {
    public function returnsIntHinted(): int
    {
        if (foo()) {
            return 123;
        }
        // here: null is implicitly returned
    }
}
Loading history...
39
        }
40
    }
41
42
    public static function deleteOldLocks() {
43
        if (lock::exist('BPT-MULTI')) {
44
            lock::delete('BPT-MULTI');
45
        }
46
        if (lock::exist('BPT-MULTI-2')) {
47
            lock::delete('BPT-MULTI-2');
48
        }
49
        if (lock::exist('getUpdate')) {
50
            lock::delete('getUpdate');
51
        }
52
    }
53
}