GameTag   A
last analyzed

Complexity

Total Complexity 16

Size/Duplication

Total Lines 84
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 30
dl 0
loc 84
ccs 25
cts 25
cp 1
rs 10
c 1
b 0
f 0
wmc 16

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getAllData() 0 18 4
F build() 0 22 11
A init() 0 4 1
1
<?php
2
3
namespace Pamo\GameTag;
4
5
use Pamo\MultiCurl\MultiCurl;
6
7
/**
8
 * GameTag
9
 * @SuppressWarnings(PHPMD.CyclomaticComplexity)
10
 * @SuppressWarnings(PHPMD.NPathComplexity)
11
 */
12
class GameTag
13
{
14
    /**
15
     * @var object $multiCurl tool.
16
     * @var string $baseAddress for the API.
17
     */
18
    private $multiCurl;
19
    private $baseAddress;
20
21
22
23
    /**
24
     * GameTag a tag
25
     *
26
     * @param string $baseAddress for the API.
27
     * @param string $apiKey for authentication.
28
     *
29
     */
30 1
    public function init()
31
    {
32 1
        $this->multiCurl = new MultiCurl();
33 1
        $this->baseAddress = "https://api.rawg.io";
34 1
    }
35
36
37
38
    /**
39
     * Return the API Data
40
     *
41
     * @param string $ipAddress is the IP Address to validate.
42
     *
43
     * @return array
44
     */
45 1
    public function getAllData(string $params) : array
46
    {
47 1
        $url = ["$this->baseAddress" . "$params"];
48
        $header = [
49 1
            "Content-Type: application/json",
50
            "charset=utf-8",
51
            "User-Agent=GameOverflow"
52
        ];
53
54 1
        $data = $this->multiCurl->get($url, $header);
55
56 1
        if ($data && !empty($data[0]["results"])) {
57 1
            $buildData = $this->build($data[0]);
58
        }
59
60 1
        $result = isset($buildData) ? $buildData : [];
61
62 1
        return $result;
63
    }
64
65
66
67
    /**
68
     * Return the organized API Data
69
     *
70
     * @param array $data from the IP.
71
     *
72
     * @return array
73
     */
74 1
    private function build(array $data) : array
75
    {
76
        $buildData = [
77 1
            "next" => isset($data["next"]) ? $data["next"] : null,
78 1
            "previous" => isset($data["previous"]) ? $data["previous"] : null,
79
            "results" => []
80
        ];
81
82 1
        foreach ($data["results"] as $row) {
83
            $result = [
84 1
                "name" => empty($row["name"]) ? null: $row["name"],
85 1
                "parents" => empty($row["parent_platforms"]) ? null : $row["parent_platforms"],
86 1
                "platforms" => empty($row["platforms"]) ? null : $row["platforms"],
87 1
                "released" => empty($row["released"]) ? null : $row["released"],
88 1
                "image" => empty($row["background_image"]) ? null : $row["background_image"],
89 1
                "video" => empty($row["clip"]["clip"]) ? null : $row["clip"]["clip"],
90 1
                "genres" => empty($row["genres"]) ? null : $row["genres"]
91
            ];
92 1
            array_push($buildData["results"], $result);
93
        }
94
95 1
        return $buildData;
96
    }
97
}
98