UserIdentifier::fromId()   A
last analyzed

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
dl 0
loc 4
c 0
b 0
f 0
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
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 108
    private function __construct($id, $screenName)
22
    {
23
24 108
        $this->id = $id;
25 108
        $this->screenName = $screenName;
26 108
    }
27
28
    /**
29
     * @param int $id
30
     *
31
     * @return UserIdentifier
32
     */
33 84
    public static function fromId($id)
34
    {
35 84
        return new self($id, null);
36
    }
37
38
    /**
39
     * @param string $screenName
40
     *
41
     * @return UserIdentifier
42
     */
43 78
    public static function fromScreenName($screenName)
44
    {
45 78
        return new self(null, $screenName);
46
    }
47
48
    /**
49
     * @return array
50
     */
51 54
    public function toArray()
52
    {
53 54
        if ($this->id !== null) {
54
            return [
55 27
                'user_id' => $this->id
56 18
            ];
57
        }
58
59
        return [
60 27
            'screen_name' => $this->screenName
61 18
        ];
62
    }
63
}
64