HelloServiceProvider   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Test Coverage

Coverage 39.29%

Importance

Changes 2
Bugs 0 Features 2
Metric Value
wmc 9
eloc 27
c 2
b 0
f 2
dl 0
loc 62
ccs 11
cts 28
cp 0.3929
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A register() 0 4 1
A provides() 0 7 1
A boot() 0 7 1
A registerResources() 0 15 4
A registerMigrations() 0 7 2
1
<?php
2
3
namespace ByTIC\Hello;
4
5
use ByTIC\Hello\Oauth\Routes\RouteRegistrar;
6
use ByTIC\Hello\Oauth\ServiceProvider\Traits\AuthorizationServerTrait;
7
use ByTIC\Hello\Oauth\ServiceProvider\Traits\RepositoriesTrait;
8
use League\OAuth2\Server\AuthorizationServer;
9
use Nip\Container\ServiceProviders\Providers\AbstractSignatureServiceProvider;
10
use Nip\Container\ServiceProviders\Providers\BootableServiceProviderInterface;
11
12
/**
13
 * Class HelloServiceProvider
14
 * @package ByTIC\Auth
15
 */
16
class HelloServiceProvider extends AbstractSignatureServiceProvider implements BootableServiceProviderInterface
17
{
18 1
    use RepositoriesTrait;
19 1
    use AuthorizationServerTrait;
20
21
    /**
22
     * @inheritdoc
23
     */
24
    public function register()
25
    {
26
        $this->registerRepositories();
27
        $this->registerAuthorizationServer();
28
    }
29
30
    /**
31
     * @inheritdoc
32
     */
33
    public function provides()
34
    {
35
        $return = ['hello.server', AuthorizationServer::class];
36
37
        $return = $this->appendRepositoriesToProvide($return);
38
        $return = $this->appendCryptKeysToProvide($return);
39
        return $return;
40
    }
41
42
    /**
43
     * @inheritDoc
44
     */
45 1
    public function boot()
46
    {
47 1
        $router = $this->getContainer()->get('router');
48 1
        (new RouteRegistrar($router))->all();
49
50 1
        $this->registerResources();
51 1
        $this->registerMigrations();
52
    }
53 1
54
    protected function registerMigrations()
55 1
    {
56 1
        $container= $this->getContainer();
57 1
        if ($container->has('migrations.migrator') === false) {
58
            return;
59
        }
60
        $container->get('migrations.migrator')->path(dirname(__DIR__) . '/migrations/');
61
    }
62
63
    protected function registerResources()
64
    {
65
        $container= $this->getContainer();
66
        if ($container->has('translation.languages') === false) {
67
            return;
68
        }
69
        $languages = $container->get('translation.languages');
70
        $folder = dirname(__DIR__) . '/resources/lang/';
71
72
        $translator = $container->get('translator');
73
74
        foreach ($languages as $language) {
75
            $path = $folder . $language;
76
            if (is_dir($path)) {
77
                $translator->addResource('php', $path, $language);
78
            }
79
        }
80
    }
81
}
82