DatabaseServiceProvider::register()   B
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 42
Code Lines 24

Duplication

Lines 33
Ratio 78.57 %

Importance

Changes 0
Metric Value
cc 1
eloc 24
nc 1
nop 0
dl 33
loc 42
rs 8.8571
c 0
b 0
f 0
1
<?php
2
3
namespace Ps2alerts\Api\ServiceProvider;
4
5
use Aura\Sql\ExtendedPdo;
6
use Aura\SqlQuery\QueryFactory;
7
use League\Container\ServiceProvider\AbstractServiceProvider;
8
9
class DatabaseServiceProvider extends AbstractServiceProvider
10
{
11
    /**
12
     * @var array
13
     */
14
    protected $provides = [
15
        'Database',
16
        'Database\Data',
17
        'Database\Archive',
18
        'Aura\SqlQuery\QueryFactory'
19
    ];
20
21
    /**
22
     * {@inheritdoc}
23
     */
24
    public function register()
25
    {
26 View Code Duplication
        $this->getContainer()->share('Database', function () {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
27
            $config = $this->getContainer()->get('config')['database'];
28
29
            $pdo = new ExtendedPdo(
30
                "mysql:host={$config['host']};port={$config['port']};dbname={$config['schema']}",
31
                $config['user'],
32
                $config['password']
33
            );
34
35
            return $pdo;
36
        });
37
38 View Code Duplication
        $this->getContainer()->share('Database\Data', function () {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
39
            $config = $this->getContainer()->get('config')['database_data'];
40
41
            $pdo = new ExtendedPdo(
42
                "mysql:host={$config['host']};port={$config['port']};dbname={$config['schema']}",
43
                $config['user'],
44
                $config['password']
45
            );
46
47
            return $pdo;
48
        });
49
50 View Code Duplication
        $this->getContainer()->share('Database\Archive', function () {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
51
            $config = $this->getContainer()->get('config')['database_archive'];
52
53
            $pdo = new ExtendedPdo(
54
                "mysql:host={$config['host']};port={$config['port']};dbname={$config['schema']}",
55
                $config['user'],
56
                $config['password']
57
            );
58
59
            return $pdo;
60
        });
61
62
        $this->getContainer()->add('Aura\SqlQuery\QueryFactory', function () {
63
            return new QueryFactory('mysql');
64
        });
65
    }
66
}
67