Passed
Branch feature/refactoring (13cbf0)
by Alexey
03:46
created

Review   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 174
Duplicated Lines 0 %

Test Coverage

Coverage 32.5%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 12
eloc 40
c 1
b 0
f 0
dl 0
loc 174
ccs 13
cts 40
cp 0.325
rs 10

11 Methods

Rating   Name   Duplication   Size   Complexity  
A getId() 0 3 1
A getText() 0 3 1
A asArray() 0 13 2
A getReply() 0 3 1
A getUserName() 0 3 1
A getAvatar() 0 3 1
A getScore() 0 3 1
A __construct() 0 20 1
A getCountLikes() 0 3 1
A getDate() 0 3 1
A getUrl() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * @author   Ne-Lexa
7
 * @license  MIT
8
 *
9
 * @see      https://github.com/Ne-Lexa/google-play-scraper
10
 */
11
12
namespace Nelexa\GPlay\Model;
13
14
use Nelexa\GPlay\GPlayApps;
15
16
/**
17
 * Contains review of application on Google Play store.
18
 *
19
 * @see GPlayApps::getReviews() Returns reviews of the Android app
20
 *     in the Google Play store.
21
 * @see GPlayApps::getAppsInfo() Returns detailed information about many
22
 *     android packages.
23
 */
24
class Review implements \JsonSerializable
25
{
26
    use JsonSerializableTrait;
27
28
    /** @var string review id */
29
    private $id;
30
31
    /** @var string review url */
32
    private $url;
33
34
    /** @var string review author */
35
    private $userName;
36
37
    /** @var string review text */
38
    private $text;
39
40
    /** @var GoogleImage author's avatar */
41
    private $avatar;
42
43
    /** @var \DateTimeInterface|null review date */
44
    private $date;
45
46
    /** @var int review score */
47
    private $score;
48
49
    /** @var int the number of likes reviews */
50
    private $countLikes;
51
52
    /** @var ReplyReview|null reply review */
53
    private $reply;
54
55
    /**
56
     * Creates an Android app review object in the Google Play store.
57
     *
58
     * @param string                  $id        review id
59
     * @param string                  $url       review url
60
     * @param string                  $userName  review author
61
     * @param string                  $text      review text
62
     * @param GoogleImage             $avatar    author's avatar
63
     * @param \DateTimeInterface|null $date      review date
64
     * @param int                     $score     review score
65
     * @param int                     $likeCount the number of likes reviews
66
     * @param ReplyReview|null        $reply     reply review
67
     */
68 20
    public function __construct(
69
        string $id,
70
        string $url,
71
        string $userName,
72
        string $text,
73
        GoogleImage $avatar,
74
        ?\DateTimeInterface $date,
75
        int $score,
76
        int $likeCount = 0,
77
        ?ReplyReview $reply = null
78
    ) {
79 20
        $this->id = $id;
80 20
        $this->url = $url;
81 20
        $this->userName = $userName;
82 20
        $this->text = $text;
83 20
        $this->avatar = $avatar;
84 20
        $this->date = $date;
85 20
        $this->score = $score;
86 20
        $this->countLikes = $likeCount;
87 20
        $this->reply = $reply;
88 20
    }
89
90
    /**
91
     * Returns review id.
92
     *
93
     * @return string review id
94
     */
95 1
    public function getId(): string
96
    {
97 1
        return $this->id;
98
    }
99
100
    /**
101
     * Returns a review url.
102
     *
103
     * @return string review url
104
     */
105
    public function getUrl(): string
106
    {
107
        return $this->url;
108
    }
109
110
    /**
111
     * Returns the username of the review author.
112
     *
113
     * @return string author's username
114
     */
115
    public function getUserName(): string
116
    {
117
        return $this->userName;
118
    }
119
120
    /**
121
     * Returns the text of the review.
122
     *
123
     * @return string review text
124
     */
125
    public function getText(): string
126
    {
127
        return $this->text;
128
    }
129
130
    /**
131
     * Returns the user's avatar.
132
     *
133
     * @return GoogleImage author's avatar
134
     */
135
    public function getAvatar(): GoogleImage
136
    {
137
        return $this->avatar;
138
    }
139
140
    /**
141
     * Returns the date of the review.
142
     *
143
     * @return \DateTimeInterface|null date of the review or null if not provided
144
     */
145
    public function getDate(): ?\DateTimeInterface
146
    {
147
        return $this->date;
148
    }
149
150
    /**
151
     * Returns a review rating.
152
     *
153
     * @return int review score
154
     */
155
    public function getScore(): int
156
    {
157
        return $this->score;
158
    }
159
160
    /**
161
     * Returns the count of likes of the review.
162
     *
163
     * @return int the number of likes reviews
164
     */
165
    public function getCountLikes(): int
166
    {
167
        return $this->countLikes;
168
    }
169
170
    /**
171
     * Returns a reply of the review.
172
     *
173
     * @return ReplyReview|null response to a review or null if not provided
174
     */
175
    public function getReply(): ?ReplyReview
176
    {
177
        return $this->reply;
178
    }
179
180
    /**
181
     * Returns class properties as an array.
182
     *
183
     * @return array class properties as an array
184
     */
185
    public function asArray(): array
186
    {
187
        return [
188
            'id' => $this->id,
189
            'url' => $this->url,
190
            'userName' => $this->userName,
191
            'text' => $this->text,
192
            'avatar' => $this->avatar->getUrl(),
193
            'date' => $this->date->format(\DateTimeInterface::RFC3339),
0 ignored issues
show
Bug introduced by
The method format() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

193
            'date' => $this->date->/** @scrutinizer ignore-call */ format(\DateTimeInterface::RFC3339),

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
194
            'timestamp' => $this->date->getTimestamp(),
195
            'score' => $this->score,
196
            'countLikes' => $this->countLikes,
197
            'reply' => $this->reply ? $this->reply->asArray() : null,
198
        ];
199
    }
200
}
201