ConsoleTaskerProvider::boot()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 5
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 9
ccs 0
cts 4
cp 0
crap 6
rs 10
1
<?php
2
3
namespace Cerbero\ConsoleTasker\Providers;
4
5
use Cerbero\ConsoleTasker\Console\Commands\MakeConsoleTaskerCommand;
6
use Cerbero\ConsoleTasker\Console\Printers\DefaultPrinter;
7
use Cerbero\ConsoleTasker\Console\Printers\PrinterInterface;
8
use Illuminate\Console\OutputStyle;
9
use Illuminate\Support\Facades\Config;
10
use Illuminate\Support\ServiceProvider;
11
use Symfony\Component\Console\Input\ArgvInput;
12
use Symfony\Component\Console\Output\ConsoleOutput;
13
14
/**
15
 * The console tasker provider.
16
 *
17
 */
18
class ConsoleTaskerProvider extends ServiceProvider
19
{
20
    /**
21
     * The configuration file path.
22
     *
23
     * @var string
24
     */
25
    protected const CONFIG = __DIR__ . '/../../config/console_tasker.php';
26
27
    /**
28
     * Bootstrap the application services.
29
     *
30
     * @return void
31
     */
32
    public function boot()
33
    {
34
        if ($this->app->runningInConsole()) {
35
            $this->commands(MakeConsoleTaskerCommand::class);
36
        }
37
38
        $this->publishes([
39
            static::CONFIG => $this->app->configPath('console_tasker.php')
40
        ], 'console_tasker');
41
    }
42
43
    /**
44
     * Register the bindings
45
     *
46
     * @return void
47
     */
48
    public function register()
49
    {
50
        $this->mergeConfigFrom(static::CONFIG, 'console_tasker');
51
52
        $this->app->bind(DefaultPrinter::class, function () {
53
            return new DefaultPrinter(new OutputStyle(new ArgvInput(), new ConsoleOutput()));
54
        });
55
56
        $this->app->bind(PrinterInterface::class, Config::get('console_tasker.printer'));
57
    }
58
}
59