Test Setup Failed
Push — master ( b3b03e...4eeb1f )
by Php Easy Api
03:35
created

Worker   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 22
dl 0
loc 59
rs 10
c 0
b 0
f 0
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 0 17 2
A run() 0 15 3
1
<?php
2
3
namespace Resta\Console\Source\Worker;
4
5
use Resta\Console\ConsoleOutputter;
6
use Resta\Console\ConsoleListAccessor;
7
8
class Worker extends ConsoleOutputter {
9
10
    use ConsoleListAccessor;
11
12
    /**
13
     * @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...
14
     */
15
    public $type = 'worker';
16
17
    /**
18
     * @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...
19
     */
20
    public $define = 'begins worker for application';
21
22
    /**
23
     * @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...
24
     */
25
    public $commandRule = ['worker'];
26
27
    /**
28
     * @inheritDoc
29
     */
30
    public function run()
31
    {
32
        $worker = strtolower($this->argument['worker']);
33
34
        $registeredWorkers = app()->get('worker');
35
36
        if(isset($registeredWorkers[$worker])){
37
            while(true){
38
                echo $this->classical($registeredWorkers[$worker](1));
39
                sleep(10);
40
            }
41
            exit();
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
42
        }
43
44
        exception()->runtime('Any worker is not available');
45
    }
46
47
    /**
48
     * @inheritDoc
49
     */
50
    public function create()
51
    {
52
        if(!file_exists(app()->path()->workers())){
53
            $this->directory['worker'] = app()->path()->workers();
54
            $this->file->makeDirectory($this);
55
        }
56
57
        $this->argument['workerNamespace'] = app()->namespace()->workers();
58
        $this->argument['workerClass'] = ucfirst($this->argument['worker']).'';
59
        $this->argument['projectName'] = strtolower($this->projectName());
60
61
        $this->touch['worker/worker']= app()->path()->workers().'/'.$this->argument['worker'].'.php';
62
63
64
        $this->file->touch($this);
65
66
        echo $this->classical(' > Worker file called as "'.$this->argument['worker'].'" has been successfully created in the '.app()->path()->workers().'');
67
    }
68
69
70
}