Passed
Push — master ( 7b7e33...6ff579 )
by Tomasz
04:38
created

Container   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 4
lcom 1
cbo 2
dl 0
loc 50
rs 10
c 1
b 0
f 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
A factory() 0 18 1
A get() 0 8 2
A has() 0 4 1
1
<?php
2
3
namespace Helpers;
4
5
use Helpers\Repository\DomainRepository;
6
use Hexarchium\CoreDomain\Model\Domain\Repository\DomainRepositoryInterface;
7
use Hexarchium\CoreDomain\UseCase\CreateDomain\UseCase;
8
use Interop\Container\ContainerInterface;
9
10
/**
11
 * Copyright
12
 */
13
class Container extends \ArrayObject implements ContainerInterface
14
{
15
    public function factory()
16
    {
17
        $container = new Container();
18
19
        $container->offsetSet(
20
            DomainRepositoryInterface::class,
21
            new DomainRepository()
22
        );
23
24
        $container->offsetSet(
25
            UseCase::class,
26
            new UseCase(
27
                $container->get(DomainRepositoryInterface::class)
28
            )
29
        );
30
31
        return $container;
32
    }
33
34
    /**
35
     * Finds an entry of the container by its identifier and returns it.
36
     *
37
     * @param string $id Identifier of the entry to look for.
38
     * @return mixed No entry was found for this identifier.
39
     * @throws \Exception
40
     */
41
    public function get($id)
42
    {
43
        if (!$this->has($id)) {
44
            throw new \Exception(sprintf("Given service '%s' don't exist", $id));
45
        }
46
47
        return $this->offsetGet($id);
48
    }
49
50
    /**
51
     * Returns true if the container can return an entry for the given identifier.
52
     * Returns false otherwise.
53
     *
54
     * @param string $id Identifier of the entry to look for.
55
     *
56
     * @return boolean
57
     */
58
    public function has($id)
59
    {
60
        return $this->offsetExists($id);
61
    }
62
}