ZoneAnalytics::getTotalRequests()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
1
<?php
2
/*
3
 * @author Chris Hilsdon <[email protected]>
4
 *
5
 * @link https://api.cloudflare.com/#zone
6
 */
7
namespace Cloudflare;
8
9
use GuzzleHttp\Exception\ClientException;
10
11
class ZoneAnalytics extends Base
12
{
13
    protected $URL = "zones";
14
15
    /**
16
     *
17
     * @link https://api.cloudflare.com/#zone-analytics-dashboard
18
     */
19
    public function fetchDashboard($zone = '', $options = [])
20
    {
21
        $defaultOptions = [
22
            'since' => '-10080',
23
            'until' => 0,
24
            'continuous' => "true",
25
        ];
26
27
        $newOptions = [];
28
        $newOptions = array_merge($newOptions, $defaultOptions, $options);
29
30
        $string = "?";
31
        foreach ($newOptions as $k => $v) {
32
            $string .= $k . '=' . $v . '&';
33
        }
34
35
        //Remove the last '&'
36
        $string = substr($string, 0, -1);
37
38
        try{
39
            $this->makeRequest($this->URL . '/' . $zone . '/analytics/dashboard/' . $string);
40
        } catch (ClientException $e) {
41
            return false;
42
        }
43
44
        return $this;
45
    }
46
47
    public function getTotalRequests()
48
    {
49
        $response = $this->getResponse();
50
        return $response->result->totals->requests;
51
    }
52
}
53