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

UserIdentifier   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 0
dl 0
loc 57
ccs 14
cts 14
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A fromId() 0 4 1
A fromScreenName() 0 4 1
A toArray() 0 12 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