Passed
Pull Request — master (#20)
by Hilmi Erdem
13:59 queued 07:56
created

ServiceProvider::viewPath()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
/*
4
 * @copyright 2018 Hilmi Erdem KEREN
5
 * @license MIT
6
 */
7
8
namespace Erdemkeren\Otp;
9
10
use Erdemkeren\Otp\Http\Middleware\Otp;
0 ignored issues
show
Bug introduced by
The type Erdemkeren\Otp\Http\Middleware\Otp was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
11
use Erdemkeren\Otp\Repositories\DatabaseTokenRepository;
12
use Illuminate\Routing\Router;
13
use Illuminate\Support\ServiceProvider as BaseServiceProvider;
14
15
/**
16
 * Class ServiceProvider.
17
 */
18
class ServiceProvider extends BaseServiceProvider
19
{
20
    /**
21
     * Indicates if loading of the provider is deferred.
22
     *
23
     * @var bool
24
     */
25
    protected bool $defer = true;
26
27
    public function boot(): void
28
    {
29
        $this->publishes([$this->configPath() => config_path('otp.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

29
        $this->publishes([$this->configPath() => /** @scrutinizer ignore-call */ config_path('otp.php')]);
Loading history...
30
        $this->publishes([$this->migrationPath() => database_path('migrations')]);
0 ignored issues
show
Bug introduced by
The function database_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

30
        $this->publishes([$this->migrationPath() => /** @scrutinizer ignore-call */ database_path('migrations')]);
Loading history...
31
        $this->publishes([$this->viewPath() => resource_path('views')]);
0 ignored issues
show
Bug introduced by
The function resource_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

31
        $this->publishes([$this->viewPath() => /** @scrutinizer ignore-call */ resource_path('views')]);
Loading history...
32
    }
33
34
    /**
35
     * Register the otp service.
36
     *
37
     * @return void
38
     */
39
    public function register(): void
40
    {
41
        $service = $this->createServiceInstance();
42
        $this->registerDefaultPasswordGenerators($service);
43
44
        $this->app->singleton('otp', function () use ($service) {
45
            return $service;
46
        });
47
48
        /** @var Router $router */
49
        $router = $this->app['router'];
50
        $router->aliasMiddleware('otp', Otp::class);
51
    }
52
53
    /**
54
     * Get the services provided by the provider.
55
     *
56
     * @return array
57
     */
58
    public function provides(): array
59
    {
60
        return [
61
            'otp',
62
        ];
63
    }
64
65
    /**
66
     * Create a new otp service instance.
67
     *
68
     * @return OtpService
69
     */
70
    private function createServiceInstance(): OtpService
71
    {
72
        return new OtpService(
73
            new GeneratorManager(),
74
            new Encryptor(config('app.secret')),
0 ignored issues
show
Bug introduced by
The type Erdemkeren\Otp\Encryptor was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
Bug introduced by
The function config 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

74
            new Encryptor(/** @scrutinizer ignore-call */ config('app.secret')),
Loading history...
75
            new DatabaseTokenRepository()
76
        );
77
    }
78
79
    /**
80
     * Register default password generators to the
81
     * given otp service instance.
82
     *
83
     * @param  OtpService  $service
84
     */
85
    private function registerDefaultPasswordGenerators($service): void
86
    {
87
        $service->addPasswordGenerator('string', Generators\StringGenerator::class);
88
        $service->addPasswordGenerator('numeric', Generators\NumericGenerator::class);
89
        $service->addPasswordGenerator('numeric-no-0', Generators\NumericNo0Generator::class);
90
    }
91
92
    /**
93
     * Get the project config path.
94
     *
95
     * @return string
96
     */
97
    private function configPath(): string
98
    {
99
        return __DIR__.'/../config/otp.php';
100
    }
101
102
    /**
103
     * Get the migration path.
104
     *
105
     * @return string
106
     */
107
    private function migrationPath(): string
108
    {
109
        return __DIR__.'/../database/migrations/';
110
    }
111
112
    /**
113
     * Get the view path.
114
     *
115
     * @return string
116
     */
117
    private function viewPath(): string
118
    {
119
        return __DIR__.'/../views/';
120
    }
121
}
122