Passed
Push — master ( e37c4e...e3a05d )
by Alexander
12:08
created

RepositoryProvider   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 14
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
eloc 9
c 1
b 0
f 0
dl 0
loc 14
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A register() 0 5 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\Provider;
6
7
use App\Blog\Comment\CommentRepository;
8
use App\Blog\Entity\Comment;
9
use App\Blog\Entity\Post;
10
use App\Blog\Entity\Tag;
11
use App\Blog\Post\PostRepository;
12
use App\Blog\Tag\TagRepository;
13
use App\Entity\User;
14
use App\Repository\UserRepository;
15
use Cycle\ORM\ORMInterface;
16
use Yiisoft\Di\Container;
17
use Yiisoft\Di\Support\ServiceProvider;
18
19
final class RepositoryProvider extends ServiceProvider
20
{
21
    private const REPOSITORIES = [
22
        User::class => UserRepository::class,
23
        Tag::class => TagRepository::class,
24
        Comment::class => CommentRepository::class,
25
        Post::class => PostRepository::class
26
    ];
27
28
    public function register(Container $container): void
29
    {
30
        $orm = $container->get(ORMInterface::class);
31
        foreach (self::REPOSITORIES as $entity => $repository) {
32
            $container->set($repository, $orm->getRepository($entity));
33
        }
34
    }
35
}
36