Passed
Push — master ( 53bb62...283d0c )
by Rougin
08:28
created

Tools   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 120
Duplicated Lines 0 %

Test Coverage

Coverage 25.92%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 43
c 1
b 0
f 0
dl 0
loc 120
ccs 14
cts 54
cp 0.2592
rs 10
wmc 13

5 Methods

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