file::link()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 2
rs 10
1
<?php
2
3
namespace BPT\types;
4
5
use BPT\settings;
6
use BPT\tools\tools;
7
use stdClass;
8
9
/**
10
 * This object represents a file ready to be downloaded. The file can be downloaded via the link
11
 * https://api.telegram.org/file/bot<token>/<file_path>. It is guaranteed that the link will be valid for at
12
 * least 1 hour. When the link expires, a new one can be requested by calling getFile.
13
 */
14
class file 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...
15
    /** Keep all of properties which has sub properties */
16
    private const subs = [];
17
18
    /** Identifier for this file, which can be used to download or reuse the file */
19
    public string $id;
20
21
    /** Identifier for this file, which can be used to download or reuse the file */
22
    public string $file_id;
23
24
    /**
25
     * Unique identifier for this file, which is supposed to be the same over time and for different bots. Can't be
26
     * used to download or reuse the file.
27
     */
28
    public string $file_unique_id;
29
30
    /**
31
     * Optional. File size in bytes. It can be bigger than 2^31 and some programming languages may have
32
     * difficulty/silent defects in interpreting it. But it has at most 52 significant bits, so a signed 64-bit
33
     * integer or double-precision float type are safe for storing this value.
34
     */
35
    public null|int $file_size = null;
36
37
    /** Optional. File path. Use https://api.telegram.org/file/bot<token>/<file_path> to get the file. */
38
    public null|string $file_path = null;
39
40
41
    public function __construct(stdClass|null $object = null) {
42
        if ($object != null) {
43
            parent::__construct($object, self::subs);
44
        }
45
    }
46
47
    /**
48
     * Get download link of this file
49
     *
50
     * It does not bypass telegram limits(e.g: Download size limit in public bot api)
51
     *
52
     * @return string
53
     */
54
    public function link(): string {
55
        return settings::$down_url . '/bot' . settings::$token . '/' . $this->file_path;
56
    }
57
58
    public function typedSize (int $precision = 2, bool $space_between = true): string {
59
        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

59
        return tools::byteFormat(/** @scrutinizer ignore-type */ $this->file_id, $precision, $space_between);
Loading history...
60
    }
61
}
62