Completed
Push — master ( 257c19...712c83 )
by Rémi
04:23
created

UserIdentifier::toArray()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 12
c 0
b 0
f 0
ccs 6
cts 6
cp 1
rs 9.4285
cc 2
eloc 6
nc 2
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