Completed
Push — 2.0 ( 2c7009...c833bc )
by Marco
03:23
created

Checks::database()   B

Complexity

Conditions 2
Paths 20

Size

Total Lines 27
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 27
rs 8.8571
cc 2
eloc 13
nc 20
nop 1
1
<?php namespace Comodojo\Extender\Utils;
2
3
use \Comodojo\Dispatcher\Components\Configuration;
4
use \Comodojo\Extender\Components\Database;
5
use \Exception;
6
7
/**
8
 * Framework wide checks
9
 *
10
 * @package     Comodojo extender
11
 * @author      Marco Giovinazzi <[email protected]>
12
 * @license     GPL-3.0+
13
 *
14
 * LICENSE:
15
 *
16
 * This program is free software: you can redistribute it and/or modify
17
 * it under the terms of the GNU Affero General Public License as
18
 * published by the Free Software Foundation, either version 3 of the
19
 * License, or (at your option) any later version.
20
 *
21
 * This program is distributed in the hope that it will be useful,
22
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24
 * GNU Affero General Public License for more details.
25
 *
26
 * You should have received a copy of the GNU Affero General Public License
27
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
28
 */
29
30
class Checks {
31
32
    /**
33
     * Check if script is running from command line
34
     *
35
     * @return  bool
36
     */
37
    final public static function cli() {
38
39
        return php_sapi_name() === 'cli';
40
41
    }
42
43
    /**
44
     * Check if php interpreter supports pcntl_fork (required in multithread mode)
45
     *
46
     * @return  bool
47
     */
48
    final public static function multithread() {
49
50
        return function_exists("pcntl_fork");
51
52
    }
53
54
    /**
55
     * Check if php interpreter supports pcntl signal handlers
56
     *
57
     * @return  bool
58
     */
59
    final public static function signals() {
60
61
        return function_exists("pcntl_signal");
62
63
    }
64
65
    /**
66
     * Check if database is available and initialized correctly
67
     *
68
     * @return  bool
69
     */
70
    final public static function database(Configuration $configuration) {
71
72
        try {
73
74
            $dbh = Database::init($configuration);
75
76
            $dbh->connect();
77
78
            $manager = $dbh->getSchemaManager();
79
80
            $manager->getTable($configuration->get('database-jobs-table'));
0 ignored issues
show
Bug introduced by
The method getTable() does not seem to exist on object<Doctrine\DBAL\Sch...\AbstractSchemaManager>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
81
            $manager->getTable($configuration->get('database-worklogs-table'));
0 ignored issues
show
Bug introduced by
The method getTable() does not seem to exist on object<Doctrine\DBAL\Sch...\AbstractSchemaManager>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
82
            $manager->getTable($configuration->get('database-queue-table'));
0 ignored issues
show
Bug introduced by
The method getTable() does not seem to exist on object<Doctrine\DBAL\Sch...\AbstractSchemaManager>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
83
84
        } catch (Exception $e) {
85
86
            return false;
87
88
        } finally {
89
90
            $dhb->close();
0 ignored issues
show
Bug introduced by
The variable $dhb does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
91
92
        }
93
94
        return true;
95
96
    }
97
98
}
99