Passed
Push — master ( dcb648...5ad5c1 )
by Alexey
03:43 queued 16s
created

PlayStoreUiAppsScraper   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Test Coverage

Coverage 93.33%

Importance

Changes 2
Bugs 1 Features 0
Metric Value
wmc 3
eloc 15
c 2
b 1
f 0
dl 0
loc 33
ccs 14
cts 15
cp 0.9333
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 24 3
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 GuzzleHttp\Psr7\Query;
17
use Nelexa\GPlay\GPlayApps;
18
use Nelexa\GPlay\HttpClient\ParseHandlerInterface;
19
use Nelexa\GPlay\Scraper\Extractor\AppsExtractor;
20
use Psr\Http\Message\RequestInterface;
21
use Psr\Http\Message\ResponseInterface;
22
23
/**
24
 * @internal
25
 */
26
class PlayStoreUiAppsScraper implements ParseHandlerInterface
27
{
28
    /**
29
     * @param RequestInterface  $request
30
     * @param ResponseInterface $response
31
     * @param array             $options
32
     *
33
     * @return array
34
     */
35 6
    public function __invoke(RequestInterface $request, ResponseInterface $response, array &$options = []): array
36
    {
37 6
        $contents = substr($response->getBody()->getContents(), 5);
38 6
        $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

38
        $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...
39
40 6
        if (empty($json[0][2])) {
41 2
            return [[], null];
42
        }
43 6
        $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

43
        $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...
44
45 6
        $json = $json[0][22] ?? $json[0][21];
46 6
        if (empty($json)) {
47
            return [[], null];
48
        }
49
50 6
        $query = Query::parse($request->getUri()->getQuery());
51 6
        $locale = $query[GPlayApps::REQ_PARAM_LOCALE] ?? GPlayApps::DEFAULT_LOCALE;
52 6
        $country = $query[GPlayApps::REQ_PARAM_COUNTRY] ?? GPlayApps::DEFAULT_COUNTRY;
53
54 6
        $apps = AppsExtractor::extractApps($json[0], $locale, $country);
55
56 6
        $nextToken = $json[1][3][1] ?? null;
57
58 6
        return [$apps, $nextToken];
59
    }
60
}
61