AuthSession   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
c 1
b 0
f 0
dl 0
loc 23
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A handleRequest() 0 7 2
A __construct() 0 3 1
1
<?php
2
3
namespace Transmission\HttpClient\Plugin;
4
5
use Http\Client\Common\Plugin;
6
use Http\Promise\Promise;
7
use Psr\Http\Message\RequestInterface;
8
9
/**
10
 * Add Session ID to the Request.
11
 */
12
class AuthSession implements Plugin
13
{
14
    /** @var string */
15
    private $sessionId;
16
17
    /**
18
     * @param string $sessionId
19
     */
20
    public function __construct($sessionId)
21
    {
22
        $this->sessionId = $sessionId;
23
    }
24
25
    /**
26
     * {@inheritdoc}
27
     */
28
    public function handleRequest(RequestInterface $request, callable $next, callable $first): Promise
29
    {
30
        if (filled($this->sessionId)) {
31
            $request = $request->withHeader('X-Transmission-Session-Id', $this->sessionId);
32
        }
33
34
        return $next($request);
35
    }
36
}
37