document::__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
eloc 2
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
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 general file (as opposed to photos, voice messages and audio files).
11
 */
12
class document 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
    /** Optional. Document thumbnail as defined by sender */
26
    public null|photoSize $thumbnail = null;
27
28
    /** Optional. Original filename as defined by sender */
29
    public null|string $file_name = null;
30
31
    /** Optional. MIME type of the file as defined by sender */
32
    public null|string $mime_type = null;
33
34
    /**
35
     * Optional. File size in bytes. It can be bigger than 2^31 and some programming languages may have
36
     * difficulty/silent defects in interpreting it. But it has at most 52 significant bits, so a signed 64-bit
37
     * integer or double-precision float type are safe for storing this value.
38
     */
39
    public null|int $file_size = null;
40
41
42
    public function __construct(stdClass|null $object = null) {
43
        if ($object != null) {
44
            parent::__construct($object, self::subs);
45
        }
46
    }
47
48
    /**
49
     * download this file and save it in destination
50
     *
51
     * if destination doesn't set , it will save in `file_name` file
52
     *
53
     * It has 20MB download limit(same as telegram)
54
     *
55
     * e.g. => $document->download();
56
     *
57
     * e.g. => $document->download('test.zip');
58
     *
59
     * @param string|null $destination destination for save the file
60
     *
61
     * @return bool|string string will be returned when destination doesn't set
62
     */
63
    public function download(string|null $destination = null): bool|string {
64
        return telegram::downloadFile($destination ?? $this->file_name ?? 'unknown.txt',$this->file_id);
65
    }
66
67
    /**
68
     * Get download link of this file
69
     *
70
     * It does not bypass telegram limits(e.g: Download size limit in public bot api)
71
     *
72
     * @return string
73
     */
74
    public function link(): string {
75
        return telegram::fileLink($this->file_id);
76
    }
77
78
    public function typedSize (int $precision = 2, bool $space_between = true): string {
79
        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

79
        return tools::byteFormat(/** @scrutinizer ignore-type */ $this->file_id, $precision, $space_between);
Loading history...
80
    }
81
}
82