Passed
Push — master ( bb114b...6dc021 )
by Alexey
03:23 queued 10s
created

ClusterAppsScraper   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Test Coverage

Coverage 93.75%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
eloc 16
dl 0
loc 37
ccs 15
cts 16
cp 0.9375
rs 10
c 1
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 29 6
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\Scraper;
13
14
use Nelexa\GPlay\GPlayApps;
15
use Nelexa\GPlay\Scraper\Extractor\AppsExtractor;
16
use Nelexa\GPlay\Util\ScraperUtil;
17
use Nelexa\HttpClient\ResponseHandlerInterface;
18
use Psr\Http\Message\RequestInterface;
19
use Psr\Http\Message\ResponseInterface;
20
use function GuzzleHttp\Psr7\parse_query;
21
22
/**
23
 * @internal
24
 */
25
class ClusterAppsScraper implements ResponseHandlerInterface
26
{
27
    /**
28
     * @param RequestInterface  $request
29
     * @param ResponseInterface $response
30
     *
31
     * @return array
32
     */
33 16
    public function __invoke(RequestInterface $request, ResponseInterface $response): array
34
    {
35 16
        $scriptData = ScraperUtil::extractScriptData($response->getBody()->getContents());
36 16
        $scriptDataInfo = null;
37
38 16
        foreach ($scriptData as $scriptValue) {
39 16
            if (isset($scriptValue[0][1][0][0][0]) && \is_array($scriptValue[0][1][0][0][0])) {
40 16
                $scriptDataInfo = $scriptValue; // ds:3
41
                break;
42
            }
43
        }
44
45 16
        if ($scriptDataInfo === null) {
46
            return [[], null];
47
        }
48
49 16
        $query = parse_query($request->getUri()->getQuery());
0 ignored issues
show
Deprecated Code introduced by
The function GuzzleHttp\Psr7\parse_query() has been deprecated: parse_query will be removed in guzzlehttp/psr7:2.0. Use Query::parse instead. ( Ignorable by Annotation )

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

49
        $query = /** @scrutinizer ignore-deprecated */ parse_query($request->getUri()->getQuery());

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...
50 16
        $locale = $query[GPlayApps::REQ_PARAM_LOCALE] ?? GPlayApps::DEFAULT_LOCALE;
51 16
        $country = $query[GPlayApps::REQ_PARAM_COUNTRY] ?? GPlayApps::DEFAULT_COUNTRY;
52
53 16
        $apps = [];
54
55 16
        foreach ($scriptDataInfo[0][1][0][0][0] as $data) {
56 16
            $apps[] = AppsExtractor::extractApp($data, $locale, $country);
57
        }
58
59 16
        $nextToken = $scriptDataInfo[0][1][0][0][7][1] ?? null;
60
61 16
        return [$apps, $nextToken];
62
    }
63
}
64