CorsServiceProvider   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Importance

Changes 6
Bugs 1 Features 0
Metric Value
eloc 11
c 6
b 1
f 0
dl 0
loc 41
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A registerBindings() 0 8 1
A configPath() 0 3 1
A register() 0 10 2
1
<?php namespace Nord\Lumen\Cors;
2
3
use Illuminate\Support\ServiceProvider;
4
use Nord\Lumen\Cors\Contracts\CorsService as CorsServiceContract;
5
6
class CorsServiceProvider extends ServiceProvider
7
{
8
    const CONFIG_KEY = 'cors';
9
10
    /**
11
     * @inheritdoc
12
     */
13
    public function register(): void
14
    {
15
        // In Lumen application configuration files needs to be loaded implicitly
16
        if ($this->app instanceof \Laravel\Lumen\Application) {
17
            $this->app->configure(self::CONFIG_KEY);
18
        } else {
19
            $this->publishes([$this->configPath() => config_path('cors.php')]);
0 ignored issues
show
Bug introduced by
The function config_path was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

19
            $this->publishes([$this->configPath() => /** @scrutinizer ignore-call */ config_path('cors.php')]);
Loading history...
20
        }
21
22
        $this->registerBindings();
23
    }
24
25
26
    /**
27
     * Registers container bindings.
28
     */
29
    protected function registerBindings(): void
30
    {
31
        // TODO: Change to bind the implementation to the interface instead.
32
        $this->app->bind(CorsService::class, function () {
33
            return new CorsService(config(self::CONFIG_KEY));
34
        });
35
36
        $this->app->alias(CorsService::class, CorsServiceContract::class);
37
    }
38
39
    /**
40
     * Default config file path
41
     *
42
     * @return string
43
     */
44
    protected function configPath(): string
45
    {
46
        return __DIR__ . '/../config/cors.php';
47
    }
48
}
49