1 | <?php |
||||||
2 | |||||||
3 | namespace Osnova\Services\Tweets; |
||||||
4 | |||||||
5 | use Osnova\Services\Media\TweetMedia; |
||||||
6 | use Osnova\Services\ServiceEntity; |
||||||
7 | |||||||
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'); |
||||||
0 ignored issues
–
show
Bug
Best Practice
introduced
by
![]() |
|||||||
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'); |
||||||
0 ignored issues
–
show
It seems like
$this->getData('created') can also be of type array ; however, parameter $time of DateTimeImmutable::__construct() does only seem to accept string , maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() 'Europe/Moscow' of type string is incompatible with the type DateTimeZone expected by parameter $timezone of DateTimeImmutable::__construct() .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
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', []); |
||||||
0 ignored issues
–
show
array() of type array is incompatible with the type null|string expected by parameter $default of Osnova\Services\ServiceEntity::getData() .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
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() |
||||||
74 | { |
||||||
75 | return $this->getData('text') ?? ''; |
||||||
0 ignored issues
–
show
|
|||||||
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() |
||||||
94 | { |
||||||
95 | return intval($this->getData('favorite_count')); |
||||||
96 | } |
||||||
97 | } |
||||||
98 |