Test Setup Failed
Push — master ( 21f1bb...1dec6d )
by Php Easy Api
04:35
created

SupervisorJob::isSupervisorRunning()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 1
b 0
f 0
1
<?php
2
3
namespace Resta\Worker;
4
5
use Resta\Contracts\JobContracts;
6
7
class SupervisorJob extends JobAbstract implements JobContracts
8
{
9
    /**
10
     * execute job
11
     *
12
     * @return mixed|void
13
     */
14
    public function execute()
15
    {
16
        $this->isSupervisorRunning();
17
18
        $this->{$this->jobProcessor()}();
19
20
        echo $this->getWorkersForSupervisor();
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->getWorkersForSupervisor() targeting Resta\Worker\SupervisorJ...tWorkersForSupervisor() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
21
    }
22
23
    /**
24
     * start job
25
     *
26
     * @return mixed|void
27
     */
28
    public function start()
29
    {
30
        $this->putConfigurationFile();
31
32
        $this->reReadForSupervisor();
33
34
        $this->updateForSupervisor();
35
36
        $this->startWorkerForSupervisor();
37
    }
38
39
    /**
40
     * stop job
41
     *
42
     * @return mixed|void
43
     */
44
    public function stop()
45
    {
46
        $this->stopWorkerForSupervisor();
47
    }
48
49
    /**
50
     * get status worker
51
     *
52
     * @return mixed|void
53
     */
54
    public function status()
55
    {
56
        //
57
    }
58
59
    /**
60
     * get workers for supervisor
61
     *
62
     * @return mixed
63
     */
64
    public function getWorkersForSupervisor()
65
    {
66
        return $this->process->command(config('supervisor.commands.workers'));
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->process->command(...sor.commands.workers')) targeting Resta\Support\Process::command() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
67
    }
68
69
    /**
70
     * check if the supervisor is or not running
71
     *
72
     * @return mixed|void
73
     */
74
    public function isSupervisorRunning()
75
    {
76
        $this->process->command(config('supervisor.commands.status'));
77
    }
78
79
    /**
80
     * reread for supervisor
81
     *
82
     * @return mixed
83
     */
84
    public function reReadForSupervisor()
85
    {
86
        return $this->process->command(config('supervisor.commands.reread'));
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->process->command(...isor.commands.reread')) targeting Resta\Support\Process::command() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
87
    }
88
89
    /**
90
     * start Worker for supervisor
91
     *
92
     * @return mixed
93
     */
94
    public function startWorkerForSupervisor()
95
    {
96
        return $this->process->command(config('supervisor.commands.start').' '.$this->app->get('WORKER').':*');
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->process->command(...->get('WORKER') . ':*') targeting Resta\Support\Process::command() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
97
    }
98
99
    /**
100
     * stop worker for supervisor
101
     *
102
     * @return mixed
103
     */
104
    public function stopWorkerForSupervisor()
105
    {
106
        return $this->process->command(config('supervisor.commands.stop').' '.$this->app->get('WORKER').':*');
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->process->command(...->get('WORKER') . ':*') targeting Resta\Support\Process::command() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
107
    }
108
109
    /**
110
     * put configutation file for supervisor
111
     *
112
     * @return mixed|void
113
     */
114
    public function putConfigurationFile()
115
    {
116
        $path = config('supervisor.path').'/'.$this->app->get('WORKER').'.conf';
117
118
        if(files()->exists($path)===false){
119
            files()->put($path,'
120
[program:'.$this->app()->get('WORKER').']
121
process_name=%(program_name)s_%(process_num)02d
122
command=php '.root.'/api worker start '.$this->app->get('PROJECT_NAME').' worker:'.$this->worker->getWorker().' apply:default
0 ignored issues
show
Bug introduced by
The method getWorker() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

122
command=php '.root.'/api worker start '.$this->app->get('PROJECT_NAME').' worker:'.$this->worker->/** @scrutinizer ignore-call */ getWorker().' apply:default

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
123
autostart=true
124
autorestart=true
125
user=root
126
numprocs=1
127
redirect_stderr=true
128
stdout_logfile='.config('supervisor.log').'/worker.log
129
');
130
        }
131
132
    }
133
134
    /**
135
     * update for supervisor
136
     *
137
     * @return mixed
138
     */
139
    public function updateForSupervisor()
140
    {
141
        return $this->process->command(config('supervisor.commands.update'));
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->process->command(...isor.commands.update')) targeting Resta\Support\Process::command() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
142
    }
143
}