Completed
Push — master ( 5a5aff...6d6efd )
by Joram van den
04:02
created

Ajde_Config_Repository::defaults()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 16
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 16
rs 9.4285
cc 3
eloc 7
nc 4
nop 0
1
<?php
2
3
class Ajde_Config_Repository extends Ajde_Object_Standard
4
{
5
    /**
6
     * TODO
7
     *
8
     * @param string $directory
9
     */
10
    public function __construct($directory)
11
    {
12
        $this->readConfigDir($directory);
13
        $this->defaults();
14
    }
15
16
    /**
17
     * TODO
18
     *
19
     * @param string $directory
20
     */
21
    public function readConfigDir($directory)
22
    {
23
        $environment = Environment::current();
24
25
        $searchDirs = [
26
            CORE_DIR . $directory, '*.json',
27
            CORE_DIR . $directory . $environment . DS, '*.json',
28
            APP_DIR . $directory, '*.json',
29
            APP_DIR . $directory . $environment . DS, '*.json'
30
        ];
31
32
        foreach($searchDirs as $searchDir) {
33
            foreach(Ajde_Fs_Find::findFiles($searchDir, '*.json') as $configFile)
34
            {
35
                $this->merge(pathinfo($configFile, PATHINFO_FILENAME), json_decode(file_get_contents($configFile), true));
36
            }
37
        }
38
    }
39
40
    public function defaults()
41
    {
42
        // URI fragments
43
        $this->site_protocol = (isset($_SERVER['HTTPS']) && !empty($_SERVER['HTTPS'])) ? 'https://' : 'http://';
0 ignored issues
show
Bug introduced by
The property site_protocol does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
44
        $this->site_domain = $_SERVER['SERVER_NAME'];
0 ignored issues
show
Bug introduced by
The property site_domain does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
45
        $this->site_path = str_replace('index.php', '', $_SERVER['PHP_SELF']);
0 ignored issues
show
Bug introduced by
The property site_path does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
46
47
        // Assembled URI
48
        $this->site_root = $this->site_protocol . $this->site_domain . $this->site_path;
0 ignored issues
show
Bug introduced by
The property site_root does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
49
50
        // Assembled URI with language identifier
51
        $this->lang_root = $this->site_root;
0 ignored issues
show
Bug introduced by
The property lang_root does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
52
53
        // Set default timezone now
54
        date_default_timezone_set($this->timezone);
0 ignored issues
show
Bug introduced by
The property timezone does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
55
    }
56
}
57