Completed
Push — master ( 15646a...c9a834 )
by Rakshit
01:11
created

ConsoleCommand   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 76
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 10
lcom 0
cbo 1
dl 0
loc 76
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
B handle() 0 44 9
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
        $commandToExecute = "";
42
        if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
43
            $phpPath = exec("where php");
44
            $command = "tasklist | FIND ";
45
        } else {
46
            $phpPath = exec("which php");
47
            $command = "pgrep ";
48
        }
49
50
51
        if (
52
            empty(config('queuefy.QUEUE_COMMAND_FULL_PATH'))
53
            and
54
            !empty(config('queuefy.QUEUE_COMMAND_AFTER_PHP_ARTISAN'))
55
        ) {
56
            $commandToExecute .= $phpPath . ' ';
57
            $commandToExecute .= base_path() . DIRECTORY_SEPARATOR . "artisan ";
58
            $commandToExecute .= config('queuefy.QUEUE_COMMAND_AFTER_PHP_ARTISAN');
59
        }
60
61
        if (
62
            !empty(config('queuefy.QUEUE_COMMAND_FULL_PATH'))
63
            and
64
            empty(config('queuefy.QUEUE_COMMAND_AFTER_PHP_ARTISAN'))
65
        ) {
66
            $commandToExecute .= config('queuefy.QUEUE_COMMAND_FULL_PATH');
67
        }
68
        $OUTPUT_FINAL = 'Nothing Done';
69
        if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
70
            $commandToCheckProcess = $command . '"' . $commandToExecute . '"';
71
        } else {
72
            $commandToCheckProcess = $command . '"' . $commandToExecute . '"';
73
        }
74
        if (!($ID = shell_exec($commandToCheckProcess))) {
75
            $ID = trim($ID);
76
            $OUTPUT_FINAL = 'Process is running with PID ' . $ID . '.';
77
        }
78
        if(empty($ID)){
79
            $OUTPUT_FINAL = shell_exec($commandToExecute);
80
        }
81
        echo $OUTPUT_FINAL;
82
    }
83
}
84