Passed
Push — feature/job-builder/skills ( f79c14...4e9cbe )
by Tristan
14:13
created

Kernel::osProcessIsRunning()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 20
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2.0438

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 20
ccs 7
cts 9
cp 0.7778
rs 10
cc 2
nc 2
nop 1
crap 2.0438
1
<?php
2
3
namespace App\Console;
4
5
use Illuminate\Console\Scheduling\Schedule;
6
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
7
8
class Kernel extends ConsoleKernel
9
{
10
    /**
11
     * The Artisan commands provided by your application.
12
     *
13
     * @var array
0 ignored issues
show
introduced by
@var annotation of property \App\Console\Kernel::$commands does not specify type hint for its items.
Loading history...
14
     */
15
    protected $commands = [
16
        //
0 ignored issues
show
Coding Style introduced by
Blank comments are not allowed
Loading history...
17
    ];
18
19
    /**
20
     * Define the application's command schedule.
21
     *
22
     * @param  \Illuminate\Console\Scheduling\Schedule $schedule
1 ignored issue
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
23
     * @return void
24
     */
25 97
    protected function schedule(Schedule $schedule): void
26
    {
27
        // $schedule->command('inspire')
28
        //          ->hourly();
0 ignored issues
show
Coding Style introduced by
Expected 1 space before comment text but found 10; use block comment if you need indentation
Loading history...
Coding Style introduced by
There should be no blank line after an inline comment.
Loading history...
29
30
        // start the queue daemon, if its not running
1 ignored issue
show
Coding Style Documentation introduced by
Inline comments must start with a capital letter
Loading history...
31 97
        if (!$this->osProcessIsRunning('queue:work')) {
32 97
            $schedule->command('queue:work')->everyMinute();
33
        }
34 97
    }
35
36
    /**
37
     * Register the commands for the application.
38
     *
39
     * @return void
40
     */
41 97
    protected function commands(): void
42
    {
43 97
        $this->load(__DIR__.'/Commands');
44
45 97
        require base_path('routes/console.php');
46 97
    }
47
48
    /**
49
     * checks, if a process with $needle in the name is running
50
     *
51
     * @param string $needle
1 ignored issue
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
52
     * @return boolean
53
     */
54 97
    protected function osProcessIsRunning(string $needle): bool
55
    {
56
        // get process status. the "-ww"-option is important to get the full output!
1 ignored issue
show
Coding Style Documentation introduced by
Inline comments must start with a capital letter
Loading history...
57 97
        exec('ps aux -ww', $process_status);
58
59
60
        // search $needle in process status
1 ignored issue
show
Coding Style Documentation introduced by
Inline comments must start with a capital letter
Loading history...
61 97
        $result = array_filter(
62 97
            $process_status,
63
            function ($var) use ($needle) {
64
                return strpos($var, $needle);
65 97
            }
66
        );
67
68
        // if the result is not empty, the needle exists in running processes
1 ignored issue
show
Coding Style Documentation introduced by
Inline comments must start with a capital letter
Loading history...
69 97
        if (!empty($result)) {
70
            return true;
71
        }
72
73 97
        return false;
74
    }
75
}
76