PsrHttpAdapterDecorator   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 96
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 11
lcom 1
cbo 3
dl 0
loc 96
ccs 29
cts 29
cp 1
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getConfiguration() 0 4 1
A setConfiguration() 0 4 1
A getName() 0 4 1
A sendInternalRequest() 0 4 1
A sendInternalRequests() 0 19 4
A doSendInternalRequest() 0 4 1
A doSendInternalRequests() 0 4 1
1
<?php
2
3
/*
4
 * This file is part of the Ivory Http Adapter package.
5
 *
6
 * (c) Eric GELOEN <[email protected]>
7
 *
8
 * For the full copyright and license information, please read the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Ivory\HttpAdapter;
13
14
use Ivory\HttpAdapter\Message\InternalRequestInterface;
15
16
/**
17
 * @author GeLo <[email protected]>
18
 */
19
class PsrHttpAdapterDecorator implements HttpAdapterInterface
20
{
21
    use HttpAdapterTrait;
22
23
    /**
24
     * @var PsrHttpAdapterInterface
25
     */
26
    private $httpAdapter;
27
28
    /**
29
     * @param PsrHttpAdapterInterface $httpAdapter
30
     */
31 216
    public function __construct(PsrHttpAdapterInterface $httpAdapter)
32
    {
33 216
        $this->httpAdapter = $httpAdapter;
34 216
    }
35
36
    /**
37
     * {@inheritdoc}
38
     */
39 9
    public function getConfiguration()
40
    {
41 9
        return $this->httpAdapter->getConfiguration();
42
    }
43
44
    /**
45
     * {@inheritdoc}
46
     */
47 9
    public function setConfiguration(ConfigurationInterface $configuration)
48
    {
49 9
        $this->httpAdapter->setConfiguration($configuration);
50 9
    }
51
52
    /**
53
     * {@inheritdoc}
54
     */
55 9
    public function getName()
56
    {
57 9
        return $this->httpAdapter->getName();
58
    }
59
60
    /**
61
     * {@inheritdoc}
62
     */
63 99
    protected function sendInternalRequest(InternalRequestInterface $internalRequest)
64
    {
65 99
        return $this->doSendInternalRequest($internalRequest);
66
    }
67
68
    /**
69
     * {@inheritdoc}
70
     */
71 81
    protected function sendInternalRequests(array $internalRequests, $success, $error)
72
    {
73 81
        $exceptions = [];
74
75
        try {
76 81
            $responses = $this->doSendInternalRequests($internalRequests);
77 71
        } catch (MultiHttpAdapterException $e) {
78 27
            $responses = $e->getResponses();
79 27
            $exceptions = $e->getExceptions();
80
        }
81
82 72
        foreach ($responses as $response) {
83 63
            call_user_func($success, $response);
84 56
        }
85
86 72
        foreach ($exceptions as $exception) {
87 27
            call_user_func($error, $exception);
88 56
        }
89 72
    }
90
91
    /**
92
     * @param InternalRequestInterface $internalRequest
93
     *
94
     * @throws HttpAdapterException
95
     *
96
     * @return ResponseInterface
97
     */
98 81
    protected function doSendInternalRequest(InternalRequestInterface $internalRequest)
99
    {
100 81
        return $this->httpAdapter->sendRequest($internalRequest);
101
    }
102
103
    /**
104
     * @param array $internalRequests
105
     *
106
     * @throws MultiHttpAdapterException
107
     *
108
     * @return array
109
     */
110 81
    protected function doSendInternalRequests(array $internalRequests)
111
    {
112 81
        return $this->httpAdapter->sendRequests($internalRequests);
113
    }
114
}
115