Completed
Pull Request — develop (#304)
by
unknown
02:48
created

User::getFirstName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
/**
3
 * This file is part of the TelegramBot package.
4
 *
5
 * (c) Avtandil Kikabidze aka LONGMAN <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Longman\TelegramBot\Entities;
12
13
use Longman\TelegramBot\Exception\TelegramException;
14
15
class User extends Entity
16
{
17
    /**
18
     * @var mixed|null
19
     */
20
    protected $id;
21
22
    /**
23
     * @var mixed|null
24
     */
25
    protected $first_name;
26
27
    /**
28
     * @var mixed|null
29
     */
30
    protected $last_name;
31
32
    /**
33
     * @var mixed|null
34
     */
35
    protected $username;
36
37
    /**
38
     * User constructor.
39
     *
40
     * @param array $data
41
     * @throws \Longman\TelegramBot\Exception\TelegramException
42
     */
43 26
    public function __construct(array $data)
44
    {
45
46 26
        $this->id = isset($data['id']) ? $data['id'] : null;
47 26
        if (empty($this->id)) {
48 1
            throw new TelegramException('id is empty!');
49
        }
50
51 25
        $this->first_name = isset($data['first_name']) ? $data['first_name'] : null;
52
53 25
        $this->last_name = isset($data['last_name']) ? $data['last_name'] : null;
54 25
        $this->username  = isset($data['username']) ? $data['username'] : null;
55 25
    }
56
57
    /**
58
     * Get id
59
     *
60
     * @return mixed|null
61
     */
62 9
    public function getId()
63
    {
64 9
        return $this->id;
65
    }
66
67
    /**
68
     * Get first name
69
     *
70
     * @return mixed|null
71
     */
72 9
    public function getFirstName()
73
    {
74 9
        return $this->first_name;
75
    }
76
77
    /**
78
     * Get last name
79
     *
80
     * @return mixed|null
81
     */
82 7
    public function getLastName()
83
    {
84 7
        return $this->last_name;
85
    }
86
87
    /**
88
     * Get username
89
     *
90
     * @return mixed|null
91
     */
92 9
    public function getUsername()
93
    {
94 9
        return $this->username;
95
    }
96
97
    /**
98
     * Try nebtion
99
     *
100
     * @return mixed|null|string
101
     */
102 3
    public function tryMention()
103
    {
104 3 View Code Duplication
        if (is_null($this->username)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
105 2
            if (!is_null($this->last_name)) {
106 1
                return $this->first_name . ' ' . $this->last_name;
107
            }
108 1
            return $this->first_name;
109
        }
110 1
        return '@' . $this->username;
111
    }
112
}
113