Tweet   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 95
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 7
lcom 0
cbo 0
dl 0
loc 95
ccs 0
cts 32
cp 0
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A createFromArray() 0 6 1
A getMessage() 0 4 1
A getUser() 0 4 1
A getHashtags() 0 4 1
A getLocation() 0 4 1
A getCreatedAt() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This software may be modified and distributed under the terms
7
 * of the MIT license. See the LICENSE file for details.
8
 */
9
10
namespace FAPI\Boilerplate\Model\Tweet;
11
12
use FAPI\Boilerplate\Model\CreatableFromArray;
13
14
/**
15
 * @author Tobias Nyholm <[email protected]>
16
 */
17
final class Tweet implements CreatableFromArray
18
{
19
    /**
20
     * @var string
21
     */
22
    private $message;
23
24
    /**
25
     * @var string
26
     */
27
    private $user;
28
29
    /**
30
     * @var array
31
     */
32
    private $hashtags;
33
34
    /**
35
     * @var string
36
     */
37
    private $location;
38
39
    /**
40
     * @var \DateTimeInterface
41
     */
42
    private $createdAt;
43
44
    /**
45
     * @param string             $message
46
     * @param string             $user
47
     * @param string             $location
48
     * @param array              $hashtags
49
     * @param \DateTimeInterface $createdAt
50
     */
51
    private function __construct(string $message, string $user, string $location, array $hashtags, \DateTimeInterface $createdAt)
52
    {
53
        $this->message = $message;
54
        $this->user = $user;
55
        $this->hashtags = $hashtags;
56
        $this->location = $location;
57
        $this->createdAt = $createdAt;
58
    }
59
60
    /**
61
     * @param array $data
62
     *
63
     * @return Tweet
64
     */
65
    public static function createFromArray(array $data): Tweet
66
    {
67
        // TODO some validation on input
68
69
        return new self($data['message'], $data['user'], $data['location'], $data['hashtags'], new \DateTimeImmutable($data['timestamp']));
70
    }
71
72
    /**
73
     * @return string
74
     */
75
    public function getMessage(): string
76
    {
77
        return $this->message;
78
    }
79
80
    /**
81
     * @return string
82
     */
83
    public function getUser(): string
84
    {
85
        return $this->user;
86
    }
87
88
    /**
89
     * @return array
90
     */
91
    public function getHashtags(): array
92
    {
93
        return $this->hashtags;
94
    }
95
96
    /**
97
     * @return string
98
     */
99
    public function getLocation(): string
100
    {
101
        return $this->location;
102
    }
103
104
    /**
105
     * @return \DateTimeInterface
106
     */
107
    public function getCreatedAt(): \DateTimeInterface
108
    {
109
        return $this->createdAt;
110
    }
111
}
112