Passed
Pull Request — master (#1107)
by Iman
04:35
created

RequirementChecker::checkLaravelVersion()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 6
nc 2
nop 0
dl 0
loc 10
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 $console;
9
10
    /**
11
     * ConsolePrinter constructor.
12
     *
13
     * @param $console
14
     */
15
    public function __construct(Command $console)
0 ignored issues
show
Bug introduced by
The type crocodicstudio\crudbooster\commands\Command was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
16
    {
17
        $this->console = $console;
18
    }
19
20
    private $requirements = true;
21
22
    function check()
23
    {
24
        $this->console->info('System Requirements Checking:');
25
        $this->checkLaravelVersion();
26
        $this->checkPHPversion();
27
        $this->chechExtension('mbstring');
28
        $this->chechExtension('openssl');
29
        $this->chechExtension('pdo');
30
        $this->chechExtension('tokenizer');
31
        $this->chechExtension('xml');
32
        $this->chechExtension('gd');
33
        $this->chechExtension('fileinfo');
34
        $this->checkWritableFolders();
35
36
        return $this->requirements;
37
    }
38
39
    private function checkPHPversion()
40
    {
41
        if (version_compare(phpversion(), '5.6.0', '>=')) {
42
            $this->console->info('PHP Version (>= 5.6.*): [Good]');
43
            return;
44
        }
45
        $this->console->info('PHP Version (>= 5.6.*): [Bad] Yours: '.phpversion());
46
        $this->requirements = false;
47
    }
48
49
    private function checkLaravelVersion()
50
    {
51
        $laravel = app();
52
        if ($laravel::VERSION >= 5.3) {
0 ignored issues
show
Bug introduced by
The constant Illuminate\Container\Container::VERSION was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
53
            $this->console->info('Laravel Version (>= 5.3.*): [Good]');
54
            return;
55
        }
56
57
        $this->console->info('Laravel Version (>= 5.3.*): [Bad]');
58
        $this->requirements = false;
59
60
    }
61
62
    private function checkWritableFolders()
63
    {
64
        if (is_writable(base_path('public'))) {
65
            $this->console->info('public dir is writable: [Good]');
66
            return true;
67
        }
68
        $this->console->info('public dir is writable: [Bad]');
69
        return $this->requirements = false;
70
71
    }
72
73
    /**
74
     * @param $extension
75
     * @return true
76
     */
77
    private function chechExtension($extension)
78
    {
79
        if (! extension_loaded($extension)) {
80
            $this->console->info($extension.' extension: [Bad]');
81
            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...
82
        }
83
84
        $this->console->info($extension.' extension: [Good]');
85
        return true;
86
    }
87
}