Completed
Pull Request — master (#5)
by Evgenii
01:09
created

IndicatorServiceProvider   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 69
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 69
c 0
b 0
f 0
wmc 6
lcom 1
cbo 6
ccs 19
cts 19
cp 1
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A register() 0 8 1
A registerIndicators() 0 6 2
A provides() 0 6 1
A registerAoIndicator() 0 6 1
A registerCmoIndicator() 0 6 1
1
<?php
2
3
namespace Laratrade\Indicators;
4
5
use Illuminate\Support\ServiceProvider;
6
use Laratrade\Indicators\Contracts\IndicatorManager as IndicatorManagerContract;
7
8
class IndicatorServiceProvider extends ServiceProvider
9
{
10
    /**
11
     * Indicates if loading of the provider is deferred.
12
     *
13
     * @var bool
14
     */
15
    protected $defer = true;
16
17
    /**
18
     * Register the service provider.
19
     */
20
    public function register()
21
    {
22
        $this->app->bind(IndicatorManagerContract::class, function () {
23 8
            return tap(new IndicatorManager, function ($manager) {
24 8
                $this->registerIndicators($manager);
25 8
            });
26 8
        });
27 8
    }
28
29
    /**
30
     * Register the indicators on the manager.
31
     *
32
     * @param IndicatorManagerContract $manager
33
     */
34 8
    protected function registerIndicators(IndicatorManagerContract $manager)
35
    {
36 8
        foreach (['Ao', 'Cmo'] as $indicator) {
37 8
            $this->{"register{$indicator}Indicator"}($manager);
38
        }
39 8
    }
40
41
    /**
42
     * Register the awesome oscillator indicator.
43
     *
44
     * @param IndicatorManagerContract $manager
45
     */
46
    protected function registerAoIndicator(IndicatorManagerContract $manager)
47
    {
48 8
        $manager->extend('ao', function () {
49 2
            return new AwesomeOscillatorIndicator;
50 8
        });
51 8
    }
52
53
    /**
54
     * Register the change momentum oscillator indicator.
55
     *
56
     * @param IndicatorManagerContract $manager
57
     */
58
    protected function registerCmoIndicator(IndicatorManagerContract $manager)
59
    {
60 8
        $manager->extend('cmo', function () {
61 2
            return new ChangeMomentumOscillatorIndicator;
62 8
        });
63 8
    }
64
65
    /**
66
     * Get the services provided by the provider.
67
     *
68
     * @return array
69
     */
70 2
    public function provides()
71
    {
72
        return [
73 2
            IndicatorManagerContract::class,
74
        ];
75
    }
76
}
77