Passed
Push — master ( 003724...f241d1 )
by Brent
02:47
created

AdapterFactory::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Brendt\Stitcher\Factory;
4
5
use Brendt\Stitcher\Adapter\Adapter;
6
use Brendt\Stitcher\Exception\UnknownAdapterException;
7
use Symfony\Component\DependencyInjection\ContainerInterface;
8
9
class AdapterFactory
10
{
11
    const COLLECTION_ADAPTER = 'collection';
12
    const PAGINATION_ADAPTER = 'pagination';
13
    const ORDER_ADAPTER = 'order';
14
    const FILTER_ADAPTER = 'filter';
15
16
    /**
17
     * @var ContainerInterface
18
     */
19
    private $container;
20
21
    /**
22
     * AdapterFactory constructor.
23
     *
24
     * @param ContainerInterface $container
25
     */
26
    public function __construct(ContainerInterface $container) {
27
        $this->container = $container;
28
    }
29
30
    /**
31
     * @param $type
32
     *
33
     * @return mixed
34
     *
35
     * @throws UnknownAdapterException
36
     */
37
    public function getByType($type) : Adapter {
38
        switch ($type) {
39
            case self::COLLECTION_ADAPTER:
40
                return $this->container->get('adapter.collection');
41
            case self::PAGINATION_ADAPTER:
42
                return $this->container->get('adapter.pagination');
43
            case self::ORDER_ADAPTER:
44
                return $this->container->get('adapter.order');
45
            case self::FILTER_ADAPTER:
46
                return $this->container->get('adapter.filter');
47
            default:
48
                throw new UnknownAdapterException();
49
        }
50
    }
51
52
}
53