TAuthBasic::authKey()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 5
rs 10
c 0
b 0
f 0
ccs 4
cts 4
cp 1
crap 1
1
<?php
2
3
namespace kalanis\RemoteRequest\Protocols\Http\Query;
4
5
6
/**
7
 * Trait TAuthBasic
8
 * @package kalanis\RemoteRequest\Protocols\Http\Query
9
 * Authorization header trait
10
 */
11
trait TAuthBasic
12
{
13
    use TAuth;
14
15
    protected string $username = '';
16
    protected string $password = '';
17
18 1
    public function setCredentials(string $username, string $password = ''): void
19
    {
20 1
        $this->username = $username;
21 1
        $this->password = $password;
22
    }
23
24 1
    protected function authType(): string
25
    {
26 1
        return 'Basic';
27
    }
28
29 1
    protected function authKey(): string
30
    {
31 1
        return base64_encode(sprintf('%s:%s',
32 1
            strtr($this->username, [':' => '']),
33 1
            $this->password
34 1
        ));
35
    }
36
}
37