Test Failed
Branch develop (c8bc8f)
by Alexey
08:48
created

ClusterAppsScraper   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 33
Duplicated Lines 9.09 %

Coupling/Cohesion

Components 0
Dependencies 6

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 6
dl 3
loc 33
c 0
b 0
f 0
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B __invoke() 3 25 6

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
declare(strict_types=1);
3
4
namespace Nelexa\GPlay\Scraper;
5
6
use Nelexa\GPlay\GPlayApps;
7
use Nelexa\GPlay\Http\ResponseHandlerInterface;
8
use Nelexa\GPlay\Scraper\Extractor\AppsExtractor;
9
use Nelexa\GPlay\Util\ScraperUtil;
10
use Psr\Http\Message\RequestInterface;
11
use Psr\Http\Message\ResponseInterface;
12
use function GuzzleHttp\Psr7\parse_query;
13
14
class ClusterAppsScraper implements ResponseHandlerInterface
15
{
16
    /**
17
     * @param RequestInterface $request
18
     * @param ResponseInterface $response
19
     * @return array
20
     */
21
    public function __invoke(RequestInterface $request, ResponseInterface $response): array
22
    {
23
        $scriptData = ScraperUtil::extractScriptData($response->getBody()->getContents());
24
        $scriptDataInfo = null;
25
        foreach ($scriptData as $scriptValue) {
26
            if (isset($scriptValue[0][1][0][0][0]) && is_array($scriptValue[0][1][0][0][0])) {
27
                $scriptDataInfo = $scriptValue; // ds:3
28
                break;
29
            }
30
        }
31
32
        if ($scriptDataInfo === null) {
33
            return [[], null];
34
        }
35
36
        $locale = parse_query($request->getUri()->getQuery())[GPlayApps::REQ_PARAM_LOCALE] ?? GPlayApps::DEFAULT_LOCALE;
37
38
        $apps = [];
39 View Code Duplication
        foreach ($scriptDataInfo[0][1][0][0][0] as $data) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
40
            $apps[] = AppsExtractor::extractApp($data, $locale);
41
        }
42
43
        $nextToken = $scriptDataInfo[0][1][0][0][7][1] ?? null;
44
        return [$apps, $nextToken];
45
    }
46
}
47