| Total Complexity | 10 |
| Total Lines | 88 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 8 | class Tweet extends ServiceEntity |
||
| 9 | { |
||
| 10 | /** |
||
| 11 | * Get tweet ID. |
||
| 12 | * |
||
| 13 | * @return string|null |
||
| 14 | */ |
||
| 15 | public function getId() |
||
| 16 | { |
||
| 17 | return $this->getData('id'); |
||
|
|
|||
| 18 | } |
||
| 19 | |||
| 20 | /** |
||
| 21 | * Get tweet author. |
||
| 22 | * |
||
| 23 | * @return TweetUser|null |
||
| 24 | */ |
||
| 25 | public function getAuthor() |
||
| 26 | { |
||
| 27 | return $this->makeEntity(TweetUser::class, 'user'); |
||
| 28 | } |
||
| 29 | |||
| 30 | /** |
||
| 31 | * Get publication date. |
||
| 32 | * |
||
| 33 | * @return \DateTimeImmutable |
||
| 34 | */ |
||
| 35 | public function getDate() |
||
| 36 | { |
||
| 37 | return new \DateTimeImmutable($this->getData('created'), 'Europe/Moscow'); |
||
| 38 | } |
||
| 39 | |||
| 40 | /** |
||
| 41 | * Determines whether the tweet has media list. |
||
| 42 | * |
||
| 43 | * @return bool |
||
| 44 | */ |
||
| 45 | public function hasMedia() |
||
| 46 | { |
||
| 47 | return $this->getData('has_media') === true; |
||
| 48 | } |
||
| 49 | |||
| 50 | /** |
||
| 51 | * Get media list. |
||
| 52 | * |
||
| 53 | * @return array|TweetMedia[] |
||
| 54 | */ |
||
| 55 | public function getMedia() |
||
| 56 | { |
||
| 57 | $media = $this->getData('media', []); |
||
| 58 | |||
| 59 | if (!is_array($media) || empty($media)) { |
||
| 60 | return []; |
||
| 61 | } |
||
| 62 | |||
| 63 | return array_map(function (array $item) { |
||
| 64 | return $this->makeEntityFrom(TweetMedia::class, $item); |
||
| 65 | }, $media); |
||
| 66 | } |
||
| 67 | |||
| 68 | /** |
||
| 69 | * Get tweet text. |
||
| 70 | * |
||
| 71 | * @return string|null |
||
| 72 | */ |
||
| 73 | public function getText() |
||
| 76 | } |
||
| 77 | |||
| 78 | /** |
||
| 79 | * Get retweets count. |
||
| 80 | * |
||
| 81 | * @return int |
||
| 82 | */ |
||
| 83 | public function getRetweetsCount() |
||
| 84 | { |
||
| 85 | return intval($this->getData('retweet_count')); |
||
| 86 | } |
||
| 87 | |||
| 88 | /** |
||
| 89 | * Get favorites count. |
||
| 90 | * |
||
| 91 | * @return int |
||
| 92 | */ |
||
| 93 | public function getFavoritesCount() |
||
| 96 | } |
||
| 97 | } |
||
| 98 |