UserNode::getAvatar()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
/**
3
 * This file is part of Platform package.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
declare(strict_types=1);
9
10
namespace Karma\Platform\Ast;
11
12
use Karma\Platform\Io\UserInterface;
13
14
/**
15
 * Class UserNode
16
 * @package Karma\Platform\Ast
17
 */
18
class UserNode extends TextNode
19
{
20
    /**
21
     * @var string
22
     */
23
    private $id;
24
25
    /**
26
     * @var string
27
     */
28
    private $login;
29
30
    /**
31
     * @var null|string
32
     */
33
    private $avatar;
34
35
    /**
36
     * @param string $body
37
     * @param UserInterface $user
38
     * @return static|UserNode
39
     */
40
    public static function fromUserInterface(string $body, UserInterface $user): UserNode
41
    {
42
        return new static($body, $user->getId(), $user->getName(), $user->getAvatar());
43
    }
44
45
    /**
46
     * UserNode constructor.
47
     * @param string $body
48
     * @param string $id
49
     * @param string $login
50
     * @param null|string $avatar
51
     */
52
    public function __construct(string $body, string $id, string $login, ?string $avatar)
53
    {
54
        $this->id = $id;
55
        $this->login = $login;
56
        $this->avatar = $avatar;
57
58
        parent::__construct($body);
59
    }
60
61
    /**
62
     * @return string
63
     */
64
    public function getId(): string
65
    {
66
        return $this->id;
67
    }
68
69
    /**
70
     * @return string
71
     */
72
    public function getLogin(): string
73
    {
74
        return $this->login;
75
    }
76
77
    /**
78
     * @return null|string
79
     */
80
    public function getAvatar(): ?string
81
    {
82
        return $this->avatar;
83
    }
84
}
85