ReviewsScraper::__invoke()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 17
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 3.054

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 17
ccs 9
cts 11
cp 0.8182
rs 9.9332
cc 3
nc 3
nop 3
crap 3.054
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * Copyright (c) Ne-Lexa
7
 *
8
 * For the full copyright and license information, please view
9
 * the LICENSE file that was distributed with this source code.
10
 *
11
 * @see https://github.com/Ne-Lexa/google-play-scraper
12
 */
13
14
namespace Nelexa\GPlay\Scraper;
15
16
use Nelexa\GPlay\HttpClient\ParseHandlerInterface;
17
use Nelexa\GPlay\Model\AppId;
18
use Nelexa\GPlay\Scraper\Extractor\ReviewsExtractor;
19
use Psr\Http\Message\RequestInterface;
20
use Psr\Http\Message\ResponseInterface;
21
22
/**
23
 * @internal
24
 */
25
class ReviewsScraper implements ParseHandlerInterface
26
{
27
    /** @var AppId */
28
    private $requestApp;
29
30
    /**
31
     * ReviewsScraper constructor.
32
     *
33
     * @param AppId $requestApp
34
     */
35 1
    public function __construct(AppId $requestApp)
36
    {
37 1
        $this->requestApp = $requestApp;
38
    }
39
40
    /**
41
     * @param RequestInterface  $request
42
     * @param ResponseInterface $response
43
     * @param array             $options
44
     *
45
     * @return array
46
     */
47 1
    public function __invoke(RequestInterface $request, ResponseInterface $response, array &$options = []): array
48
    {
49 1
        $contents = substr($response->getBody()->getContents(), 5);
50 1
        $json = \GuzzleHttp\json_decode($contents, true);
0 ignored issues
show
Deprecated Code introduced by
The function GuzzleHttp\json_decode() has been deprecated: json_decode will be removed in guzzlehttp/guzzle:8.0. Use Utils::jsonDecode instead. ( Ignorable by Annotation )

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

50
        $json = /** @scrutinizer ignore-deprecated */ \GuzzleHttp\json_decode($contents, true);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
51
52 1
        if (!isset($json[0][2])) {
53
            return [[], null];
54
        }
55 1
        $json = \GuzzleHttp\json_decode($json[0][2], true);
0 ignored issues
show
Deprecated Code introduced by
The function GuzzleHttp\json_decode() has been deprecated: json_decode will be removed in guzzlehttp/guzzle:8.0. Use Utils::jsonDecode instead. ( Ignorable by Annotation )

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

55
        $json = /** @scrutinizer ignore-deprecated */ \GuzzleHttp\json_decode($json[0][2], true);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
56
57 1
        if (empty($json[0])) {
58
            return [[], null];
59
        }
60 1
        $reviews = ReviewsExtractor::extractReviews($this->requestApp, $json[0]);
61 1
        $nextToken = $json[1][1] ?? null;
62
63 1
        return [$reviews, $nextToken];
64
    }
65
}
66