videoNote::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 2
c 0
b 0
f 0
nc 2
nop 1
dl 0
loc 3
rs 10
1
<?php
2
3
namespace BPT\types;
4
5
use BPT\telegram\telegram;
6
use BPT\tools\tools;
7
use stdClass;
8
9
/**
10
 * This object represents a video message (available in Telegram apps as of v.4.0).
11
 */
12
class videoNote extends types {
0 ignored issues
show
Bug introduced by
The type BPT\types\types was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
13
    /** Keep all properties which has sub properties */
14
    private const subs = ['thumbnail' => 'BPT\types\photoSize'];
15
16
    /** Identifier for this file, which can be used to download or reuse the file */
17
    public string $file_id;
18
19
    /**
20
     * Unique identifier for this file, which is supposed to be the same over time and for different bots. Can't be
21
     * used to download or reuse the file.
22
     */
23
    public string $file_unique_id;
24
25
    /** Video width and height (diameter of the video message) as defined by sender */
26
    public int $length;
27
28
    /** Duration of the video in seconds as defined by sender */
29
    public int $duration;
30
31
    /** Optional. Video thumbnail */
32
    public null|photoSize $thumbnail = null;
33
34
    /** Optional. File size in bytes */
35
    public null|int $file_size = null;
36
37
38
    public function __construct(stdClass|null $object = null) {
39
        if ($object != null) {
40
            parent::__construct($object, self::subs);
41
        }
42
    }
43
44
    /**
45
     * download this file and save it in destination
46
     *
47
     * if destination doesn't set , it will return the downloaded file(as string)
48
     *
49
     * It has 20MB download limit(same as telegram)
50
     *
51
     * e.g. => $video_note->download();
52
     *
53
     * e.g. => $video_note->download('test.mp4');
54
     *
55
     * @param string|null $destination destination for save the file
56
     *
57
     * @return bool|string string will be returned when destination doesn't set
58
     */
59
    public function download(string|null $destination = null): bool|string {
60
        return telegram::downloadFile($destination ?? 'unknown.mp4',$this->file_id);
61
    }
62
63
    /**
64
     * Get download link of this file
65
     *
66
     * It does not bypass telegram limits(e.g: Download size limit in public bot api)
67
     *
68
     * @return string
69
     */
70
    public function link(): string {
71
        return telegram::fileLink($this->file_id);
72
    }
73
74
    public function typedSize (int $precision = 2, bool $space_between = true): string {
75
        return tools::byteFormat($this->file_id, $precision, $space_between);
0 ignored issues
show
Bug introduced by
$this->file_id of type string is incompatible with the type integer expected by parameter $byte of BPT\tools\tools::byteFormat(). ( Ignorable by Annotation )

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

75
        return tools::byteFormat(/** @scrutinizer ignore-type */ $this->file_id, $precision, $space_between);
Loading history...
76
    }
77
}
78