Completed
Push — master ( 47778c...ba169d )
by Dan Michael O.
10:36
created

ServiceProvider   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 74
Duplicated Lines 16.22 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
dl 12
loc 74
rs 10
c 0
b 0
f 0
wmc 5
lcom 0
cbo 2

3 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 6 1
A register() 12 37 3
A provides() 0 4 1

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
namespace Scriptotek\Alma\Laravel;
4
5
use Scriptotek\Alma\Client as AlmaClient;
6
use Scriptotek\Sru\Client as SruClient;
7
8
class ServiceProvider extends \Illuminate\Support\ServiceProvider
9
{
10
    /**
11
     * Indicates if loading of the provider is deferred.
12
     *
13
     * @var bool
14
     */
15
    protected $defer = true;
16
17
    /**
18
     * Bootstrap the application events.
19
     *
20
     * @return void
21
     */
22
    public function boot()
23
    {
24
        $this->publishes([
25
            __DIR__ . '/../../config/alma.php' => config_path('alma.php'),
26
        ]);
27
    }
28
29
    /**
30
     * Register the service provider.
31
     *
32
     * @return void
33
     */
34
    public function register()
35
    {
36
        $this->mergeConfigFrom(
37
            __DIR__ . '/../../config/alma.php',
38
            'alma'
39
        );
40
41
        $this->app->singleton(AlmaClient::class, function ($app) {
42
43
            // Create Alma client
44
            $alma = new AlmaClient(
45
                $app['config']->get('alma.iz.key'),
46
                $app['config']->get('alma.region')
47
            );
48
49
            // Set network zone key, if any
50
            $alma->nz->setKey($app['config']->get('alma.nz.key'));
51
52
            // Optionally, attach SRU client for institution zone
53 View Code Duplication
            if ($app['config']->get('alma.iz.sru')) {
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...
54
                $alma->setSruClient(new SruClient(
55
                    $app['config']->get('alma.iz.sru'),
56
                    ['version' => '1.2', 'schema' => 'marcxml']
57
                ));
58
            }
59
60
            // Optionally, attach SRU client for network zone
61 View Code Duplication
            if ($app['config']->get('alma.nz.sru')) {
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...
62
                $alma->nz->setSruClient(new SruClient(
63
                    $app['config']->get('alma.nz.sru'),
64
                    ['version' => '1.2', 'schema' => 'marcxml']
65
                ));
66
            }
67
68
            return $alma;
69
        });
70
    }
71
72
    /**
73
     * Get the services provided by the provider.
74
     *
75
     * @return array
76
     */
77
    public function provides()
78
    {
79
        return [AlmaClient::class];
80
    }
81
}
82