Test Setup Failed
Push — master ( 894c42...6b221f )
by Php Easy Api
03:38
created

Worker::create()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 17
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 9
nc 2
nop 0
dl 0
loc 17
rs 9.9666
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 run()
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_STATUS',false);
37
38
        app()->resolve(WorkerManager::class,['args'=>$this->argument])->execute();
39
    }
40
41
    /**
42
     * @inheritDoc
43
     */
44
    public function stop()
45
    {
46
        $workerName = $this->projectName().'-'.$this->argument['worker'];
47
        app()->register('WORKER',$workerName);
48
        app()->register('PROJECT_NAME',strtolower($this->projectName()));
49
        app()->register('WORKER_STATUS',true);
50
51
        app()->resolve(WorkerManager::class,['args'=>$this->argument])->execute();
52
    }
53
54
    /**
55
     * @inheritDoc
56
     */
57
    public function create()
58
    {
59
        if(!file_exists(app()->path()->workers())){
60
            $this->directory['worker'] = app()->path()->workers();
61
            $this->file->makeDirectory($this);
62
        }
63
64
        $this->argument['workerNamespace'] = app()->namespace()->workers();
65
        $this->argument['workerClass'] = ucfirst($this->argument['worker']).'';
66
        $this->argument['projectName'] = strtolower($this->projectName());
67
68
        $this->touch['worker/worker']= app()->path()->workers().'/'.$this->argument['worker'].'.php';
69
70
71
        $this->file->touch($this);
72
73
        echo $this->classical(' > Worker file called as "'.$this->argument['worker'].'" has been successfully created in the '.app()->path()->workers().'');
74
    }
75
76
77
}