Passed
Push — main ( d761d2...4cb247 )
by Miaad
10:19
created

telegram::__call()   A

Complexity

Conditions 4
Paths 2

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 4
nc 2
nop 2
1
<?php
2
3
namespace BPT\api;
4
use BPT\settings;
5
use BPT\tools;
6
7
/**
8
 * telegram class , Adding normal method call to request class and a simple name for being easy to call
9
 */
10
class telegram extends request {
11
    public function __call (string $name, array $arguments) {
12
        if (!isset($arguments[1]) && isset($arguments[0]) && is_array($arguments[0])) {
13
            return request::$name(...$arguments[0]);
14
        }
15
        else {
16
            return request::$name(...$arguments);
17
        }
18
    }
19
20
    /**
21
     * download telegram file with file_id to destination location
22
     *
23
     * It has 20MB download limit(same as telegram)
24
     *
25
     * e.g. => tools::downloadFile('test.mp4');
26
     *
27
     * e.g. => tools::downloadFile('test.mp4','file_id_asdadadadadadad);
28
     *
29
     * @param string|null $destination destination for save the file
30
     * @param string|null $file_id     file_id for download, if not set, will generate by request::catchFields method
31
     *
32
     * @return bool
33
     */
34
    public static function downloadFile(string|null $destination = null, string|null $file_id = null): bool {
35
        $file = telegram::getFile();
36
        if (isset($file->file_path)) {
37
            $file_path = settings::$down_url.'bot'.settings::$token.'/'.$file->file_path;
38
            return tools::downloadFile($file_path,$destination);
0 ignored issues
show
Bug introduced by
It seems like $destination can also be of type null; however, parameter $path of BPT\tools::downloadFile() 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

38
            return tools::downloadFile($file_path,/** @scrutinizer ignore-type */ $destination);
Loading history...
39
        }
40
        else {
41
            return false;
42
        }
43
    }
44
}