Completed
Push — master ( 66d463...29db82 )
by Chris
05:36 queued 01:38
created

Cloudflare::loadConfig()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 19
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 19
rs 9.4285
cc 3
eloc 13
nc 3
nop 0
1
<?php
2
namespace Cloudflare;
3
4
use Symfony\Component\Yaml\Yaml;
5
6
class Cloudflare
7
{
8
    public $Endpoint = "https://api.cloudflare.com/client/v4/";
9
    public $APIKEY;
10
    public $Email;
11
12
    public function __construct($APIKEY = null, $Email = null)
13
    {
14
        if (is_null($APIKEY) || is_null($Email)) {
15
            $this->loadConfig();
16
        } else {
17
            $this->APIKEY = $APIKEY;
18
            $this->Email = $Email;
19
        }
20
    }
21
22
    private function loadConfig()
23
    {
24
        $config = 'Cloudflare.yml';
25
        $configDist = $config.'.dist';
26
        $dir = $_SERVER['DOCUMENT_ROOT'];
27
28
        if (@file_exists($dir . $config)) {
29
            $load = $config;
30
        } elseif (@file_exists($dir . $configDist)) {
31
            $load = $configDist;
32
        } else {
33
            die('Unable to load either "'.$config.'" or "'.$configDist.'"');
34
        }
35
36
        $config = Yaml::parse(file_get_contents($load));
37
38
        $this->APIKEY = $config['APIKEY'];
39
        $this->Email = $config['Email'];
40
    }
41
}
42