PermissionScraper   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Test Coverage

Coverage 92.31%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
eloc 28
c 1
b 0
f 0
dl 0
loc 53
ccs 24
cts 26
cp 0.9231
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B __invoke() 0 44 6
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;
15
16
use Nelexa\GPlay\HttpClient\ParseHandlerInterface;
17
use Nelexa\GPlay\Model\GoogleImage;
18
use Nelexa\GPlay\Model\Permission;
19
use Psr\Http\Message\RequestInterface;
20
use Psr\Http\Message\ResponseInterface;
21
22
/**
23
 * @internal
24
 */
25
class PermissionScraper implements ParseHandlerInterface
26
{
27
    /**
28
     * @param RequestInterface  $request
29
     * @param ResponseInterface $response
30
     * @param array             $options
31
     *
32
     * @return Permission[]
33
     */
34 1
    public function __invoke(RequestInterface $request, ResponseInterface $response, array &$options = []): array
35
    {
36 1
        $contents = substr($response->getBody()->getContents(), 5);
37 1
        $json = \GuzzleHttp\json_decode($contents, true);
0 ignored issues
show
Deprecated Code introduced by
The function GuzzleHttp\json_decode() has been deprecated: json_decode will be removed in guzzlehttp/guzzle:8.0. Use Utils::jsonDecode instead. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

37
        $json = /** @scrutinizer ignore-deprecated */ \GuzzleHttp\json_decode($contents, true);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
38 1
        $data = \GuzzleHttp\json_decode($json[0][2], true);
0 ignored issues
show
Deprecated Code introduced by
The function GuzzleHttp\json_decode() has been deprecated: json_decode will be removed in guzzlehttp/guzzle:8.0. Use Utils::jsonDecode instead. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

38
        $data = /** @scrutinizer ignore-deprecated */ \GuzzleHttp\json_decode($json[0][2], true);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
39
40 1
        $permissionMapFn = static function (array $v): string {
41 1
            return (string) $v[1];
42
        };
43
44 1
        $permissions = [];
45
46 1
        foreach (\array_slice($data, 0, 2) as $items) {
47 1
            if ($items === null) {
48
                continue;
49
            }
50
51 1
            foreach ($items as $values) {
52 1
                if (empty($values)) {
53
                    continue;
54
                }
55 1
                $permissionName = $values[0];
56 1
                $permissions[$permissionName] = [
57
                    'name' => $permissionName,
58 1
                    'icon' => new GoogleImage($values[1][3][2]),
59 1
                    'permissions' => array_map($permissionMapFn, $values[2]),
60
                ];
61
            }
62
        }
63
64 1
        if (isset($data[2])) {
65 1
            end($permissions);
66 1
            $lastKey = key($permissions);
67 1
            $permissions[$lastKey]['permissions'] = array_merge(
68 1
                array_map($permissionMapFn, $data[2]),
69 1
                $permissions[$lastKey]['permissions']
70
            );
71
        }
72
73 1
        return array_map(
74 1
            static function (array $data) {
75 1
                return new Permission($data['name'], $data['icon'], $data['permissions']);
76
            },
77
            $permissions
78
        );
79
    }
80
}
81