Tweet   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 88
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 14
dl 0
loc 88
rs 10
c 0
b 0
f 0
wmc 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A getText() 0 3 1
A getMedia() 0 11 3
A getId() 0 3 1
A getAuthor() 0 3 1
A getDate() 0 3 1
A getFavoritesCount() 0 3 1
A getRetweetsCount() 0 3 1
A hasMedia() 0 3 1
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
The expression return $this->getData('id') also could return the type array which is incompatible with the documented return type null|string.
Loading history...
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
Bug introduced by
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 ignore-type  annotation

37
        return new \DateTimeImmutable(/** @scrutinizer ignore-type */ $this->getData('created'), 'Europe/Moscow');
Loading history...
Bug introduced by
'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 ignore-type  annotation

37
        return new \DateTimeImmutable($this->getData('created'), /** @scrutinizer ignore-type */ 'Europe/Moscow');
Loading history...
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
Bug introduced by
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 ignore-type  annotation

57
        $media = $this->getData('media', /** @scrutinizer ignore-type */ []);
Loading history...
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
Bug Best Practice introduced by
The expression return $this->getData('text') ?? '' also could return the type array which is incompatible with the documented return type null|string.
Loading history...
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