ConsoleCommand::handle()   B
last analyzed

Complexity

Conditions 9
Paths 64

Size

Total Lines 46

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 46
rs 7.6226
c 0
b 0
f 0
cc 9
nc 64
nop 0
1
<?php
2
3
4
namespace Rakshitbharat\Queuefy;
5
6
use Illuminate\Console\Command;
7
8
class ConsoleCommand extends Command
9
{
10
    /**
11
     * The name and signature of the console command.
12
     *
13
     * @var string
14
     */
15
    protected $signature = 'queuefy:run';
16
17
    /**
18
     * The console command description.
19
     *
20
     * @var string
21
     */
22
    protected $description = 'Run queue from console.';
23
24
    /**
25
     * Create a new command instance.
26
     *
27
     * @return void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
28
     */
29
    public function __construct()
30
    {
31
        parent::__construct();
32
    }
33
34
    /**
35
     * Execute the console command.
36
     *
37
     * @return mixed
38
     */
39
    public function handle()
40
    {
41
        echo 'Command Started';
42
        $commandToExecute = "";
43
        if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
44
            $phpPath = exec("where php");
45
            $command = "tasklist | FIND ";
46
        } else {
47
            $phpPath = exec("which php");
48
            $command = "pgrep ";
49
        }
50
51
52
        if (
53
            empty(config('queuefy.QUEUE_COMMAND_FULL_PATH'))
54
            and
55
            !empty(config('queuefy.QUEUE_COMMAND_AFTER_PHP_ARTISAN'))
56
        ) {
57
            $commandToExecute .= $phpPath . ' ';
58
            $commandToExecute .= base_path() . DIRECTORY_SEPARATOR . "artisan ";
59
            $commandToExecute .= config('queuefy.QUEUE_COMMAND_AFTER_PHP_ARTISAN');
60
        }
61
62
        if (
63
            !empty(config('queuefy.QUEUE_COMMAND_FULL_PATH'))
64
            and
65
            empty(config('queuefy.QUEUE_COMMAND_AFTER_PHP_ARTISAN'))
66
        ) {
67
            $commandToExecute .= config('queuefy.QUEUE_COMMAND_FULL_PATH');
68
        }
69
        $OUTPUT_FINAL = 'Nothing Done';
70
        if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
71
            $commandToCheckProcess = $command . '"' . $commandToExecute . '"';
72
        } else {
73
            $commandToCheckProcess = $command . '"' . $commandToExecute . '"';
74
        }
75
        if (!($ID = shell_exec($commandToCheckProcess))) {
76
            $ID = trim($ID);
77
            $OUTPUT_FINAL = 'Process is running with PID ' . $ID . '.';
78
        }
79
        if(empty($ID)){
80
            echo ' and Started Que';
81
            $OUTPUT_FINAL = shell_exec($commandToExecute);
82
        }
83
        echo $OUTPUT_FINAL;
84
    }
85
}
86