ConsoleServiceProvider   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 79
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 10

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 79
rs 10
c 1
b 0
f 0
wmc 4
lcom 1
cbo 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 4 1
A register() 0 8 1
B registerCommands() 0 36 1
A provides() 0 13 1
1
<?php
2
declare(strict_types=1);
3
4
/**
5
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
6
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
7
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
8
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
9
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
10
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
11
 * THE SOFTWARE.
12
 */
13
14
namespace Ytake\LaravelCouchbase;
15
16
use Illuminate\Support\ServiceProvider;
17
use Ytake\LaravelCouchbase\Console\DesignCreatorCommand;
18
use Ytake\LaravelCouchbase\Console\IndexCreatorCommand;
19
use Ytake\LaravelCouchbase\Console\IndexFinderCommand;
20
use Ytake\LaravelCouchbase\Console\IndexRemoverCommand;
21
use Ytake\LaravelCouchbase\Console\PrimaryIndexCreatorCommand;
22
use Ytake\LaravelCouchbase\Console\PrimaryIndexRemoverCommand;
23
use Ytake\LaravelCouchbase\Console\QueueCreatorCommand;
24
use Ytake\LaravelCouchbase\Migrations\CouchbaseMigrationRepository;
25
26
/**
27
 * Class ConsoleServiceProvider.
28
 *
29
 * @codeCoverageIgnore
30
 *
31
 * @author Yuuki Takezawa<[email protected]>
32
 */
33
class ConsoleServiceProvider extends ServiceProvider
34
{
35
    /** @var bool */
36
    protected $defer = true;
37
38
    public function boot()
39
    {
40
        $this->registerCommands();
41
    }
42
43
    /**
44
     * {@inheritdoc}
45
     */
46
    public function register()
47
    {
48
        $this->app->singleton('migration.repository', function ($app) {
49
            $table = $app['config']['database.migrations'];
50
51
            return new CouchbaseMigrationRepository($app['db'], $table);
52
        });
53
    }
54
55
    /**
56
     * register laravel-couchbase commands
57
     */
58
    protected function registerCommands(): void
59
    {
60
        $this->app->singleton('command.couchbase.indexes', function ($app) {
61
            return new IndexFinderCommand($app['Illuminate\Database\DatabaseManager']);
62
        });
63
        $this->app->singleton('command.couchbase.primary.index.create', function ($app) {
64
            return new PrimaryIndexCreatorCommand($app['Illuminate\Database\DatabaseManager']);
65
        });
66
        $this->app->singleton('command.couchbase.primary.index.drop', function ($app) {
67
            return new PrimaryIndexRemoverCommand($app['Illuminate\Database\DatabaseManager']);
68
        });
69
        $this->app->singleton('command.couchbase.index.create', function ($app) {
70
            return new IndexCreatorCommand($app['Illuminate\Database\DatabaseManager']);
71
        });
72
        $this->app->singleton('command.couchbase.index.drop', function ($app) {
73
            return new IndexRemoverCommand($app['Illuminate\Database\DatabaseManager']);
74
        });
75
        $this->app->singleton('command.couchbase.queue.index.create', function ($app) {
76
            return new QueueCreatorCommand($app['Illuminate\Database\DatabaseManager']);
77
        });
78
        $this->app->singleton('command.couchbase.design.document.create', function ($app) {
79
            return new DesignCreatorCommand(
80
                $app['Illuminate\Database\DatabaseManager'],
81
                $app['config']->get('couchbase.design')
82
            );
83
        });
84
        $this->commands([
85
            'command.couchbase.indexes',
86
            'command.couchbase.primary.index.create',
87
            'command.couchbase.primary.index.drop',
88
            'command.couchbase.index.create',
89
            'command.couchbase.index.drop',
90
            'command.couchbase.queue.index.create',
91
            'command.couchbase.design.document.create',
92
        ]);
93
    }
94
95
    /**
96
     * {@inheritdoc}
97
     */
98
    public function provides()
99
    {
100
        return [
101
            'command.couchbase.indexes',
102
            'command.couchbase.primary.index.create',
103
            'command.couchbase.primary.index.drop',
104
            'command.couchbase.index.create',
105
            'command.couchbase.index.drop',
106
            'command.couchbase.queue.index.create',
107
            'command.couchbase.design.document.create',
108
            'migration.repository',
109
        ];
110
    }
111
}
112