RepositoryServiceProvider::provides()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 0
cts 4
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 0
crap 2
1
<?php
2
3
namespace Loadsman\LaravelPlugin\Providers;
4
5
6
use Loadsman\LaravelPlugin\Collections\RouteCollection;
7
use Loadsman\LaravelPlugin\Contracts\RequestRepositoryInterface;
8
use Loadsman\LaravelPlugin\Contracts\RouteRepositoryInterface;
9
use Loadsman\LaravelPlugin\Repositories\RouteRepository;
10
use Illuminate\Contracts\Container\Container;
11
use Illuminate\Support\ServiceProvider;
12
13
class RepositoryServiceProvider extends ServiceProvider
14
{
15
16
    /**
17
     * Indicates if loading of the provider is deferred.
18
     *
19
     * @var bool
20
     */
21
    protected $defer = true;
22
23
24
    /**
25
     * Register the service provider.
26
     *
27
     * @return void
28
     */
29
    public function register()
30
    {
31
        $this->app->singleton(RouteRepositoryInterface::class, function (Container $app) {
32
            $repositories = [];
33
            foreach (config('api-tester.route_repositories') as $repository) {
34
                $repositories[] = $app->make($repository);
35
            }
36
37
            $routeCollection = $app->make(RouteCollection::class);
38
39
            return new RouteRepository($routeCollection, $repositories);
40
        });
41
42
        $this->app->singleton(
43
            RequestRepositoryInterface::class,
44
            config('api-tester.request_repository')
45
        );
46
    }
47
48
49
    /**
50
     * Get the services provided by the provider.
51
     *
52
     * @return array
53
     */
54
    public function provides()
55
    {
56
        return [
57
            RouteRepositoryInterface::class,
58
            RequestRepositoryInterface::class,
59
        ];
60
    }
61
}