AbstractAuthHandler::isAuthorized()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

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