GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

Core::createSessionTableCliAction()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 11

Duplication

Lines 11
Ratio 100 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 0
dl 11
loc 11
rs 9.9
c 0
b 0
f 0
1
<?php
2
/**
3
 * Controller
4
 *
5
 * @copyright Copyright (c)  Gjero Krsteski (http://krsteski.de)
6
 * @license   http://opensource.org/licenses/MIT MIT License
7
 */
8
9
namespace Pimf\Controller;
10
11
use Pimf\Config, Pimf\Cli\Std, Pimf\Pdo\Factory, \Pimf\Controller\Exception as Bomb, Pimf\Util\File;
12
13
/**
14
 * @package Controller
15
 * @author  Gjero Krsteski <[email protected]>
16
 * @codeCoverageIgnore
17
 */
18
class Core extends Base
19
{
20
    /**
21
     * Because it is a PIMF restriction!
22
     */
23
    public function indexAction()
24
    {
25
26
    }
27
28
    /**
29
     * Checks the applications architecture and creates some security and safety measures.
30
     */
31
    public function initCliAction()
32
    {
33
        clearstatcache();
34
35
        $app = 'app/' . Config::get('app.name') . '/';
36
37
        $assets = array(
38
            BASE_PATH . $app . '_session/',
39
            BASE_PATH . $app . '_cache/',
40
            BASE_PATH . $app . '_database/',
41
            BASE_PATH . $app . '_templates/',
42
        );
43
44
        echo 'Check app assets' . PHP_EOL;
45
46
        foreach ($assets as $asset) {
47
48
            if (!is_dir($asset)) {
49
                echo "[ Please create '$asset' directory! ]" . PHP_EOL;
50
            }
51
52
            if (!is_writable($asset)) {
53
                echo "[ Please make '$asset' writable! ]" . PHP_EOL;
54
            }
55
        }
56
57
        echo 'Secure root directory' . PHP_EOL;
58
        chmod(BASE_PATH, 0755);
59
60
        echo 'Secure .htaccess' . PHP_EOL;
61
        chmod(BASE_PATH . '.htaccess', 0644);
62
63
        echo 'Secure index.php' . PHP_EOL;
64
        chmod(BASE_PATH . 'index.php', 0644);
65
66
        echo 'Secure autoload.core.php' . PHP_EOL;
67
        chmod(BASE_PATH . 'pimf-framework/autoload.core.php', 0644);
68
69
        echo 'Create logging files' . PHP_EOL;
70
71
        $directory = Config::get('bootstrap.local_temp_directory');
72
73
        $handle = fopen($file = $directory . 'pimf-logs.txt', "at+");
74
        fclose($handle);
75
        chmod($file, 0777);
76
        $handle = fopen($file = $directory . 'pimf-warnings.txt', "at+");
77
        fclose($handle);
78
        chmod($file, 0777);
79
        $handle = fopen($file = $directory . 'pimf-errors.txt', "at+");
80
        fclose($handle);
81
        chmod($file, 0777);
82
83
        clearstatcache();
84
    }
85
86 View Code Duplication
    public function createSessionTableCliAction()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
87
    {
88
        $std = new Std();
89
        $type = $std->read('database type [mysql|sqlite]', '(mysql|sqlite)');
90
91
        if ($this->createTable($type, 'session')) {
92
            echo 'Session table successfully created.' . PHP_EOL;
93
        } else {
94
            echo 'Problems creating session table!' . PHP_EOL;
95
        }
96
    }
97
98 View Code Duplication
    public function createCacheTableCliAction()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
99
    {
100
        $std = new Std();
101
        $type = $std->read('database type [mysql|sqlite]', '(mysql|sqlite)');
102
103
        if ($this->createTable($type, 'cache')) {
104
            echo 'Cache table successfully created.' . PHP_EOL;
105
        } else {
106
            echo 'Problems creating cache table!' . PHP_EOL;
107
        }
108
    }
109
110
    /**
111
     * @param string $type
112
     * @param string $for
113
     *
114
     * @return bool
115
     * @throws \DomainException
116
     */
117
    protected function createTable($type, $for)
118
    {
119
        $type = trim($type);
120
121
        try {
122
            $pdo = $file = null;
123
124
            switch ($for) {
125
                case 'cache':
126
                    $pdo = Factory::get(Config::get('cache.database'));
127
                    $file = 'create-cache-table-' . $type . '.sql';
128
                    break;
129
                case 'session':
130
                    $pdo = Factory::get(Config::get('session.database'));
131
                    $file = 'create-session-table-' . $type . '.sql';
132
                    break;
133
            }
134
135
            $file = str_replace('/', DS, BASE_PATH . 'pimf-framework/core/Pimf/_database/' . $file);
136
137
            return $pdo->exec(file_get_contents(new File($file))) || print_r($pdo->errorInfo(), true);
138
139
        } catch (\PDOException $pdoe) {
140
            throw new Bomb($pdoe->getMessage());
141
        }
142
    }
143
}
144