Test Failed
Branch feature/fix-old-client (2ee070)
by Alexey
11:31
created

ClusterPagesFromClusterResponseScraper   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
eloc 13
c 1
b 0
f 0
dl 0
loc 27
rs 10

1 Method

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

36
        $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...
37
        $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

37
        $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...
38
39
        $results = [];
40
        foreach ($json[0][1] as $items) {
41
            $results[] = [
42
                'name' => $items[0][1],
43
                'url' => GPlayApps::GOOGLE_PLAY_URL . $items[0][3][4][2],
44
            ];
45
        }
46
        $token = $json[0][3][1] ?? null;
47
48
        return [
0 ignored issues
show
Bug Best Practice introduced by
The expression return array('results' =...lts, 'token' => $token) returns an array which contains values of type array|array<mixed,array<string,mixed|string>> which are incompatible with the documented value type string.
Loading history...
49
            'results' => $results,
50
            'token' => $token,
51
        ];
52
    }
53
}
54