HistoryPlugin::handleRequest()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 14
ccs 8
cts 8
cp 1
rs 9.7998
c 0
b 0
f 0
cc 1
nc 1
nop 3
crap 1
1
<?php
2
3
namespace Http\Client\Plugin;
4
5 1
@trigger_error('The '.__NAMESPACE__.'\HistoryPlugin class is deprecated since version 1.1 and will be removed in 2.0. Use Http\Client\Common\Plugin\HistoryPlugin instead.', E_USER_DEPRECATED);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
6
7
use Http\Client\Exception;
8
use Psr\Http\Message\RequestInterface;
9
use Psr\Http\Message\ResponseInterface;
10
11
/**
12
 * Record http call.
13
 *
14
 * @deprecated since since version 1.1, and will be removed in 2.0. Use {@link \Http\Client\Common\Plugin\HistoryPlugin} instead.
15
 */
16
class HistoryPlugin implements Plugin
0 ignored issues
show
Deprecated Code introduced by
The interface Http\Client\Plugin\Plugin has been deprecated with message: since since version 1.1, and will be removed in 2.0. Use {@link \Http\Client\Common\Plugin} instead.

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
17
{
18
    /**
19
     * Journal use to store request / responses / exception.
20
     *
21
     * @var Journal
22
     */
23
    private $journal;
24
25
    /**
26
     * @param Journal $journal
27
     */
28 3
    public function __construct(Journal $journal)
29
    {
30 3
        $this->journal = $journal;
31 3
    }
32
33
    /**
34
     * {@inheritdoc}
35
     */
36 2
    public function handleRequest(RequestInterface $request, callable $next, callable $first)
37
    {
38 2
        $journal = $this->journal;
39
40
        return $next($request)->then(function (ResponseInterface $response) use ($request, $journal) {
41 1
            $journal->addSuccess($request, $response);
42
43 1
            return $response;
44 2
        }, function (Exception $exception) use ($request, $journal) {
45 1
            $journal->addFailure($request, $exception);
46
47 1
            throw $exception;
48 2
        });
49
    }
50
}
51