Test Failed
Push — master ( bdaab5...176ee2 )
by Vladimir
06:36
created

AppServiceProvider::boot()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 0
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace FondBot\Foundation;
6
7
use Dotenv\Dotenv;
8
use Dotenv\Exception\InvalidPathException;
9
use FondBot\Conversation\ConversationManager;
10
use League\Container\ServiceProvider\AbstractServiceProvider;
11
use League\Container\ServiceProvider\BootableServiceProviderInterface;
12
13
abstract class AppServiceProvider extends AbstractServiceProvider implements BootableServiceProviderInterface
14
{
15
    protected $provides = [
16
        'environment',
17
        'base_path',
18
        'resources_path',
19
        'bootstrap_path',
20
        ConversationManager::class,
21
    ];
22
23
    /**
24
     * Determine environment where application is currently is running on.
25
     *
26
     * @return string
27
     */
28
    abstract public function environment(): string;
29
30
    /**
31
     * Base path of the application.
32
     *
33
     * @return string
34
     */
35
    abstract public function basePath(): string;
36
37
    /**
38
     * Path to the "resources folder".
39
     *
40
     * @return string
41
     */
42
    abstract public function resourcesPath(): string;
43
44
    /**
45
     * Method will be invoked on registration of a service provider implementing
46
     * this interface. Provides ability for eager loading of Service Providers.
47
     *
48
     * @return void
49
     */
50
    public function boot(): void
51
    {
52
        try {
53
            (new Dotenv($this->basePath()))->load();
54
        } catch (InvalidPathException $exception) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
55
        }
56
    }
57
58
    /**
59
     * Use the register method to register items with the container via the
60
     * protected $this->container property or the `getContainer` method
61
     * from the ContainerAwareTrait.
62
     *
63
     * @return void
64
     */
65
    public function register(): void
66
    {
67
        $this->container->share('environment', $this->environment());
68
        $this->container->share('base_path', $this->basePath());
69
        $this->container->share('resources_path', $this->resourcesPath());
70
        $this->container->share('bootstrap_path', 'bootstrap');
71
72
        $this->container->share(ConversationManager::class, function () {
73
            return new ConversationManager($this->container->get(Kernel::class));
74
        });
75
    }
76
}
77