user   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 119
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 26
c 0
b 0
f 0
dl 0
loc 119
rs 10
wmc 11

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getMention() 0 14 5
A __construct() 0 3 2
A fullName() 0 2 2
A inviteLink() 0 2 1
A getProfiles() 0 2 1
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 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
     * Optional. True, if the bot can be connected to a Telegram Business account to receive its messages. Returned
56
     * only in getMe.
57
     */
58
    public null|bool $can_connect_to_business = null;
59
60
61
    public function __construct(stdClass|null $object = null) {
62
        if ($object != null) {
63
            parent::__construct($object, self::subs);
64
        }
65
    }
66
67
    /**
68
     * Get user invite link(referral link)
69
     *
70
     * Same as tools::inviteLink($user_id);
71
     *
72
     * These links can be proceeded by library databases
73
     *
74
     * @return string
75
     */
76
    public function inviteLink(): string {
77
        return tools::inviteLink($this->id);
78
    }
79
80
    /**
81
     * Get fullname of user
82
     *
83
     * If last name exist : Firstname . ' ' . lastname
84
     *
85
     * if not : Firstname
86
     *
87
     * @param bool $nameFirst
88
     *
89
     * @return string
90
     */
91
    public function fullName(bool $nameFirst = true): string {
92
        return trim($nameFirst ? $this->first_name . ' ' . $this->last_name : $this->last_name . ' ' . $this->first_name);
93
    }
94
95
    /**
96
     * Get user profiles
97
     *
98
     * @param null|int  $offset
99
     * @param null|int  $limit
100
     * @param null|bool $answer
101
     *
102
     * @return userProfilePhotos|responseError
103
     */
104
    public function getProfiles(int|null $offset = null, int|null $limit = null, bool $answer = null): userProfilePhotos|responseError {
105
        return telegram::getUserProfilePhotos($this->id, $offset, $limit, answer: $answer);
106
    }
107
108
    /**
109
     * Get user mention link for different parse mode
110
     *
111
     * if link_text parameter is empty, it will use fullname for link text
112
     *
113
     * @param string $link_text
114
     * @param string $parse_mode
115
     *
116
     * @return string
117
     */
118
    public function getMention (string $link_text = '', string $parse_mode = '') {
119
        if (empty($link_text)) {
120
            $link_text = $this->fullName();
121
        }
122
123
        if ($parse_mode === parseMode::HTML) {
124
            return "<a href=\"tg://user?id=$this->id\">$link_text</a>";
125
        }
126
127
        if ($parse_mode === parseMode::MARKDOWN || $parse_mode === parseMode::MARKDOWNV2) {
128
            return "[$link_text](tg://user?id=$this->id)";
129
        }
130
131
        return "tg://user?id=$this->id";
132
    }
133
}
134