Passed
Push — master ( 6429db...ea3910 )
by Iman
04:24
created

RequirementChecker   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 78
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 78
rs 10
c 0
b 0
f 0
wmc 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A checkPHPversion() 0 8 2
A chechExtension() 0 9 2
A checkLaravelVersion() 0 9 2
A checkWritableFolders() 0 8 2
A __construct() 0 3 1
A check() 0 14 1
1
<?php
2
3
namespace crocodicstudio\crudbooster\CBCoreModule\Installer;
4
5
use Illuminate\Foundation\Application;
6
7
class RequirementChecker
8
{
9
10
    private $console;
11
12
    /**
13
     * ConsolePrinter constructor.
14
     *
15
     * @param $console
16
     */
17
    public function __construct($console)
18
    {
19
        $this->console = $console;
20
    }
21
22
    private $requirements = true;
23
24
    public function check()
25
    {
26
        $this->console->info('System Requirements Checking:');
27
        $this->checkLaravelVersion();
28
        $this->checkPHPversion();
29
30
        $extensions = ['mbstring', 'openssl', 'pdo', 'tokenizer', 'xml', 'gd', 'fileinfo',];
31
        array_walk($extensions, function ($ext){
32
            $this->chechExtension($ext);
33
        });
34
35
        $this->checkWritableFolders();
36
37
        return $this->requirements;
38
    }
39
40
    private function checkPHPversion()
41
    {
42
        if (version_compare(phpversion(), '7.0', '>=')) {
43
            $this->console->info('PHP Version (>= 7.0): [Good]');
44
            return;
45
        }
46
        $this->console->info('PHP Version (>= 7.0): [Bad] Yours: '.phpversion());
47
        $this->requirements = false;
48
    }
49
50
    private function checkLaravelVersion()
51
    {
52
        if (Application::VERSION >= 5.4) {
53
            $this->console->info('Laravel Version (>= 5.4.*): [Good]');
54
            return;
55
        }
56
57
        $this->console->info('Laravel Version (>= 5.4.*): [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
     * @param $extension
74
     * @return boolean
75
     */
76
    private function chechExtension($extension)
77
    {
78
        if (! extension_loaded($extension)) {
79
            $this->console->info($extension.' extension: [Bad]');
80
            return $this->requirements = false;
81
        }
82
83
        $this->console->info($extension.' extension: [Good]');
84
        return true;
85
    }
86
}