ClientAuth   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 6
dl 0
loc 56
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getPassword() 0 3 1
A getCode() 0 3 1
A promptPassword() 0 7 2
A getPhone() 0 3 1
A __construct() 0 10 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Zored\Telegram\Madeline\Config\Auth;
6
7
use Zored\Telegram\Madeline\Auth\Prompt\PromptInterface;
8
9
class ClientAuth extends AbstractAuthConfig
10
{
11
    /**
12
     * @var string
13
     */
14
    private $phone;
15
16
    /**
17
     * @var string|null
18
     */
19
    private $password;
20
21
    /**
22
     * @var string|null
23
     */
24
    private $code;
25
26
    /**
27
     * @var PromptInterface
28
     */
29
    private $prompt;
30
31
    public function __construct(
32
        string $phone,
33
        string $password = null,
34
        string $code = null,
35
        PromptInterface $prompt = null
36
    ) {
37
        $this->phone = $phone;
38
        $this->password = $password;
39
        $this->code = $code;
40
        $this->prompt = $prompt;
41
    }
42
43
    public function getPhone(): string
44
    {
45
        return $this->phone;
46
    }
47
48
    public function getPassword(): string
49
    {
50
        return $this->password ?? $this->promptPassword('Password');
51
    }
52
53
    public function getCode(): string
54
    {
55
        return $this->code ?? $this->promptPassword('Code');
56
    }
57
58
    private function promptPassword(string $title): string
59
    {
60
        if (!$this->prompt) {
61
            return '';
62
        }
63
64
        return $this->prompt->prompt($title . ': ');
65
    }
66
}
67