Total Complexity | 7 |
Total Lines | 57 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
12 | class ReviewsExtractor |
||
13 | { |
||
14 | /** |
||
15 | * @param RequestApp $requestApp |
||
16 | * @param array $data |
||
17 | * @return array |
||
18 | */ |
||
19 | public static function extractReviews(RequestApp $requestApp, array $data): array |
||
20 | { |
||
21 | $reviews = []; |
||
22 | foreach ($data as $reviewData) { |
||
23 | $reviewId = $reviewData[0]; |
||
24 | $reviewUrl = $requestApp->getUrl() . '&reviewId=' . urlencode($reviewId); |
||
25 | $userName = $reviewData[1][0]; |
||
26 | $avatar = new GoogleImage($reviewData[1][1][3][2]); |
||
27 | $date = null; |
||
28 | if (isset($reviewData[5][0])) { |
||
29 | $date = DateStringFormatter::unixTimeToDateTime($reviewData[5][0]); |
||
30 | } |
||
31 | $score = $reviewData[2] ?? 0; |
||
32 | $text = (string)($reviewData[4] ?? ''); |
||
33 | $likeCount = $reviewData[6]; |
||
34 | |||
35 | $reply = self::extractReplyReview($reviewData); |
||
36 | |||
37 | $reviews[] = new Review( |
||
38 | $reviewId, |
||
39 | $reviewUrl, |
||
40 | $userName, |
||
41 | $text, |
||
42 | $avatar, |
||
43 | $date, |
||
44 | $score, |
||
45 | $likeCount, |
||
46 | $reply |
||
47 | ); |
||
48 | } |
||
49 | return $reviews; |
||
50 | } |
||
51 | |||
52 | /** |
||
53 | * @param array $reviewData |
||
54 | * @return ReplyReview|null |
||
55 | */ |
||
56 | private static function extractReplyReview(array $reviewData): ?ReplyReview |
||
69 | } |
||
70 | } |
||
71 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)
or! empty(...)
instead.