Passed
Push — main ( f82312...487838 )
by Miaad
10:48 queued 13s
created

user::getProfiles()   A

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 3
dl 0
loc 2
rs 10
1
<?php
2
3
namespace BPT\types;
4
5
use BPT\constants\parseMode;
6
use BPT\telegram\telegram;
7
use BPT\tools\tools;
8
use stdClass;
9
10
/**
11
 * This object represents a Telegram user or bot.
12
 */
13
class user 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...
14
    /** Keep all of properties which has sub properties */
15
    private const subs = [];
16
17
    /**
18
     * Unique identifier for this user or bot. This number may have more than 32 significant bits and some
19
     * programming languages may have difficulty/silent defects in interpreting it. But it has at most 52 significant
20
     * bits, so a 64-bit integer or double-precision float type are safe for storing this identifier.
21
     */
22
    public int $id;
23
24
    /** True, if this user is a bot */
25
    public null|bool $is_bot = null;
26
27
    /** User's or bot's first name */
28
    public null|string $first_name = null;
29
30
    /** Optional. User's or bot's last name */
31
    public null|string $last_name = null;
32
33
    /** Optional. User's or bot's username */
34
    public null|string $username = null;
35
36
    /** Optional. IETF language tag of the user's language */
37
    public null|string $language_code = null;
38
39
    /** Optional. True, if this user is a Telegram Premium user */
40
    public null|bool $is_premium = null;
41
42
    /** Optional. True, if this user added the bot to the attachment menu */
43
    public null|bool $added_to_attachment_menu = null;
44
45
    /** Optional. True, if the bot can be invited to groups. Returned only in getMe. */
46
    public null|bool $can_join_groups = null;
47
48
    /** Optional. True, if privacy mode is disabled for the bot. Returned only in getMe. */
49
    public null|bool $can_read_all_group_messages = null;
50
51
    /** Optional. True, if the bot supports inline queries. Returned only in getMe. */
52
    public null|bool $supports_inline_queries = null;
53
54
55
    public function __construct(stdClass|null $object = null) {
56
        if ($object != null) {
57
            parent::__construct($object, self::subs);
58
        }
59
    }
60
61
    /**
62
     * Get user invite link(referral link)
63
     *
64
     * Same as tools::inviteLink($user_id);
65
     *
66
     * These links can be proceeded by library databases
67
     *
68
     * @return string
69
     */
70
    public function inviteLink(): string {
71
        return tools::inviteLink($this->id);
72
    }
73
74
    /**
75
     * Get fullname of user
76
     *
77
     * If last name exist : Firstname . ' ' . lastname
78
     *
79
     * if not : Firstname
80
     *
81
     * @param bool $nameFirst
82
     *
83
     * @return string
84
     */
85
    public function fullName(bool $nameFirst = true): string {
86
        return trim($nameFirst ? $this->first_name . ' ' . $this->last_name : $this->last_name . ' ' . $this->first_name);
87
    }
88
89
    /**
90
     * Get user profiles
91
     *
92
     * @param null|int  $offset
93
     * @param null|int  $limit
94
     * @param null|bool $answer
95
     *
96
     * @return userProfilePhotos|responseError
97
     */
98
    public function getProfiles(int|null $offset = null, int|null $limit = null, bool $answer = null): userProfilePhotos|responseError {
99
        return telegram::getUserProfilePhotos($this->id, $offset, $limit, answer: $answer);
100
    }
101
102
    /**
103
     * Get user mention link for different parse mode
104
     *
105
     * if link_text parameter is empty, it will use fullname for link text
106
     *
107
     * @param string $link_text
108
     * @param string $parse_mode
109
     *
110
     * @return string
111
     */
112
    public function getMention (string $link_text = '', string $parse_mode = '') {
113
        if (empty($link_text)) {
114
            $link_text = $this->fullName();
115
        }
116
117
        if ($parse_mode === parseMode::HTML) {
118
            return "<a href=\"tg://user?id=$this->id\">$link_text</a>";
119
        }
120
121
        if ($parse_mode === parseMode::MARKDOWN || $parse_mode === parseMode::MARKDOWNV2) {
122
            return "[$link_text](tg://user?id=$this->id)";
123
        }
124
125
        return "tg://user?id=$this->id";
126
    }
127
}
128