TAuthBasic   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 23
ccs 9
cts 9
cp 1
rs 10
c 0
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setCredentials() 0 4 1
A authKey() 0 5 1
A authType() 0 3 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