Passed
Push — master ( 9e4977...ad78b7 )
by Brent
02:46
created

AdapterFactory   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
dl 0
loc 40
rs 10
c 0
b 0
f 0
wmc 5
lcom 1
cbo 3

1 Method

Rating   Name   Duplication   Size   Complexity  
B getByType() 0 24 5
1
<?php
2
3
namespace brendt\stitcher\factory;
4
5
use brendt\stitcher\adapter\Adapter;
6
use brendt\stitcher\adapter\CollectionAdapter;
7
use brendt\stitcher\adapter\PaginationAdapter;
8
use brendt\stitcher\exception\UnknownAdapterException;
9
10
class AdapterFactory {
11
12
    const COLLECTION_ADAPTER = 'collection';
13
    const PAGINATION_ADAPTER = 'pagination';
14
15
    private $adapters;
16
17
    /**
18
     * @param $type
19
     *
20
     * @return Adapter
21
     *
22
     * @throws UnknownAdapterException
23
     */
24
    public function getByType($type) {
25
        if (isset($this->adapters[$type])) {
26
            return $this->adapters[$type];
27
        }
28
29
        switch ($type) {
30
            case self::COLLECTION_ADAPTER:
31
                $adapter = new CollectionAdapter();
32
33
                break;
34
            case self::PAGINATION_ADAPTER:
35
                $adapter = new PaginationAdapter();
36
37
                break;
38
            default:
39
                throw new UnknownAdapterException();
40
        }
41
42
        if ($adapter) {
43
            $this->adapters[$type] = $adapter;
44
        }
45
46
        return $adapter;
47
    }
48
49
}
50