Completed
Push — master ( 70df6c...4c9ad9 )
by Jasper
11:34
created

EncryptedDataServiceProvider   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Test Coverage

Coverage 95.65%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 20
dl 0
loc 39
ccs 22
cts 23
cp 0.9565
rs 10
c 1
b 0
f 0
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setupStorageDriver() 0 22 2
A register() 0 3 1
A boot() 0 3 1
A registerEncrypter() 0 3 1
1
<?php
2
3
namespace Swis\Laravel\Encrypted;
4
5
use Illuminate\Contracts\Foundation\Application;
6
use Illuminate\Support\Arr;
7
use Illuminate\Support\Facades\Storage;
8
use Illuminate\Support\ServiceProvider;
9
use League\Flysystem\Adapter\Local as LocalAdapter;
10
use League\Flysystem\Filesystem;
11
use Swis\Flysystem\Encrypted\EncryptedAdapter;
12
13
class EncryptedDataServiceProvider extends ServiceProvider
14
{
15
    public function register(): void
16
    {
17
        $this->registerEncrypter();
18
    }
19
20 87
    protected function registerEncrypter(): void
21
    {
22 87
        $this->app->alias('encrypter', 'encrypted-data.encrypter');
23 87
    }
24 87
25
    public function boot(): void
26 87
    {
27
        $this->setupStorageDriver();
28 87
    }
29 87
30 58
    protected function setupStorageDriver(): void
31 3
    {
32
        Storage::extend(
33 3
            'local-encrypted',
34
            function (Application $app, array $config) {
35 3
                $permissions = $config['permissions'] ?? [];
36
37 3
                $links = ($config['links'] ?? null) === 'skip'
38 3
                    ? LocalAdapter::SKIP_LINKS
39 3
                    : LocalAdapter::DISALLOW_LINKS;
40 3
41 3
                return new Filesystem(
42 1
                    new EncryptedAdapter(
43 1
                        new LocalAdapter(
44
                            $config['root'],
45 3
                            $config['lock'] ?? LOCK_EX,
46
                            $links,
47 3
                            $permissions
48
                        ),
49 87
                        $app->make('encrypted-data.encrypter')
50
                    ),
51 87
                    Arr::only($config, ['visibility', 'disable_asserts', 'url'])
52
                );
53 87
            }
54
        );
55 87
    }
56
}
57