Completed
Push — master ( 257c19...712c83 )
by Rémi
04:23
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 69
    private function __construct($id, $screenName)
22
    {
23
24 69
        $this->id = $id;
25 69
        $this->screenName = $screenName;
26 69
    }
27
28
    /**
29
     * @param int $id
30
     *
31
     * @return UserIdentifier
32
     */
33 57
    public static function fromId($id)
34
    {
35 57
        return new self($id, null);
36
    }
37
38
    /**
39
     * @param string $screenName
40
     *
41
     * @return UserIdentifier
42
     */
43 15
    public static function fromScreenName($screenName)
44
    {
45 15
        return new self(null, $screenName);
46
    }
47
48
    /**
49
     * @return array
50
     */
51 30
    public function toArray()
52
    {
53 30
        if ($this->id !== null) {
54
            return [
55 18
                'user_id' => $this->id
56 12
            ];
57
        }
58
59
        return [
60 12
            'screen_name' => $this->screenName
61 8
        ];
62
    }
63
}
64