Completed
Push — master ( 461c20...02a675 )
by Chris
01:56
created

Cloudflare   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 1

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 12
c 2
b 0
f 1
lcom 2
cbo 1
dl 0
loc 67
rs 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A getEndpoint() 0 4 1
A getAPIKEY() 0 4 1
A getEmail() 0 4 1
A getMakeRequests() 0 4 1
A diableRequests() 0 4 1
A enableRequests() 0 4 1
A __construct() 0 9 3
A loadConfig() 0 19 3
1
<?php
2
/**
3
 * @author Chris Hilsdon <[email protected]>
4
 */
5
namespace Cloudflare;
6
7
use Symfony\Component\Yaml\Yaml;
8
9
class Cloudflare
10
{
11
    protected $Endpoint = "https://api.cloudflare.com/client/v4/";
12
    protected $APIKEY;
13
    protected $Email;
14
    protected $MakeRequests = true;
15
16
    public function getEndpoint()
17
    {
18
        return $this->Endpoint;
19
    }
20
21
    public function getAPIKEY()
22
    {
23
        return $this->APIKEY;
24
    }
25
26
    public function getEmail()
27
    {
28
        return $this->Email;
29
    }
30
31
    public function getMakeRequests()
32
    {
33
        return $this->MakeRequests;
34
    }
35
36
    public function diableRequests()
37
    {
38
        $this->MakeRequests = false;
39
    }
40
41
    public function enableRequests()
42
    {
43
        $this->MakeRequests = true;
44
    }
45
46
    public function __construct($APIKEY = null, $Email = null)
47
    {
48
        if (is_null($APIKEY) || is_null($Email)) {
49
            $this->loadConfig();
50
        } else {
51
            $this->APIKEY = $APIKEY;
52
            $this->Email = $Email;
53
        }
54
    }
55
56
    private function loadConfig()
57
    {
58
        $config = 'Cloudflare.yml';
59
        $configDist = $config.'.dist';
60
        $dir = $_SERVER['DOCUMENT_ROOT'];
61
62
        if (@file_exists($dir . $config)) {
63
            $load = $config;
64
        } elseif (@file_exists($dir . $configDist)) {
65
            $load = $configDist;
66
        } else {
67
            die('Unable to load either "'.$config.'" or "'.$configDist.'"');
68
        }
69
70
        $config = Yaml::parse(file_get_contents($load));
71
72
        $this->APIKEY = $config['APIKEY'];
73
        $this->Email = $config['Email'];
74
    }
75
}
76