Completed
Push — master ( b69e83...ad913f )
by Vladimir
02:54
created

AppServiceProvider   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 50
ccs 0
cts 6
cp 0
c 0
b 0
f 0
rs 10
wmc 1
lcom 1
cbo 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
environment() 0 1 ?
basePath() 0 1 ?
resourcesPath() 0 1 ?
A register() 0 12 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace FondBot\Application;
6
7
use Dotenv\Dotenv;
8
use League\Container\ServiceProvider\AbstractServiceProvider;
9
10
abstract class AppServiceProvider extends AbstractServiceProvider
11
{
12
    protected $provides = [
13
        Config::class,
14
        'env',
15
        'base_path',
16
        'resources_path',
17
    ];
18
19
    /**
20
     * Determine environment where application is currently is running on.
21
     *
22
     * @return string
23
     */
24
    abstract public function environment(): string;
25
26
    /**
27
     * Base path of the application.
28
     *
29
     * @return string
30
     */
31
    abstract public function basePath(): string;
32
33
    /**
34
     * Path to the "resources folder".
35
     *
36
     * @return string
37
     */
38
    abstract public function resourcesPath(): string;
39
40
    /**
41
     * Use the register method to register items with the container via the
42
     * protected $this->container property or the `getContainer` method
43
     * from the ContainerAwareTrait.
44
     *
45
     * @return void
46
     */
47
    public function register(): void
48
    {
49
        $this->getContainer()->share(Config::class, function () {
50
            $dotenv = new Dotenv($this->basePath());
51
52
            return new Config($dotenv->load());
53
        });
54
55
        $this->getContainer()->share('env', $this->environment());
56
        $this->getContainer()->share('base_path', $this->basePath());
57
        $this->getContainer()->share('resources_path', $this->resourcesPath());
58
    }
59
}
60