ClientAuthHandler   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
dl 0
loc 27
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A suits() 0 3 2
A auth() 0 14 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Zored\Telegram\Madeline\Auth\Handler;
6
7
use danog\MadelineProto\MTProto;
8
use Zored\Telegram\Madeline\Config\Auth\AuthConfigInterface;
9
use Zored\Telegram\Madeline\Config\Auth\ClientAuth;
10
11
/**
12
 * @property ClientAuth $config
13
 */
14
class ClientAuthHandler extends AbstractAuthHandler
15
{
16
    /**
17
     * {@inheritdoc}
18
     */
19
    public function suits(AuthConfigInterface $config): bool
20
    {
21
        return parent::suits($config) || $config instanceof ClientAuth;
22
    }
23
24
    /**
25
     * {@inheritdoc}
26
     */
27
    public function auth(MTProto $proto): void
28
    {
29
        parent::auth($proto);
30
        if ($this->isAuthorized($proto)) {
31
            return;
32
        }
33
34
        $proto->phone_login($this->config->getPhone());
35
        $result = $proto->complete_phone_login($this->config->getCode());
36
        if ('account.password' !== $result['_']) {
37
            return;
38
        }
39
40
        $proto->complete_2fa_login($this->config->getPassword());
41
    }
42
}
43