Passed
Branch develop (2fd4b5)
by Alexey
01:46
created

Review::asArray()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

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

189
            '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...
190
            'timestamp' => $this->date->getTimestamp(),
191
            'score' => $this->score,
192
            'countLikes' => $this->countLikes,
193
            'reply' => $this->reply ? $this->reply->asArray() : null,
194
        ];
195
    }
196
}
197