ZoneAnalytics   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 1
dl 0
loc 42
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
B fetchDashboard() 0 27 3
A getTotalRequests() 0 5 1
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