Passed
Push — master ( 1e7e1e...fa42da )
by Kris
01:37
created

ApiResponse   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 6
c 1
b 0
f 0
dl 0
loc 55
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getObject() 0 3 1
A __construct() 0 3 1
A getPlaintext() 0 3 1
A getArray() 0 3 1
1
<?php declare(strict_types=1);
2
3
/**
4
 *     _    _                    ___ ____  ____  ____
5
 *    / \  | |__  _   _ ___  ___|_ _|  _ \|  _ \| __ )
6
 *   / _ \ | '_ \| | | / __|/ _ \| || |_) | | | |  _ \
7
 *  / ___ \| |_) | |_| \__ \  __/| ||  __/| |_| | |_) |
8
 * /_/   \_\_.__/ \__,_|___/\___|___|_|   |____/|____/
9
 *
10
 * This file is part of Kristuff\AbsuseIPDB.
11
 *
12
 * (c) Kristuff <[email protected]>
13
 *
14
 * For the full copyright and license information, please view the LICENSE
15
 * file that was distributed with this source code.
16
 *
17
 * @version    0.9.8
18
 * @copyright  2020-2021 Kristuff
19
 */
20
21
namespace Kristuff\AbuseIPDB;
22
23
/**
24
 * Class ApiResponse
25
 * 
26
 */
27
class ApiResponse
28
{
29
    /**
30
     * 
31
     * @access protected
32
     * @var string 
33
     */
34
    protected $curlResponse; 
35
36
    /**
37
     * Constructor
38
     * 
39
     * @access public
40
     * @param string     $plaintext      AbuseIPDB response in plaintext 
41
     * 
42
     */
43
    public function __construct(?string $plaintext = null)
44
    {
45
        $this->curlResponse = $plaintext;
46
    }
47
48
    /**
49
     * Get response as array. May return null
50
     * 
51
     * @access public
52
     * 
53
     * @return array|null
54
     */
55
    public function getArray(): ?array
56
    {
57
        return json_decode($this->curlResponse, true);
58
    }
59
60
    /**
61
     * Get response as object. May return null
62
     * 
63
     * @access public
64
     * 
65
     * @return object|null
66
     */
67
    public function getObject(): ?object
68
    {
69
        return json_decode($this->curlResponse, false);
70
    }
71
72
    /**
73
     * Get response as plaintext. May return null
74
     * 
75
     * @access public
76
     * 
77
     * @return string|null
78
     */
79
    public function getPlaintext(): ?string
80
    {
81
        return $this->curlResponse;
82
    }
83
}