Passed
Push — main ( 926a07...7834cc )
by Miaad
10:19
created

telegram::downloadFile()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 6
c 0
b 0
f 0
nc 2
nop 2
dl 0
loc 8
rs 10
1
<?php
2
3
namespace BPT\telegram;
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
        return request::$name(...$arguments);
13
    }
14
15
    /**
16
     * download telegram file with file_id to destination location
17
     *
18
     * It has 20MB download limit(same as telegram)
19
     *
20
     * e.g. => tools::downloadFile('test.mp4');
21
     *
22
     * e.g. => tools::downloadFile('test.mp4','file_id_asdadadadadadad);
23
     *
24
     * @param string|null $destination destination for save the file
25
     * @param string|null $file_id     file_id for download, if not set, will generate by request::catchFields method
26
     *
27
     * @return bool
28
     */
29
    public static function downloadFile (string|null $destination = null, string|null $file_id = null): bool {
30
        $file = telegram::getFile($file_id);
31
        if (isset($file->file_path)) {
32
            $file_path = settings::$down_url . 'bot' . settings::$token . '/' . $file->file_path;
33
            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

33
            return tools::downloadFile($file_path, /** @scrutinizer ignore-type */ $destination);
Loading history...
34
        }
35
        else {
36
            return false;
37
        }
38
    }
39
}