Passed
Push — master ( 81593c...33129c )
by Alexey
10:12 queued 12s
created

AppsExtractor::extractSummary()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2.0625

Importance

Changes 0
Metric Value
eloc 3
c 0
b 0
f 0
dl 0
loc 5
ccs 3
cts 4
cp 0.75
rs 10
cc 2
nc 2
nop 1
crap 2.0625
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\Extractor;
15
16
use Nelexa\GPlay\Model\App;
17
use Nelexa\GPlay\Model\GoogleImage;
18
use Nelexa\GPlay\Util\ScraperUtil;
19
20
/**
21
 * @internal
22
 */
23
class AppsExtractor
24
{
25
    /**
26
     * @param array  $data
27
     * @param string $locale
28
     * @param string $country
29
     *
30
     * @return App
31
     */
32 21
    public static function extractApp(array $data, string $locale, string $country): App
33
    {
34 21
        $name = $data[3];
35 21
        $appId = $data[0][0];
36 21
        $icon = new GoogleImage($data[1][3][2]);
37 21
        $developerName = $data[14];
38 21
        $installsText = $data[15];
39 21
        $priceText = null;
40 21
        if (isset($data[8][1][0][0], $data[8][1][0][2]) && $data[8][1][0][0] > 0) {
41 15
            $priceText = $data[8][1][0][2];
42
        }
43 21
        $score = $data[4][1] ?? 0.0;
44 21
        $screenshots = array_map(static function (array $item) {
45 21
            return new GoogleImage($item[3][2]);
46 21
        }, $data[2]);
47 21
        $description = ScraperUtil::html2text($data[13][1] ?? '');
48 21
        $cover = null;
49 21
        if (isset($data[22][3][2])) {
50 21
            $cover = new GoogleImage($data[22][3][2]);
51
        } elseif (isset($data[100][1][0][3][2])) {
52
            $cover = new GoogleImage($data[100][1][0][3][2]);
53
        }
54
//        $categoryName = $data[0][5];
55
56 21
        return App::newBuilder()
57 21
            ->setId($appId)
58 21
            ->setLocale($locale)
59 21
            ->setCountry($country)
60 21
            ->setName($name)
61 21
            ->setDeveloperName($developerName)
62 21
            ->setCover($cover)
63 21
            ->setIcon($icon)
64 21
            ->setInstallsText($installsText)
65 21
            ->setScore($score)
66 21
            ->setPriceText($priceText)
67 21
            ->setScreenshots($screenshots)
68 21
            ->setDescription($description)
69 21
            ->build()
70
        ;
71
    }
72
}
73