OrmBootstrapper   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 10
c 1
b 0
f 0
dl 0
loc 26
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getBindings() 0 3 1
A registerBindings() 0 8 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AbterPhp\Contact\Bootstrappers\Orm;
6
7
use AbterPhp\Admin\Bootstrappers\Orm\OrmBootstrapper as AbterAdminOrmBootstrapper;
8
use AbterPhp\Contact\Domain\Entities\Form;
9
use AbterPhp\Contact\Orm\DataMappers\FormSqlDataMapper;
10
use AbterPhp\Contact\Orm\FormRepo;
11
use Opulence\Ioc\IContainer;
12
use Opulence\Ioc\IocException;
13
use Opulence\Orm\IUnitOfWork;
14
use RuntimeException;
15
16
class OrmBootstrapper extends AbterAdminOrmBootstrapper
17
{
18
    /** @var array */
19
    protected $repoMappers = [
20
        FormRepo::class => [FormSqlDataMapper::class, Form::class],
21
    ];
22
23
    /**
24
     * @inheritdoc
25
     */
26
    public function getBindings(): array
27
    {
28
        return array_keys($this->repoMappers);
29
    }
30
31
    /**
32
     * @inheritdoc
33
     */
34
    public function registerBindings(IContainer $container)
35
    {
36
        try {
37
            $unitOfWork = $container->resolve(IUnitOfWork::class);
38
            $this->bindRepositories($container, $unitOfWork);
39
        } catch (IocException $ex) {
40
            $namespace = explode('\\', __NAMESPACE__)[0];
41
            throw new RuntimeException("Failed to register $namespace bindings", 0, $ex);
42
        }
43
    }
44
}
45