Kernel::getCurrentQueue()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 7
nc 2
nop 0
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace App\Console;
4
5
use App\Model\MailJob\Condition;
6
use Illuminate\Console\Scheduling\Schedule;
7
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
8
9
class Kernel extends ConsoleKernel
10
{
11
    /**
12
     * The Artisan commands provided by your application.
13
     *
14
     * @var array
15
     */
16
    protected $commands = [
17
        'App\Console\Commands\Inspire',
18
        'App\Console\Commands\SendReport',
19
        'App\Console\Commands\CloseWork',
20
        'App\Console\Commands\TicketFetch',
21
    ];
22
23
    /**
24
     * Define the application's command schedule.
25
     *
26
     * @param \Illuminate\Console\Scheduling\Schedule $schedule
27
     *
28
     * @return void
29
     */
30
    protected function schedule(Schedule $schedule)
31
    {
32
        if (env('DB_INSTALL') == 1) {
33
34
            if ($this->getCurrentQueue() != 'sync') {
35
                $schedule->command('queue:listen '.$this->getCurrentQueue().' --sleep 60')->everyMinute();
36
            }
37
            $this->execute($schedule, 'fetching');
38
            $this->execute($schedule, 'notification');
39
            $this->execute($schedule, 'work');
40
        }
41
    }
42
43
    public function execute($schedule, $task)
44
    {
45
        $condition = new Condition();
46
        $command = $condition->getConditionValue($task);
47
        switch ($task) {
48
            case 'fetching':
49
                $this->getCondition($schedule->command('ticket:fetch'), $command);
50
                break;
51
            case 'notification':
52
                $this->getCondition($schedule->command('report:send'), $command);
53
                break;
54
            case 'work':
55
                $this->getCondition($schedule->command('ticket:close'), $command);
56
                break;
57
        }
58
    }
59
60
    public function getCondition($schedule, $command)
61
    {
62
        $condition = $command['condition'];
63
        $at = $command['at'];
64
        switch ($condition) {
65
            case 'everyMinute':
66
                $schedule->everyMinute();
67
                break;
68
            case 'everyFiveMinutes':
69
                $schedule->everyFiveMinutes();
70
                break;
71
            case 'everyTenMinutes':
72
                $schedule->everyTenMinutes();
73
                break;
74
            case 'everyThirtyMinutes':
75
                $schedule->everyThirtyMinutes();
76
                break;
77
            case 'hourly':
78
                $schedule->hourly();
79
                break;
80
            case 'daily':
81
                $schedule->daily();
82
                break;
83
            case 'dailyAt':
84
                $this->getConditionWithOption($schedule, $condition, $at);
85
                break;
86
            case 'weekly':
87
                $schedule->weekly();
88
                break;
89
            case 'monthly':
90
                $schedule->monthly();
91
                break;
92
            case 'yearly':
93
                $schedule->yearly();
94
                break;
95
        }
96
    }
97
98
    public function getConditionWithOption($schedule, $command, $at)
99
    {
100
        switch ($command) {
101
            case 'dailyAt':
102
                $schedule->dailyAt($at);
103
                break;
104
        }
105
    }
106
107
    public function getCurrentQueue()
108
    {
109
        $queue = 'database';
110
        $services = new \App\Model\MailJob\QueueService();
111
        $current = $services->where('status', 1)->first();
0 ignored issues
show
Documentation Bug introduced by
The method where does not exist on object<App\Model\MailJob\QueueService>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
112
        if ($current) {
113
            $queue = $current->short_name;
114
        }
115
116
        return $queue;
117
    }
118
}
119