Test Failed
Pull Request — stable (#129)
by
unknown
02:21
created

ComponentProvider::isAvailable()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace LaravelZero\Framework\Commands\Component\Illuminate\Events;
4
5
use LaravelZero\Framework\Commands\Component\AbstractComponentProvider;
6
7
/**
8
 * This is the Laravel Zero Framework illuminate/events component provider class.
9
 *
10
 */
11
class ComponentProvider extends AbstractComponentProvider
12
{
13
14
    protected $commands = [
15
        'EventGenerate' => 'command.event.generate',
16
        'EventMake' => 'command.event.make',
17
        'ListenerMake' => 'command.listener.make',
18
    ];
19
20
    /**
21
     * {@inheritdoc}
22
     */
23
    public function isAvailable(): bool
24
    {
25
        return class_exists(\Illuminate\Events\EventServiceProvider::class);
26
    }
27
28
    /**
29
     * {@inheritdoc}
30
     */
31
    public function register(): void
32
    {
33
        // Since the LaravelZero Framework requires illuminate\events be installed, the call to isAvailable() above
34
        // will always return true. We cannot put this particular conditional in the isAbailable method since
35
        // the application isn't fully booted, and we cannot resolve $this->app->getNamespace(). Only when
36
        // the application-level EventServiceProvider is present do we register the Event commands.
37
        $providerName = $this->app->getNamespace() . 'Providers\EventServiceProvider';
38
        if (class_exists($providerName)) {
39
            $this->registerServiceProvider($providerName);
40
            $this->registerCommands($this->commands);
41
        }
42
    }
43
44
    /**
45
    * Register the given commands.
46
    *
47
    * @param  array  $commands
48
    * @return void
49
    */
50
    protected function registerCommands(array $commands)
51
    {
52
        foreach (array_keys($commands) as $command) {
53
            call_user_func_array([$this, "register{$command}Command"], []);
54
        }
55
56
        $this->commands(array_values($commands));
57
    }
58
59
    /**
60
     * Register the command.
61
     *
62
     * @return void
63
     */
64
    protected function registerEventGenerateCommand()
65
    {
66
        $this->app->singleton('command.event.generate', function () {
67
            return new EventGenerateCommand;
68
        });
69
    }
70
    /**
71
     * Register the command.
72
     *
73
     * @return void
74
     */
75
    protected function registerEventMakeCommand()
76
    {
77
        $this->app->singleton('command.event.make', function ($app) {
78
            return new EventMakeCommand($app['files']);
79
        });
80
    }
81
82
    /**
83
     * Register the command.
84
     *
85
     * @return void
86
     */
87
    protected function registerListenerMakeCommand()
88
    {
89
        $this->app->singleton('command.listener.make', function ($app) {
90
            return new ListenerMakeCommand($app['files']);
91
        });
92
    }
93
}
94