Passed
Push — master ( a14023...ec1592 )
by Ferry
05:48
created

CbInstaller::rrmdir()   A

Complexity

Conditions 5
Paths 5

Size

Total Lines 19
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 19
rs 9.6111
c 0
b 0
f 0
cc 5
nc 5
nop 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A CbInstaller::publishFiles() 0 7 1
A CbInstaller::findComposer() 0 7 2
1
<?php
2
3
namespace Crocodicstudio\Crudbooster\CBCoreModule\Installer;
4
5
use Symfony\Component\Process\Process;
6
7
class CbInstaller
8
{
9
    private $console;
10
11
    /**
12
     * ConsolePrinter constructor.
13
     *
14
     * @param $console
15
     */
16
    public function __construct($console)
17
    {
18
        $this->console = $console;
19
    }
20
21
    public function createVendorAtPublic()
22
    {
23
        $this->console->info('Checking public/vendor directory...');
24
        if (! file_exists(public_path('vendor'))) {
25
            mkdir(public_path('vendor'), 0777);
26
        }
27
28
        if (! is_writable(public_path('vendor'))) {
29
            $this->console->info('Setup aborted !');
30
            $this->console->info('Please set public/vendor directory to writable 0777');
31
            exit;
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
32
        }
33
    }
34
35
    public function installCrudbooster()
36
    {
37
        $this->publishFiles();
38
        $this->composerDumpAutoload();
39
        $this->migrateDatabase();
40
        $this->seedDatabase();
41
        $this->console->call('config:clear');
42
        if (app()->version() < 5.6) {
0 ignored issues
show
introduced by
The method version() does not exist on Illuminate\Container\Container. Are you sure you never get this type here, but always one of the subclasses? ( Ignorable by Annotation )

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

42
        if (app()->/** @scrutinizer ignore-call */ version() < 5.6) {
Loading history...
43
            $this->console->call('optimize');
44
        }
45
46
        $this->console->info('Installing CRUDBooster Is Completed ! Thank You :)');
47
    }
48
49
    /**
50
     * Get the composer command for the environment.
51
     *
52
     * @return string
53
     */
54
    private function findComposer()
55
    {
56
        if (file_exists(getcwd().'/composer.phar')) {
57
            return '"'.PHP_BINARY.'" '.getcwd().'/composer.phar';
58
        }
59
60
        return 'composer';
61
    }
62
63
    private function publishFiles()
64
    {
65
        $this->console->info('Publishing CRUDBooster needs file...');
66
        $this->console->callSilent('vendor:publish', ['--provider' => 'Crocodicstudio\\Crudbooster\\CRUDBoosterServiceProvider', '--force' => true]);
67
        $this->console->callSilent('vendor:publish', ['--tag' => 'cb_migration', '--force' => true]);
68
        $this->console->callSilent('vendor:publish', ['--tag' => 'cb_lfm', '--force' => true]);
69
        $this->console->callSilent('vendor:publish', ['--tag' => 'cb_localization', '--force' => true]);
70
    }
71
72
    private function migrateDatabase()
73
    {
74
        $this->console->info('Migrating Database...');
75
        $this->console->callSilent('migrate', ['--path' => '\database\migrations\crudbooster']);
76
        $this->console->callSilent('migrate');
77
    }
78
79
    private function seedDatabase()
80
    {
81
        $this->console->info('Seeding Database...');
82
        $this->console->callSilent('db:seed', ['--class' => '\Crocodicstudio\Crudbooster\Modules\EmailTemplates\Seeder']);
83
        $this->console->callSilent('db:seed', ['--class' => '\Crocodicstudio\Crudbooster\Modules\SettingModule\Seeder']);
84
        $this->console->callSilent('db:seed', ['--class' => '\Crocodicstudio\Crudbooster\Modules\PrivilegeModule\Seeder']);
85
    }
86
87
    private function composerDumpAutoload()
88
    {
89
        $this->console->info('Dumping the autoloaded files and reloading all new files...');
90
        $composer = $this->findComposer();
91
        $process = new Process($composer.' dumpautoload');
0 ignored issues
show
Bug introduced by
$composer . ' dumpautoload' of type string is incompatible with the type array expected by parameter $command of Symfony\Component\Process\Process::__construct(). ( Ignorable by Annotation )

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

91
        $process = new Process(/** @scrutinizer ignore-type */ $composer.' dumpautoload');
Loading history...
92
        $process->setWorkingDirectory(base_path())->run();
93
    }
94
}