Passed
Push — feature/queued-mail ( 707895...3257bc )
by Tristan
11:52
created

Kernel::osProcessIsRunning()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 18
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2.0116

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 18
ccs 6
cts 7
cp 0.8571
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 2.0116
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
        //
17
    ];
18
19
    /**
20
     * Define the application's command schedule.
21
     *
22
     * @param  \Illuminate\Console\Scheduling\Schedule  $schedule
2 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter type; 2 found
Loading history...
23
     * @return void
24
     */
25 82
    protected function schedule(Schedule $schedule)
0 ignored issues
show
introduced by
Method \App\Console\Kernel::schedule() does not have return type hint for its return value but it should be possible to add it based on @return annotation "void".
Loading history...
26
    {
27
        // $schedule->command('inspire')
28
        //          ->hourly();
29
30
        // start the queue daemon, if its not running
31 82
        if (!$this->osProcessIsRunning('queue:work')) {
32 82
            $schedule->command('queue:work')->everyMinute();
33
        }
34 82
    }
35
36
    /**
37
     * Register the commands for the application.
38
     *
39
     * @return void
40
     */
41 82
    protected function commands()
0 ignored issues
show
introduced by
Method \App\Console\Kernel::commands() does not have return type hint for its return value but it should be possible to add it based on @return annotation "void".
Loading history...
42
    {
43 82
        $this->load(__DIR__.'/Commands');
44
45 82
        require base_path('routes/console.php');
46 82
    }
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 bool
1 ignored issue
show
Coding Style introduced by
Expected "boolean" but found "bool" for function return type
Loading history...
53
     */
54 82
    protected function osProcessIsRunning($needle)
1 ignored issue
show
introduced by
Method \App\Console\Kernel::osProcessIsRunning() does not have parameter type hint for its parameter $needle but it should be possible to add it based on @param annotation "string".
Loading history...
introduced by
Method \App\Console\Kernel::osProcessIsRunning() does not have return type hint for its return value but it should be possible to add it based on @return annotation "bool".
Loading history...
Coding Style introduced by
Type hint "string" missing for $needle
Loading history...
55
    {
56
        // get process status. the "-ww"-option is important to get the full output!
57 82
        exec('ps aux -ww', $process_status);
58
59
60
        // search $needle in process status
61 82
        $result = array_filter($process_status,
62
            function($var) use ($needle)
0 ignored issues
show
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
63 82
            {   return strpos($var, $needle); });
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
Coding Style introduced by
Opening brace must be the last content on the line
Loading history...
Coding Style introduced by
It is generally recommended to place each PHP statement on a line by itself.

Let’s take a look at an example:

// Bad
$a = 5; $b = 6; $c = 7;

// Good
$a = 5;
$b = 6;
$c = 7;
Loading history...
64
65
66
        // if the result is not empty, the needle exists in running processes
67 82
        if (!empty($result)) {
68
            return true;
69
        }
70
71 82
        return false;
72
    }
73
}
74