Passed
Pull Request — master (#1095)
by Iman
03:10
created

RequirementChecker::check()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 12
nc 1
nop 0
dl 0
loc 15
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace crocodicstudio\crudbooster\commands;
4
5
class RequirementChecker
6
{
7
8
    private $requirements = true;
9
10
    function check()
11
    {
12
        $this->info('System Requirements Checking:');
0 ignored issues
show
Bug introduced by
The method info() does not exist on crocodicstudio\crudboost...ands\RequirementChecker. ( Ignorable by Annotation )

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

12
        $this->/** @scrutinizer ignore-call */ 
13
               info('System Requirements Checking:');

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...
13
        $this->checkLaravelVersion();
14
        $this->checkPHPversion();
15
        $this->chechExtension('mbstring');
16
        $this->chechExtension('openssl');
17
        $this->chechExtension('pdo');
18
        $this->chechExtension('tokenizer');
19
        $this->chechExtension('xml');
20
        $this->chechExtension('gd');
21
        $this->chechExtension('fileinfo');
22
        $this->checkWritableFolders();
23
24
        return $this->requirements;
25
    }
26
27
    private function checkPHPversion()
28
    {
29
        if (version_compare(phpversion(), '5.6.0', '>=')) {
30
            $this->info('PHP Version (>= 5.6.*): [Good]');
31
        } else {
32
            $this->info('PHP Version (>= 5.6.*): [Bad] Yours: '.phpversion());
33
            $this->requirements = false;
34
        }
35
    }
36
37
    private function checkLaravelVersion()
38
    {
39
        $laravel = app();
0 ignored issues
show
Bug introduced by
The function app was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

39
        $laravel = /** @scrutinizer ignore-call */ app();
Loading history...
40
        if ($laravel::VERSION >= 5.3) {
41
            $this->info('Laravel Version (>= 5.3.*): [Good]');
42
            return true;
43
        }
44
        $this->info('Laravel Version (>= 5.3.*): [Bad]');
45
        return $this->requirements = false;
46
47
    }
48
49
    private function checkWritableFolders()
50
    {
51
        if (is_writable(base_path('public'))) {
0 ignored issues
show
Bug introduced by
The function base_path was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

51
        if (is_writable(/** @scrutinizer ignore-call */ base_path('public'))) {
Loading history...
52
            $this->info('public dir is writable: [Good]');
53
            return true;
54
        }
55
        $this->info('public dir is writable: [Bad]');
56
        return $this->requirements = false;
57
58
    }
59
60
    /**
61
     * @param $extension
62
     * @return true
63
     */
64
    private function chechExtension($extension)
65
    {
66
        if (! extension_loaded($extension)) {
67
            $this->info($extension.' extension: [Bad]');
68
            return $this->requirements = false;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->requirements = false returns the type false which is incompatible with the documented return type true.
Loading history...
69
        }
70
71
        $this->info($extension.' extension: [Good]');
72
        return true;
73
    }
74
}