Completed
Push — master ( a4b34c...4714ce )
by Rougin
02:31
created

Tools   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 122
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 16
Bugs 5 Features 1
Metric Value
wmc 13
c 16
b 5
f 1
lcom 0
cbo 2
dl 0
loc 122
ccs 50
cts 50
cp 1
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A hasLayout() 0 7 2
B ignite() 0 64 6
A isCommandEnabled() 0 7 2
A stripTableSchema() 0 6 2
A strip_table_schema() 0 4 1
1
<?php
2
3
namespace Rougin\Combustor\Common;
4
5
/**
6
 * Tools
7
 *
8
 * Provides a list of multi-purpose functions for Combustor.
9
 * 
10
 * @package Combustor
11
 * @author  Rougin Royce Gutib <[email protected]>
12
 */
13
class Tools
14
{
15
    /**
16
     * Checks whether the header and footer file exists.
17
     *
18
     * @return bool
19
     */
20 6
    public static function hasLayout()
21
    {
22 6
        $header = APPPATH . 'views/layout/header.php';
23 6
        $footer = APPPATH . 'views/layout/footer.php';
24
25 6
        return file_exists($header) && file_exists($footer);
26
    }
27
28
    /**
29
     * "Ignites" the post installation process.
30
     * 
31
     * @return void
32
     */
33 30
    public static function ignite()
34
    {
35 30
        $autoloadPath = 'realpath(\'vendor\') . \'/autoload.php\'';
36 30
        $configPath = APPPATH . 'config';
37
        $templatePath = __DIR__ . '/../Templates';
38
39 30
        // Gets data from application/config/config.php
40
        $config = new Config('config', $configPath);
41 30
42 30
        $config->set('composer_autoload', 138, $autoloadPath, 'string', true);
43 30
        $config->set('index_page', 37, '', 'string');
44
        $config->set('encryption_key', 316, md5('rougin'), 'string');
45 30
46
        $config->save();
47
48 30
        // Gets data from application/config/autoload.php
49
        $autoload = new Config('autoload', $configPath);
50
51 30
        // Gets the currently included drivers.
52
        $drivers = $autoload->get('drivers', 81, 'array');
53
54 30
        // Includes "session" driver.
55 30
        if ( ! in_array('session', $drivers)) {
56 30
            array_push($drivers, 'session');
57
        }
58
59 30
        // Gets the currently included helpers
60 30
        $defaultHelpers = [ 'form', 'url' ];
61
        $helpers = $autoload->get('helper', 91, 'array');
62 30
63 30
        foreach ($defaultHelpers as $helper) {
64 30
            if ( ! in_array($helper, $helpers)) {
65 30
                array_push($helpers, $helper);
66 30
            }
67
        }
68 30
69 30
        $autoload->set('drivers', 81, $drivers, 'array');
70
        $autoload->set('helper', 91, $helpers, 'array');
71 30
72
        $autoload->save();
73
74 30
        $templates = [
75 30
            [
76 30
                'file' => '.htaccess',
77
                'name' => 'Htaccess'
78 30
            ],
79 30
            [
80
                'file' => APPPATH . 'config/pagination.php',
81 30
                'name' => 'Pagination'
82 30
            ]
83 30
        ];
84
85 30
        foreach ($templates as $template) {
86
            $file = new File($template['file']);
87
            $path = $templatePath . '/' . $template['name'] . '.tpl';
88 30
89 30
            if ($template['file'] == '.htaccess') {
90 30
                $file->chmod(0777);
91
            }
92 30
93
            $file->putContents(file_get_contents($path));
94 30
            $file->close();
95 30
        }
96 30
    }
97 30
98
    /**
99
     * Checks whether the command is enabled or not in the current environment.
100
     *
101
     * @return bool
102
     */
103
    public static function isCommandEnabled()
104 6
    {
105
        $doctrine = APPPATH . 'libraries/Doctrine.php';
106 6
        $wildfire = APPPATH . 'libraries/Wildfire.php';
107
108
        return file_exists($doctrine) || file_exists($wildfire);
109
    }
110
111
    /**
112
     * Strips the table schema from the table name.
113
     * 
114 3
     * @param  string $table
115
     * @return string
116 3
     */
117
    public static function stripTableSchema($table)
118
    {
119
        return (strpos($table, '.') !== false)
120
            ? substr($table, strpos($table, '.') + 1)
121
            : $table;
122
    }
123
124 6
    /**
125
     * Strips the table schema from the table name.
126 6
     * 
127
     * @param  string $table
128
     * @return string
129
     */
130
    public static function strip_table_schema($table)
131
    {
132
        return self::stripTableSchema($table);
133
    }
134
}
135