AbstractAuthHandler   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
dl 0
loc 36
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A auth() 0 4 2
A isAuthorized() 0 3 1
A suits() 0 6 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
10
abstract class AbstractAuthHandler implements AuthHandlerInterface
11
{
12
    /**
13
     * @var bool
14
     */
15
    private $suitsCalled = false;
16
17
    /**
18
     * @var AuthConfigInterface
19
     */
20
    protected $config;
21
22
    /**
23
     * {@inheritdoc}
24
     */
25
    public function suits(AuthConfigInterface $config): bool
26
    {
27
        $this->suitsCalled = true;
28
        $this->config = $config;
29
30
        return false;
31
    }
32
33
    /**
34
     * {@inheritdoc}
35
     */
36
    public function auth(MTProto $proto): void
37
    {
38
        if (!$this->suitsCalled) {
39
            throw Exception\AuthHandlerException::becauseNoSuitsCall(__CLASS__);
40
        }
41
    }
42
43
    protected function isAuthorized(MTProto $proto): bool
44
    {
45
        return MTProto::LOGGED_IN === $proto->authorized;
46
    }
47
}
48