Passed
Push — master ( 72fffe...b949dd )
by Ferry
04:19
created

ComposerHelper::dumpAutoLoad()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 6
rs 10
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: User
5
 * Date: 8/26/2019
6
 * Time: 4:50 PM
7
 */
8
9
namespace crocodicstudio\crudbooster\helpers;
10
11
use Illuminate\Support\Facades\Artisan;
12
use Illuminate\Support\Facades\Log;
13
use Symfony\Component\Process\Process;
14
15
class ComposerHelper
16
{
17
    private static function findComposer()
18
    {
19
        if (file_exists(getcwd().'/composer.phar')) {
20
            return '"'.PHP_BINARY.'" '.getcwd().'/composer.phar';
21
        }
22
23
        return 'composer';
24
    }
25
26
    private static function findPHP() {
27
        return PHP_BINARY;
28
    }
29
30
    public static function dumpAutoLoad()
31
    {
32
        $composer = self::findComposer();
33
        $process = new Process($composer.' dump-autoload');
0 ignored issues
show
Bug introduced by
$composer . ' dump-autoload' 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

33
        $process = new Process(/** @scrutinizer ignore-type */ $composer.' dump-autoload');
Loading history...
34
        $process->setTimeout(0);
35
        $process->setWorkingDirectory(base_path())->run();
36
    }
37
38
    public static function composerRemove($package) {
39
        $composer = self::findComposer();
40
41
        // Composer require
42
        $process = new Process($composer.' remove '.$package);
0 ignored issues
show
Bug introduced by
$composer . ' remove ' . $package 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

42
        $process = new Process(/** @scrutinizer ignore-type */ $composer.' remove '.$package);
Loading history...
43
        $process->setTimeout(0);
44
        $process->setWorkingDirectory(base_path())->run();
45
    }
46
47
    public static function composerRequire($package, $serviceProvider) {
48
        $composer = self::findComposer();
49
        $php = self::findPHP();
0 ignored issues
show
Unused Code introduced by
The assignment to $php is dead and can be removed.
Loading history...
50
51
        // Composer require
52
        Log::debug($composer." require ".$package);
53
        $process = new Process($composer.' require '.$package);
0 ignored issues
show
Bug introduced by
$composer . ' require ' . $package 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

53
        $process = new Process(/** @scrutinizer ignore-type */ $composer.' require '.$package);
Loading history...
54
        $process->setTimeout(0);
55
        $process->setInput("Y");
56
        $process->setWorkingDirectory(base_path())->run();
57
58
        Artisan::call("vendor:publish",["--provider"=>$serviceProvider]);
59
60
        return $process->getOutput();
61
    }
62
63
}