Checks::cli()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php namespace Comodojo\Extender\Utils;
2
3
use \Comodojo\Foundation\Base\Configuration;
4
use \Comodojo\Extender\Components\Database;
5
use \Exception;
6
7
/**
8
 * @package     Comodojo Extender
9
 * @author      Marco Giovinazzi <[email protected]>
10
 * @license     MIT
11
 *
12
 * LICENSE:
13
 *
14
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
 * THE SOFTWARE.
21
 */
22
23
class Checks {
24
25
    /**
26
     * Check if script is running from command line
27
     *
28
     * @return  bool
29
     */
30
    final public static function cli() {
31
32
        return php_sapi_name() === 'cli';
33
34
    }
35
36
    /**
37
     * Check if php interpreter supports pcntl_fork (required in multithread mode)
38
     *
39
     * @return  bool
40
     */
41
    final public static function multithread() {
42
43
        return function_exists("pcntl_fork");
44
45
    }
46
47
    /**
48
     * Check if php interpreter supports pcntl signal handlers
49
     *
50
     * @return  bool
51
     */
52
    final public static function signals() {
53
54
        return function_exists("pcntl_signal");
55
56
    }
57
58
    /**
59
     * Check if database is available and initialized correctly
60
     *
61
     * @return  bool
62
     */
63
    final public static function database(Configuration $configuration) {
64
65
        try {
66
67
            $dbh = Database::init($configuration);
68
69
            $dbh->connect();
0 ignored issues
show
Bug introduced by
The method connect() does not exist on Comodojo\Extender\Components\Database. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

69
            $dbh->/** @scrutinizer ignore-call */ 
70
                  connect();

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...
70
71
            $manager = $dbh->getSchemaManager();
0 ignored issues
show
Bug introduced by
The method getSchemaManager() does not exist on Comodojo\Extender\Components\Database. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

71
            /** @scrutinizer ignore-call */ 
72
            $manager = $dbh->getSchemaManager();

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...
72
73
            $manager->getTable($configuration->get('database-jobs-table'));
74
            $manager->getTable($configuration->get('database-worklogs-table'));
75
            $manager->getTable($configuration->get('database-queue-table'));
76
77
        } catch (Exception $e) {
78
79
            return false;
80
81
        } finally {
82
83
            $dhb->close();
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $dhb seems to be never defined.
Loading history...
84
85
        }
86
87
        return true;
88
89
    }
90
91
}
92