Factory::make()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 8
c 1
b 0
f 0
nc 2
nop 2
dl 0
loc 14
ccs 0
cts 10
cp 0
crap 6
rs 10
1
<?php
2
3
namespace Longman\TelegramBot\Entities\MenuButton;
4
5
use Longman\TelegramBot\Entities\Entity;
6
7
class Factory extends \Longman\TelegramBot\Entities\Factory
8
{
9
    public static function make(array $data, string $bot_username): Entity
10
    {
11
        $type = [
12
            'commands' => MenuButtonCommands::class,
13
            'web_app'  => MenuButtonWebApp::class,
14
            'default'  => MenuButtonDefault::class,
15
        ];
16
17
        if (! isset($type[$data['type'] ?? ''])) {
18
            return new MenuButtonNotImplemented($data, $bot_username);
19
        }
20
21
        $class = $type[$data['type']];
22
        return new $class($data, $bot_username);
23
    }
24
}
25