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

Worker::start()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 7
nc 1
nop 0
dl 0
loc 10
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Resta\Console\Source\Worker;
4
5
use Resta\Worker\WorkerManager;
6
use Resta\Console\ConsoleOutputter;
7
use Resta\Console\ConsoleListAccessor;
8
9
class Worker extends ConsoleOutputter {
10
11
    use ConsoleListAccessor;
12
13
    /**
14
     * @var $type
0 ignored issues
show
Documentation Bug introduced by
The doc comment $type at position 0 could not be parsed: Unknown type name '$type' at position 0 in $type.
Loading history...
15
     */
16
    public $type = 'worker';
17
18
    /**
19
     * @var $define
0 ignored issues
show
Documentation Bug introduced by
The doc comment $define at position 0 could not be parsed: Unknown type name '$define' at position 0 in $define.
Loading history...
20
     */
21
    public $define = 'begins worker for application';
22
23
    /**
24
     * @var $commandRule
0 ignored issues
show
Documentation Bug introduced by
The doc comment $commandRule at position 0 could not be parsed: Unknown type name '$commandRule' at position 0 in $commandRule.
Loading history...
25
     */
26
    public $commandRule = ['worker'];
27
28
    /**
29
     * @inheritDoc
30
     */
31
    public function start()
32
    {
33
        $workerName = $this->projectName().'-'.$this->argument['worker'];
34
        app()->register('WORKER',$workerName);
35
        app()->register('PROJECT_NAME',strtolower($this->projectName()));
36
        app()->register('WORKER_START',true);
37
        app()->register('WORKER_STOP',false);
38
        app()->register('WORKER_STATUS',false);
39
40
        app()->resolve(WorkerManager::class,['args'=>$this->argument])->execute();
41
    }
42
43
    /**
44
     * @inheritDoc
45
     */
46
    public function stop()
47
    {
48
        $workerName = $this->projectName().'-'.$this->argument['worker'];
49
        app()->register('WORKER',$workerName);
50
        app()->register('PROJECT_NAME',strtolower($this->projectName()));
51
        app()->register('WORKER_START',false);
52
        app()->register('WORKER_STOP',true);
53
        app()->register('WORKER_STATUS',false);
54
55
        app()->resolve(WorkerManager::class,['args'=>$this->argument])->execute();
56
    }
57
58
    /**
59
     * @inheritDoc
60
     */
61
    public function status()
62
    {
63
        $workerName = $this->projectName().'-'.$this->argument['worker'];
64
        app()->register('WORKER',$workerName);
65
        app()->register('PROJECT_NAME',strtolower($this->projectName()));
66
        app()->register('WORKER_START',false);
67
        app()->register('WORKER_STOP',false);
68
        app()->register('WORKER_STATUS',true);
69
70
        app()->resolve(WorkerManager::class,['args'=>$this->argument])->execute();
71
    }
72
73
    /**
74
     * @inheritDoc
75
     */
76
    public function create()
77
    {
78
        if(!file_exists(app()->path()->workers())){
79
            $this->directory['worker'] = app()->path()->workers();
80
            $this->file->makeDirectory($this);
81
        }
82
83
        $this->argument['workerNamespace'] = app()->namespace()->workers();
84
        $this->argument['workerClass'] = ucfirst($this->argument['worker']).'';
85
        $this->argument['projectName'] = strtolower($this->projectName());
86
87
        $this->touch['worker/worker']= app()->path()->workers().'/'.$this->argument['worker'].'.php';
88
89
90
        $this->file->touch($this);
91
92
        echo $this->classical(' > Worker file called as "'.$this->argument['worker'].'" has been successfully created in the '.app()->path()->workers().'');
93
    }
94
95
96
}