Test Failed
Push — stable ( 994ca0...7d5c83 )
by Nuno
04:30
created

Provider::isAvailable()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 3

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 5
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0
cc 3
nc 3
nop 0
crap 3
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * This file is part of Laravel Zero.
7
 *
8
 * (c) Nuno Maduro <[email protected]>
9
 *
10
 *  For the full copyright and license information, please view the LICENSE
11
 *  file that was distributed with this source code.
12
 */
13
14
namespace LaravelZero\Framework\Components\Queue;
15
16
use function class_exists;
17
use LaravelZero\Framework\Components\AbstractComponentProvider;
18
19
/**
20
 * @internal
21
 */
22
final class Provider extends AbstractComponentProvider
23
{
24
    /**
25
     * {@inheritdoc}
26
     */
27 29
    public function isAvailable(): bool
28
    {
29 29
        return class_exists(\Illuminate\Bus\BusServiceProvider::class) && class_exists(
30 29
                \Illuminate\Queue\QueueServiceProvider::class
31 29
            ) && file_exists($this->app->configPath('queue.php'));
32
    }
33
34
    /**
35
     * {@inheritdoc}
36
     */
37 29
    public function boot(): void
38
    {
39 29
        if ($this->app->environment() !== 'production') {
40 28
            $this->commands(
41
                [
42 28
                    \Illuminate\Queue\Console\TableCommand::class,
43
                    \Illuminate\Queue\Console\FailedTableCommand::class,
44
                    \Illuminate\Foundation\Console\JobMakeCommand::class,
45
                ]
46
            );
47
        }
48
49 29
        $this->commands(
50
            [
51 29
                \Illuminate\Queue\Console\WorkCommand::class,
52
                \Illuminate\Queue\Console\RetryCommand::class,
53
                \Illuminate\Queue\Console\ListenCommand::class,
54
                \Illuminate\Queue\Console\RestartCommand::class,
55
                \Illuminate\Queue\Console\ListFailedCommand::class,
56
                \Illuminate\Queue\Console\FlushFailedCommand::class,
57
                \Illuminate\Queue\Console\ForgetFailedCommand::class,
58
            ]
59
        );
60 29
    }
61
62
    /**
63
     * {@inheritdoc}
64
     */
65 29
    public function register(): void
66
    {
67 29
        $this->app->register(\Illuminate\Bus\BusServiceProvider::class);
68 29
        $this->app->register(\Illuminate\Queue\QueueServiceProvider::class);
69
70 29
        $this->app->bind(
71 29
            \Illuminate\Queue\Listener::class,
72
            function ($app) {
73 29
                return $app['queue.listener'];
74 29
            }
75
        );
76
77 29
        $config = $this->app['config'];
78
79 29
        $config->set('queue.default', $config->get('queue.default') ?: 'default');
80 29
    }
81
}
82