Passed
Push — master ( 3c5c71...77c285 )
by Kris
02:07
created

QuietApiHandler::bulkReport()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
dl 0
loc 6
rs 10
c 1
b 0
f 0
cc 2
nc 2
nop 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.10
18
 * @copyright  2020-2021 Kristuff
19
 */
20
21
namespace Kristuff\AbuseIPDB;
22
23
/**
24
 * Class QuietApiHandler
25
 * 
26
 * Overwrite ApiHandler with Exception handling
27
 * Instead of Exception, all methods return an ApiResponse that may 
28
 * contains errors from the AbuseIPDB API, or internal errors  
29
 */
30
class QuietApiHandler extends ApiHandler
31
{
32
    /**
33
     * Performs a 'report' api request, with Exception handling
34
     * 
35
     * @access public
36
     * @param string    $ip             The ip to report
37
     * @param string    $categories     The report category(es)
38
     * @param string    $message        The report message
39
     *
40
     * @return ApiResponse
41
     */
42
    public function report(string $ip, string $categories, string $message): ApiResponse
43
    {
44
        try {
45
            return parent::report($ip,$categories,$message);
46
        } catch (\Exception $e) {
47
            return ApiResponse::createErrorResponse($e->getMessage());
48
        }
49
    }
50
51
    /**
52
     * Performs a 'bulk-report' api request, with Exception handling
53
     * 
54
     * @access public
55
     * @param string    $filePath       The CSV file path. Could be an absolute or relative path.
56
     *
57
     * @return ApiResponse
58
     */
59
    public function bulkReport(string $filePath): ApiResponse
60
    {
61
        try {
62
            return parent::bulkReport($filePath);
63
        } catch (\Exception $e) {
64
            return ApiResponse::createErrorResponse($e->getMessage());
65
        }
66
    }
67
68
    /**
69
     * Perform a 'clear-address' api request, with Exception handling
70
     * 
71
     * @access public
72
     * @param string    $ip             The IP to clear reports
73
     * 
74
     * @return ApiResponse
75
     */
76
    public function clearAddress(string $ip): ApiResponse
77
    {
78
        try {
79
            return parent::clearAddress($ip);
80
        } catch (\Exception $e) {
81
            return ApiResponse::createErrorResponse($e->getMessage());
82
        }
83
    }
84
85
    /**
86
     * Perform a 'check' api request, with Exception handling
87
     * 
88
     * @access public
89
     * @param string    $ip             The ip to check
90
     * @param int       $maxAgeInDays   Max age in days. Default is 30.
91
     * @param bool      $verbose        True to get the full response (last reports and countryName). Default is false
92
     * 
93
     * @return ApiResponse
94
     */
95
    public function check(string $ip, int $maxAgeInDays = 30, bool $verbose = false): ApiResponse
96
    {
97
        try {
98
            return parent::check($ip, $maxAgeInDays, $verbose);
99
        } catch (\Exception $e) {
100
            return ApiResponse::createErrorResponse($e->getMessage());
101
        }
102
    }
103
104
    /**
105
     * Perform a 'check-block' api request, with Exception handling
106
     * 
107
     * @access public
108
     * @param string    $network        The network to check
109
     * @param int       $maxAgeInDays   The Max age in days, must 
110
     * 
111
     * @return ApiResponse
112
     */
113
    public function checkBlock(string $network, int $maxAgeInDays = 30): ApiResponse
114
    {
115
        try {
116
            return parent::checkBlock($network, $maxAgeInDays);
117
        } catch (\Exception $e) {
118
            return ApiResponse::createErrorResponse($e->getMessage());
119
        }
120
    }
121
122
    /**
123
     * Perform a 'blacklist' api request, with Exception handling
124
     * 
125
     * @access public
126
     * @param int       $limit              The blacklist limit. Default is 10000 (the api default limit) 
127
     * @param bool      $plainText          True to get the response in plaintext list. Default is false
128
     * @param int       $confidenceMinimum  The abuse confidence score minimum (subscribers feature). Default is 100.
129
     *                                      The confidence minimum must be between 25 and 100.
130
     *                                      This parameter is a subscriber feature (not honored otherwise).
131
     * 
132
     * @return ApiResponse
133
     */
134
    public function blacklist(int $limit = 10000, bool $plainText = false, int $confidenceMinimum = 100): ApiResponse
135
    {
136
        try {
137
            return parent::blacklist($limit, $plainText, $confidenceMinimum);
138
        } catch (\Exception $e) {
139
            return ApiResponse::createErrorResponse($e->getMessage());
140
        }
141
    }
142
}