FortrabbitStorageServiceProvider   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 8
lcom 0
cbo 5
dl 0
loc 41
ccs 0
cts 20
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
C boot() 0 23 7
A register() 0 4 1
1
<?php
2
3
namespace Nedmas\FortrabbitStorage\Providers;
4
5
use Aws\S3\S3Client;
6
use Illuminate\Support\Arr;
7
use Illuminate\Support\Facades\Storage;
8
use Illuminate\Support\ServiceProvider;
9
use League\Flysystem\Filesystem;
10
use Nedmas\FortrabbitStorage\Filesystem\FortrabbitAdapter;
11
12
class FortrabbitStorageServiceProvider extends ServiceProvider
13
{
14
    /**
15
     * Perform post-registration booting of services.
16
     *
17
     * @return void
18
     */
19
    public function boot()
20
    {
21
        Storage::extend('fortrabbit', function ($app, $config) {
22
            $s3Config = $config + ['version' => 'latest'];
23
24
            if ($s3Config['key'] && $s3Config['secret']) {
25
                $s3Config['credentials'] = Arr::only($s3Config, ['key', 'secret']);
26
            }
27
28
            $root = isset($s3Config['root']) ? $s3Config['root'] : null;
29
30
            $options = isset($config['options']) ? $config['options'] : [];
31
32
            $storageUrl = isset($s3Config['storage_url']) ? $s3Config['storage_url'] : null;
33
34
            $config = Arr::only($config, ['visibility', 'disable_asserts']);
35
36
            return new Filesystem(
37
                new FortrabbitAdapter(new S3Client($s3Config), $s3Config['bucket'], $root, $options, $storageUrl),
0 ignored issues
show
Bug introduced by
It seems like $root defined by isset($s3Config['root'])...s3Config['root'] : null on line 28 can also be of type array or null; however, Nedmas\FortrabbitStorage...tAdapter::__construct() does only seem to accept string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
Bug introduced by
It seems like $options defined by isset($config['options']...ig['options'] : array() on line 30 can also be of type string; however, Nedmas\FortrabbitStorage...tAdapter::__construct() does only seem to accept array, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
Bug introduced by
It seems like $storageUrl defined by isset($s3Config['storage...g['storage_url'] : null on line 32 can also be of type array or null; however, Nedmas\FortrabbitStorage...tAdapter::__construct() does only seem to accept string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
38
                count($config) > 0 ? $config : null
39
            );
40
        });
41
    }
42
43
    /**
44
     * Register bindings in the container.
45
     *
46
     * @return void
47
     */
48
    public function register()
49
    {
50
        //
51
    }
52
}
53