Test Setup Failed
Push — master ( 1dec6d...a46529 )
by Php Easy Api
03:50
created

SupervisorJob::execute()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 7
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
        $this->getWorkersForSupervisor();
57
    }
58
59
    /**
60
     * cleans worker
61
     *
62
     * @return mixed|void
63
     */
64
    public function clear()
65
    {
66
        $this->cleanWorkerForSupervisor();
67
    }
68
69
    /**
70
     * get workers for supervisor
71
     *
72
     * @return mixed
73
     */
74
    private function cleanWorkerForSupervisor()
75
    {
76
        return $this->process->command(config('supervisor.commands.remove').' '.$this->app->get('WORKER').'');
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->process->command(...pp->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...
77
    }
78
79
    /**
80
     * get workers for supervisor
81
     *
82
     * @return mixed
83
     */
84
    public function getWorkersForSupervisor()
85
    {
86
        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...
87
    }
88
89
    /**
90
     * check if the supervisor is or not running
91
     *
92
     * @return mixed|void
93
     */
94
    public function isSupervisorRunning()
95
    {
96
        $this->process->command(config('supervisor.commands.status'));
97
    }
98
99
    /**
100
     * reread for supervisor
101
     *
102
     * @return mixed
103
     */
104
    public function reReadForSupervisor()
105
    {
106
        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...
107
    }
108
109
    /**
110
     * start Worker for supervisor
111
     *
112
     * @return mixed
113
     */
114
    public function startWorkerForSupervisor()
115
    {
116
        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...
117
    }
118
119
    /**
120
     * stop worker for supervisor
121
     *
122
     * @return mixed|void
123
     */
124
    public function stopWorkerForSupervisor()
125
    {
126
        $this->process->command(config('supervisor.commands.stop').' '.$this->app->get('WORKER').':*');
127
    }
128
129
    /**
130
     * put configutation file for supervisor
131
     *
132
     * @return mixed|void
133
     */
134
    public function putConfigurationFile()
135
    {
136
        $path = config('supervisor.path').'/'.$this->app->get('WORKER').'.conf';
137
138
        if(files()->exists($path)===false){
139
            files()->put($path,'
140
[program:'.$this->app()->get('WORKER').']
141
process_name=%(program_name)s_%(process_num)02d
142
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

142
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...
143
autostart=true
144
autorestart=true
145
user=root
146
numprocs=1
147
redirect_stderr=true
148
stdout_logfile='.config('supervisor.log').'/worker.log
149
');
150
        }
151
152
    }
153
154
    /**
155
     * update for supervisor
156
     *
157
     * @return mixed
158
     */
159
    public function updateForSupervisor()
160
    {
161
        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...
162
    }
163
}