EloquentEncryptionServiceProvider   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 6
dl 0
loc 61
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 13 2
A register() 0 38 5
1
<?php
2
3
namespace RichardStyles\EloquentEncryption;
4
5
use Illuminate\Database\Schema\Blueprint;
6
use Illuminate\Database\Schema\ColumnDefinition;
7
use Illuminate\Database\Schema\Grammars\Grammar;
8
use Illuminate\Support\Fluent;
9
use Illuminate\Support\ServiceProvider;
10
use RichardStyles\EloquentEncryption\Console\Commands\GenerateRsaKeys;
11
use RichardStyles\EloquentEncryption\Exceptions\UnknownGrammarClass;
12
13
class EloquentEncryptionServiceProvider extends ServiceProvider
14
{
15
    /**
16
     * Bootstrap the application services.
17
     */
18
    public function boot()
19
    {
20
        if ($this->app->runningInConsole()) {
21
            $this->publishes([
22
                __DIR__ . '/../config/eloquent_encryption.php' => config_path('eloquent_encryption.php'),
23
            ], 'config');
24
25
            // Registering package commands.
26
            $this->commands([
27
                GenerateRsaKeys::class,
28
            ]);
29
        }
30
    }
31
32
    /**
33
     * Register the application services.
34
     */
35
    public function register()
36
    {
37
        Grammar::macro('typeEncrypted', function (Fluent $column) {
0 ignored issues
show
Unused Code introduced by
The parameter $column is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
38
            $className = (new \ReflectionClass($this))->getShortName();
39
40
            if ($className === "MySqlGrammar") {
41
                return 'blob';
42
            }
43
44
            if ($className === "PostgresGrammar") {
45
                return 'bytea';
46
            }
47
48
            if ($className === "SQLiteGrammar") {
49
                return 'blob';
50
            }
51
52
            if ($className === "SqlServerGrammar") {
53
                return 'varbinary(max)';
54
            }
55
56
            throw new UnknownGrammarClass;
57
        });
58
59
60
        Blueprint::macro('encrypted', function ($column): ColumnDefinition {
61
            /** @var Blueprint $this */
62
            return $this->addColumn('encrypted', $column);
0 ignored issues
show
Bug introduced by
The method addColumn() does not seem to exist on object<RichardStyles\Elo...ryptionServiceProvider>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
63
        });
64
65
        // Automatically apply the package configuration
66
        $this->mergeConfigFrom(__DIR__ . '/../config/eloquent_encryption.php', 'eloquentencryption');
67
68
        // Register the main class to use with the facade
69
        $this->app->singleton('eloquentencryption', function () {
70
            return new EloquentEncryption;
71
        });
72
    }
73
}
74