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

Factory   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 4
Bugs 0 Features 0
Metric Value
eloc 14
c 4
b 0
f 0
dl 0
loc 23
ccs 0
cts 8
cp 0
rs 10
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A make() 0 21 3
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