EncryptedDataServiceProvider   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Test Coverage

Coverage 97.5%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 29
c 2
b 0
f 0
dl 0
loc 53
ccs 39
cts 40
cp 0.975
rs 10
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setupStorageDriver() 0 36 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\Filesystem\FilesystemAdapter;
7
use Illuminate\Support\Arr;
8
use Illuminate\Support\Facades\Storage;
9
use Illuminate\Support\ServiceProvider;
10
use League\Flysystem\Filesystem;
11
use League\Flysystem\Local\LocalFilesystemAdapter;
12
use League\Flysystem\UnixVisibility\PortableVisibilityConverter;
13
use League\Flysystem\Visibility;
14
use Swis\Flysystem\Encrypted\EncryptedFilesystemAdapter;
15
16
class EncryptedDataServiceProvider extends ServiceProvider
17
{
18 14
    public function register(): void
19
    {
20 14
        $this->registerEncrypter();
21 7
    }
22
23 14
    protected function registerEncrypter(): void
24
    {
25 14
        $this->app->alias('encrypter', 'encrypted-data.encrypter');
26 7
    }
27
28 14
    public function boot(): void
29
    {
30 14
        $this->setupStorageDriver();
31 7
    }
32
33 14
    protected function setupStorageDriver(): void
34
    {
35 14
        Storage::extend(
36 14
            'local-encrypted',
37 14
            function (Application $app, array $config) {
38 2
                $visibility = PortableVisibilityConverter::fromArray(
39 2
                    $config['permissions'] ?? [],
40 2
                    $config['directory_visibility'] ?? $config['visibility'] ?? Visibility::PRIVATE
41 1
                );
42
43 2
                $links = ($config['links'] ?? null) === 'skip'
44
                    ? LocalFilesystemAdapter::SKIP_LINKS
45 2
                    : LocalFilesystemAdapter::DISALLOW_LINKS;
46
47 2
                $adapter = new EncryptedFilesystemAdapter(
48 2
                    new LocalFilesystemAdapter(
49 2
                        $config['root'],
50 1
                        $visibility,
51 2
                        $config['lock'] ?? LOCK_EX,
52 1
                        $links
53 1
                    ),
54 2
                    $app->make('encrypted-data.encrypter')
55 1
                );
56
57 2
                $driver = new Filesystem(
58 2
                    $adapter,
59 2
                    Arr::only($config, [
60 2
                        'directory_visibility',
61 1
                        'disable_asserts',
62 1
                        'temporary_url',
63 1
                        'url',
64 1
                        'visibility',
65 1
                    ])
66 1
                );
67
68 2
                return new FilesystemAdapter($driver, $adapter, $config);
69 14
            }
70 7
        );
71 7
    }
72
}
73