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

FindSimilarAppsUrlScraper::__invoke()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 3.0123

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 14
ccs 8
cts 9
cp 0.8889
rs 10
cc 3
nc 3
nop 2
crap 3.0123
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 1
                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