Passed
Branch feature/refactoring (13cbf0)
by Alexey
03:46
created

ClusterPagesFromListAppsScraper   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
eloc 12
c 0
b 0
f 0
dl 0
loc 29
ccs 12
cts 12
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 21 5
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\Model\App;
16
use Nelexa\GPlay\Util\ScraperUtil;
17
use Nelexa\HttpClient\ResponseHandlerInterface;
18
use Psr\Http\Message\RequestInterface;
19
use Psr\Http\Message\ResponseInterface;
20
21
/**
22
 * @internal
23
 */
24
class ClusterPagesFromListAppsScraper implements ResponseHandlerInterface
25
{
26
    /**
27
     * @param RequestInterface  $request
28
     * @param ResponseInterface $response
29
     *
30
     * @return App[]
31
     */
32 34
    public function __invoke(RequestInterface $request, ResponseInterface $response)
33
    {
34 34
        $scriptData = ScraperUtil::extractScriptData($response->getBody()->getContents());
35
36 34
        $results = [];
37
38 34
        foreach ($scriptData as $k => $v) {
39 34
            if (isset($v[0][1][0][0][1], $v[0][1][0][0][3][4][2])) {
40 30
                foreach ($v[0][1] as $a) {
41 30
                    if (isset($a[0][1], $a[0][3][4][2])) {
42 30
                        $results[] = [
43 30
                            'name' => trim($a[0][1]),
44 30
                            'url' => GPlayApps::GOOGLE_PLAY_URL . $a[0][3][4][2],
45
                        ];
46
                    }
47
                }
48 34
                break;
49
            }
50
        }
51
52 34
        return $results;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $results returns an array which contains values of type array<string,string> which are incompatible with the documented value type Nelexa\GPlay\Model\App.
Loading history...
53
    }
54
}
55