Passed
Push — master ( 0efe7a...946c43 )
by Roberto
01:43
created

Node::getIpV6()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 10
c 0
b 0
f 0
rs 10
cc 1
nc 1
nop 0
1
<?php
2
/**
3
 * Copyright (c) 2019 - present
4
 * updown - Node.php
5
 * author: Roberto Belotti - [email protected]
6
 * web : robertobelotti.com, github.com/biscolab
7
 * Initial version created on: 18/2/2019
8
 * MIT license: https://github.com/biscolab/updown-php/blob/master/LICENSE
9
 */
10
11
namespace Biscolab\UpDown\Objects;
12
13
use Biscolab\UpDown\Abstracts\AbstractCollection;
14
use Biscolab\UpDown\Enum\UpDownFieldType;
15
use Biscolab\UpDown\Fields\NodeFields;
16
use Biscolab\UpDown\Http\UpDownResponse;
17
use Biscolab\UpDown\Types\Nodes;
18
19
/**
20
 * Class Node
21
 * @property string name
22
 * @property string ip
23
 * @property string ip6
24
 * @property string city
25
 * @property string country
26
 * @property string country_code
27
 * @property float  lat
28
 * @property float  lng
29
 * @package Biscolab\UpDown\Object
30
 */
31
class Node extends BaseObject
32
{
33
34
    /**
35
     * @var string
36
     */
37
    protected static $endpoint = 'nodes';
38
39
    /**
40
     * @var string
41
     */
42
    protected static $collection_type = Nodes::class;
43
44
    /**
45
     * @var string
46
     */
47
    protected static $key = NodeFields::NAME;
48
49
    /**
50
     * @var array
51
     */
52
    protected $typeCheck = [
53
        NodeFields::NAME         => UpDownFieldType::STRING,
54
        NodeFields::IP           => UpDownFieldType::STRING,
55
        NodeFields::IP6          => UpDownFieldType::STRING,
56
        NodeFields::CITY         => UpDownFieldType::STRING,
57
        NodeFields::COUNTRY      => UpDownFieldType::STRING,
58
        NodeFields::COUNTRY_CODE => UpDownFieldType::STRING,
59
        NodeFields::LAT          => UpDownFieldType::FLOAT,
60
        NodeFields::LNG          => UpDownFieldType::FLOAT
61
    ];
62
63
    /**
64
     * @return array
65
     */
66
    public function getIpV4(): array
67
    {
68
69
        $path = $this->prepareApiPath() . '/ipv4';
70
71
        $response = $this->updown->get($path);
0 ignored issues
show
Bug introduced by Roberto
The method get() does not exist on null. ( Ignorable by Annotation )

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

71
        /** @scrutinizer ignore-call */ 
72
        $response = $this->updown->get($path);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
72
73
        $data = $response->getResult()->getData();
74
75
        return $data;
76
    }
77
78
    /**
79
     * @return array
80
     */
81
    public function getIpV6(): array
82
    {
83
84
        $path = $this->prepareApiPath() . '/ipv6';
85
86
        $response = $this->updown->get($path);
87
88
        $data = $response->getResult()->getData();
89
90
        return $data;
91
    }
92
93
    /**
94
     * @param UpDownResponse $response
95
     *
96
     * @return mixed
97
     */
98
    protected function getCollection(UpDownResponse $response): AbstractCollection
99
    {
100
101
        $data = [];
102
103
        $result = $response->getResult()->getData();
104
105
        foreach ($result as $k => $v) {
106
107
            $node_data = array_merge($v, [
108
                NodeFields::NAME => $k
109
            ]);
110
            array_push($data, $node_data);
111
        }
112
113
        $collection_type = static::$collection_type;
114
115
        return new $collection_type($response->getResult()->getData());
116
    }
117
118
}