Completed
Push — master ( a1a386...b15fa9 )
by arto
04:17
created

BuilderFactory::getRequest()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 12
rs 9.4286
cc 2
eloc 7
nc 2
nop 0
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
    /**
20
     * @return Builder|mixed
21
     */
22
    public function create()
23
    {
24
        $builder = new Builder($this->getRequest(), new Merge());
25
26
        return $builder;
27
    }
28
29
    /**
30
     * @param DispatcherInterface $dispatcher
31
     */
32
    public function overwriteDispatcher(DispatcherInterface $dispatcher)
33
    {
34
        $this->dispatcher = $dispatcher;
35
    }
36
37
    /**
38
     * @return Request
39
     */
40
    protected function getRequest()
41
    {
42
        $dispatcher         = $this->dispatcher;
43
        $factory            = new RequestFactory();
44
        $isValidDispatcher  = ($dispatcher instanceof DispatcherInterface);
45
46
        if ($isValidDispatcher) {
47
            $factory->overwriteDispatcher($dispatcher);
48
        }
49
50
        return $factory->create();
51
    }
52
}
53