ServiceProvider   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 51
Duplicated Lines 35.29 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 4
dl 18
loc 51
ccs 0
cts 29
cp 0
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A register() 0 4 1
A boot() 0 10 2
A insertCredentialSetting() 18 22 3

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
/**
3
 * Laravel Cache Adapter for AWS Credential Caching.
4
 *
5
 * @author    Luke Waite <[email protected]>
6
 * @copyright 2017 Luke Waite
7
 * @license   http://www.opensource.org/licenses/mit-license.php MIT
8
 *
9
 * @link      https://github.com/lukewaite/laravel-aws-cache-adapter
10
 */
11
12
namespace LukeWaite\LaravelAwsCacheAdapter;
13
14
use Illuminate\Cache\CacheManager;
15
use Illuminate\Config\Repository;
16
use Illuminate\Support\ServiceProvider as BaseServiceProvider;
17
18
class ServiceProvider extends BaseServiceProvider
19
{
20
    /**
21
     * {@inheritdoc}
22
     */
23
    public function register()
24
    {
25
        //
26
    }
27
28
    /**
29
     * Bootstrap any application services.
30
     *
31
     * @param CacheManager $manager
32
     * @param Repository $config
33
     * @return void
34
     */
35
    public function boot(CacheManager $manager, Repository $config)
36
    {
37
        $this->publishes([
38
            __DIR__ . '/../config/laravel-aws-cache.php' => config_path('laravel-aws-cache.php')
39
        ]);
40
41
        if (config('laravel-aws-cache.enable')) {
42
            $this->insertCredentialSetting($manager, $config);
43
        }
44
    }
45
46
    protected function insertCredentialSetting(CacheManager $manager, Repository $config)
47
    {
48 View Code Duplication
        if (!empty(config('laravel-aws-cache.filesystems'))) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
49
            collect(explode(',', config('laravel-aws-cache.filesystems')))
50
                ->each(function ($filesystem) use ($manager, $config) {
51
                    $config->set([
52
                        'filesystems.disks.' . $filesystem . '.credentials' =>
53
                            new LaravelCacheAdapter($manager, config('laravel-aws-cache.cache'))
54
                    ]);
55
                });
56
        }
57
58 View Code Duplication
        if (!empty(config('laravel-aws-cache.queues'))) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
59
            collect(explode(',', config('laravel-aws-cache.queues')))
60
                ->each(function ($queue) use ($manager, $config) {
61
                    $config->set([
62
                        'queue.connections.' . $queue . '.credentials' =>
63
                            new LaravelCacheAdapter($manager, config('laravel-aws-cache.cache'))
64
                    ]);
65
                });
66
        }
67
    }
68
}
69