ClientAuthHandler::auth()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 8
nc 3
nop 1
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