Completed
Push — master ( 45165d...5e44c4 )
by Alexey
04:08 queued 11s
created

FindSimilarAppsUrlScraper   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Test Coverage

Coverage 90.91%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 11
c 1
b 0
f 0
dl 0
loc 35
ccs 10
cts 11
cp 0.9091
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A __invoke() 0 14 3
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\AppId;
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 FindSimilarAppsUrlScraper implements ResponseHandlerInterface
25
{
26
    /** @var AppId */
27
    private $appId;
28
29
    /**
30
     * SimilarScraper constructor.
31
     *
32
     * @param AppId $appId
33
     */
34 1
    public function __construct(AppId $appId)
35
    {
36 1
        $this->appId = $appId;
37 1
    }
38
39
    /**
40
     * @param RequestInterface  $request
41
     * @param ResponseInterface $response
42
     *
43
     * @return string|null
44
     */
45 1
    public function __invoke(RequestInterface $request, ResponseInterface $response): ?string
46
    {
47 1
        $scriptData = ScraperUtil::extractScriptData($response->getBody()->getContents());
48
49 1
        foreach ($scriptData as $key => $scriptValue) {
50 1
            if (isset($scriptValue[1][1][0][0][3][4][2])) {
51 1
                return GPlayApps::GOOGLE_PLAY_URL . $scriptValue[1][1][0][0][3][4][2] .
52 1
                    '&' . GPlayApps::REQ_PARAM_LOCALE . '=' . urlencode($this->appId->getLocale()) .
53 1
                    '&' . GPlayApps::REQ_PARAM_COUNTRY . '=' . urlencode($this->appId->getCountry());
54
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
55
            }
56
        }
57
58
        return null;
59
    }
60
}
61