BuilderFactory   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 0 9 1
A overwriteDispatcher() 0 4 1
A overwriteRequestFactory() 0 4 1
A createRequestFromFactory() 0 18 3
1
<?php
2
/**
3
 * @author stev leibelt <[email protected]>
4
 * @since 2015-12-09
5
 */
6
namespace Net\Bazzline\Component\Curl\Builder;
7
8
use Net\Bazzline\Component\Curl\Dispatcher\DispatcherInterface;
9
use Net\Bazzline\Component\Curl\FactoryInterface;
10
use Net\Bazzline\Component\Curl\Request\Request;
11
use Net\Bazzline\Component\Curl\Request\RequestFactory;
12
use Net\Bazzline\Component\Toolbox\HashMap\Merge;
13
14
class BuilderFactory implements FactoryInterface
15
{
16
    /** @var DispatcherInterface */
17
    private $dispatcher;
18
19
    /** @var RequestFactory */
20
    private $factory;
21
22
    /**
23
     * @return Builder|mixed
24
     */
25
    public function create()
26
    {
27
        $builder = new Builder(
28
            $this->createRequestFromFactory(),
29
            new Merge()
30
        );
31
32
        return $builder;
33
    }
34
35
    /**
36
     * @param DispatcherInterface $dispatcher
37
     */
38
    public function overwriteDispatcher(DispatcherInterface $dispatcher)
39
    {
40
        $this->dispatcher = $dispatcher;
41
    }
42
43
    /**
44
     * @param RequestFactory $factory
45
     */
46
    public function overwriteRequestFactory(RequestFactory $factory)
47
    {
48
        $this->factory = $factory;
49
    }
50
51
    /**
52
     * @return Request
53
     */
54
    protected function createRequestFromFactory()
55
    {
56
        $dispatcher         = $this->dispatcher;
57
        $isInvalidFactory   = (!($this->factory instanceof RequestFactory));
58
        $isValidDispatcher  = ($dispatcher instanceof DispatcherInterface);
59
60
        if ($isInvalidFactory) {
61
            $this->factory  = new RequestFactory();
62
        }
63
64
        if ($isValidDispatcher) {
65
            $this->factory->overwriteDispatcher($dispatcher);
66
        }
67
68
        $factory = $this->factory;
69
70
        return $factory->create();
71
    }
72
}
73