Authentication::authenticate()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 5
ccs 3
cts 3
cp 1
crap 1
rs 10
1
<?php
2
3
/**
4
 * This file is part of RussianPost SDK package.
5
 *
6
 * © Appwilio (http://appwilio.com), JhaoDa (https://github.com/jhaoda)
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace Appwilio\RussianPostSDK\Dispatching\Http;
15
16
use Psr\Http\Message\RequestInterface;
17
18
final class Authentication
19
{
20
    /** @var string */
21
    private $token;
22
23
    /** @var string */
24
    private $basic;
25
26 36
    public function __construct(string $login, string $password, string $token)
27
    {
28 36
        $this->token = $token;
29
30 36
        $this->basic = \base64_encode("{$login}:{$password}");
31 36
    }
32
33 32
    public function authenticate(RequestInterface $request): RequestInterface
34
    {
35
        return $request
36 32
            ->withHeader('Authorization', "AccessToken {$this->token}")
37 32
            ->withHeader('X-User-Authorization', "Basic {$this->basic}");
38
    }
39
}
40