GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

Data   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 16
c 1
b 0
f 0
dl 0
loc 54
ccs 14
cts 14
cp 1
rs 10
wmc 7

3 Methods

Rating   Name   Duplication   Size   Complexity  
A formatUrls() 0 8 2
A payload() 0 12 4
A googleApiUrl() 0 4 1
1
<?php
2
3
namespace RattfieldNz\SafeUrls\Libraries\Data;
4
5
use RattfieldNz\SafeUrls\Libraries\Config\Config;
6
7
/**
8
 * Class Data.
9
 *
10
 * @category PHP
11
 *
12
 * @author  Rob Attfield <[email protected]>
13
 * @license https://github.com/rattfieldnz/safe-urls/blob/master/license.md MIT
14
 *
15
 * @link https://github.com/rattfieldnz/safe-urls/
16
 */
17
class Data
18
{
19
    /**
20
     * Generate payload for Google Safe Browsing API.
21
     *
22
     * @param array $urls             List of URLS to add to payload for checking.
23
     * @param array $threatTypes      List of Google Threat Types.
24
     * @param array $platformTypes    List of Google Platform Types.
25
     * @param array $threatEntryTypes List of Google Threat Platform Types.
26
     *
27
     * @return array The generated payload.
28
     */
29 11
    public static function payload(array $urls, array $threatTypes = [], array $platformTypes = [], array $threatEntryTypes = []): array
30
    {
31
        return [
32
            'client' => [
33 11
                'clientId'      => Config::clientId(),
34 11
                'clientVersion' => Config::clientVersion(),
35
            ],
36
            'threatInfo' => [
37 11
                'threatTypes'      => !empty($threatTypes) ? $threatTypes : Config::threatTypes(),
38 11
                'platformTypes'    => !empty($platformTypes) ? $platformTypes : Config::platformTypes(),
39 11
                'threatEntryTypes' => !empty($threatEntryTypes) ? $threatEntryTypes : Config::threatEntryTypes(),
40 11
                'threatEntries'    => self::formatUrls($urls),
41
            ],
42
        ];
43
    }
44
45
    /**
46
     * Format URLS suitable for use with API.
47
     *
48
     * @param array $urls List of URLS to format.
49
     *
50
     * @return array The formatted URLs.
51
     */
52 14
    public static function formatUrls(array $urls): array
53
    {
54 14
        $formattedUrls = [];
55 14
        foreach ($urls as $url) {
56 12
            $formattedUrls[] = ['url' => $url];
57
        }
58
59 14
        return $formattedUrls;
60
    }
61
62
    /**
63
     * Get Google Safebrowing API URL with key.
64
     *
65
     * @return string
66
     */
67 8
    public static function googleApiUrl()
68
    {
69
        return 'https://safebrowsing.googleapis.com/v4/threatMatches:find?key='.
70 8
            Config::googleApiKey();
71
    }
72
}
73