DatabaseServiceProvider   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Test Coverage

Coverage 0%

Importance

Changes 6
Bugs 0 Features 4
Metric Value
wmc 1
c 6
b 0
f 4
lcom 0
cbo 5
dl 0
loc 51
ccs 0
cts 28
cp 0
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B register() 0 34 1
1
<?php
2
3
namespace Albert221\Blog\ServiceProvider;
4
5
use Albert221\Blog\Entity\Category;
6
use Albert221\Blog\Entity\Post;
7
use Albert221\Blog\Entity\Setting;
8
use Albert221\Blog\Entity\Tag;
9
use Albert221\Blog\Repository\CategoryRepositoryInterface;
10
use Albert221\Blog\Repository\PostRepositoryInterface;
11
use Albert221\Blog\Repository\SettingRepositoryInterface;
12
use Albert221\Blog\Repository\TagRepositoryInterface;
13
use Doctrine\ORM\EntityManager;
14
use Doctrine\ORM\Tools\Setup;
15
use DoctrineExtensions\Query\Mysql\MatchAgainst;
16
use League\Container\ServiceProvider\AbstractServiceProvider;
17
18
class DatabaseServiceProvider extends AbstractServiceProvider
19
{
20
    /**
21
     * {@inheritdoc}
22
     */
23
    protected $provides = [
24
        'entityManager',
25
        PostRepositoryInterface::class,
26
        CategoryRepositoryInterface::class,
27
        TagRepositoryInterface::class,
28
        SettingRepositoryInterface::class
29
    ];
30
31
    /**
32
     * {@inheritdoc}
33
     */
34
    public function register()
35
    {
36
        $this->getContainer()->share('entityManager', function () {
37
            $config = Setup::createAnnotationMetadataConfiguration(
38
                [dirname(__DIR__)],
39
                $this->getContainer()->get('config')['debug']
40
            );
41
            $config->addCustomStringFunction('MATCH', MatchAgainst::class);
42
43
            $connectionConfig = $this->getContainer()->get('config')['database'];
44
45
            return EntityManager::create($connectionConfig, $config);
46
        });
47
48
        $this->getContainer()->share(
49
            PostRepositoryInterface::class,
50
            $this->getContainer()->get('entityManager')->getRepository(Post::class)
51
        );
52
53
        $this->getContainer()->share(
54
            CategoryRepositoryInterface::class,
55
            $this->getContainer()->get('entityManager')->getRepository(Category::class)
56
        );
57
        
58
        $this->getContainer()->share(
59
            TagRepositoryInterface::class,
60
            $this->getContainer()->get('entityManager')->getRepository(Tag::class)
61
        );
62
63
        $this->getContainer()->share(
64
            SettingRepositoryInterface::class,
65
            $this->getContainer()->get('entityManager')->getRepository(Setting::class)
66
        );
67
    }
68
}
69