Passed
Pull Request — develop (#1229)
by
unknown
02:46
created

Factory::make()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 21
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 4
Bugs 0 Features 0
Metric Value
cc 3
eloc 13
c 4
b 0
f 0
nc 3
nop 2
dl 0
loc 21
ccs 0
cts 8
cp 0
crap 12
rs 9.8333
1
<?php
2
3
4
namespace Longman\TelegramBot\Entities\ChatMember;
5
6
7
use Longman\TelegramBot\Entities\Entity;
8
use Longman\TelegramBot\Exception\TelegramException;
9
10
class Factory extends \Longman\TelegramBot\Entities\Factory
11
{
12
    public function make(array $data, string $bot_username): Entity
13
    {
14
        if (! isset($data['status'])) {
15
            throw new TelegramException('Missing ChatMember status');
16
        }
17
18
        $type = [
19
            'creator'       => ChatMemberOwner::class,
20
            'administrator' => ChatMemberAdministrator::class,
21
            'member'        => ChatMemberMember::class,
22
            'restricted'    => ChatMemberRestricted::class,
23
            'left'          => ChatMemberLeft::class,
24
            'kicked'        => ChatMemberBanned::class,
25
        ];
26
27
        if (! isset($type[$data['status']])) {
28
            throw new TelegramException('Unexpected ChatMember status');
29
        }
30
31
        $class = $type[$data['status']];
32
        return new $class($data, $bot_username);
33
    }
34
}
35