Completed
Push — master ( d83f32...d4821e )
by Rémi
04:29
created

UserIdentifier::getId()   A

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
c 0
b 0
f 0
ccs 0
cts 2
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
3
namespace Twitter\API\REST\DTO;
4
5
use Twitter\API\REST\ApiParameters;
6
7
class UserIdentifier implements ApiParameters
8
{
9
    /** @var int */
10
    private $id;
11
12
    /** @var string */
13
    private $screenName;
14
15
    /**
16
     * UserIdentifier constructor.
17
     *
18
     * @param int    $id
19
     * @param string $screenName
20
     */
21 51
    private function __construct($id, $screenName)
22
    {
23
24 51
        $this->id = $id;
25 51
        $this->screenName = $screenName;
26 51
    }
27
28
    /**
29
     * @return int
30
     */
31
    public function getId()
32
    {
33
        return $this->id;
34
    }
35
36
    /**
37
     * @return string
38
     */
39
    public function getScreenName()
40
    {
41
        return $this->screenName;
42
    }
43
44
    /**
45
     * @param int $id
46
     *
47
     * @return UserIdentifier
48
     */
49 48
    public static function fromId($id)
50
    {
51 48
        return new self($id, null);
52
    }
53
54
    /**
55
     * @param string $screenName
56
     *
57
     * @return UserIdentifier
58
     */
59 6
    public static function fromScreenName($screenName)
60
    {
61 6
        return new self(null, $screenName);
62
    }
63
64
    /**
65
     * @return array
66
     */
67 12
    public function toArray()
68
    {
69 12
        if ($this->id !== null) {
70
            return [
71 9
                'user_id' => $this->id
72 6
            ];
73
        }
74
75
        return [
76 3
            'screen_name' => $this->screenName
77 2
        ];
78
    }
79
}
80