Passed
Pull Request — develop (#1492)
by Rabie
07:07
created

PaidMedia   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 20
rs 10
wmc 2

3 Methods

Rating   Name   Duplication   Size   Complexity  
A hp$0 ➔ getFactory() 0 15 1
getFactory() 0 15 ?
A hp$0 ➔ subEntities() 0 1 1
1
<?php
2
3
namespace Longman\TelegramBot\Entities\PaidMedia;
4
5
use Longman\TelegramBot\Entities\Entity;
6
7
/**
8
 * Class PaidMedia
9
 *
10
 * This object describes the paid media.
11
 *
12
 * @link https://core.telegram.org/bots/api#paidmedia
13
 *
14
 * @method string getType() Type of the paid media
15
 */
16
abstract class PaidMedia extends Entity
17
{
18
    /**
19
     * {@inheritdoc}
20
     */
21
    public static function getFactory($data)
22
    {
23
        $type = $data['type'] ?? null;
24
        switch ($type) {
25
            case 'preview':
26
                return new PaidMediaPreview($data);
27
            case 'photo':
28
                return new PaidMediaPhoto($data);
29
            case 'video':
30
                return new PaidMediaVideo($data);
31
            default:
32
                // return new static($data);
33
                // throw new TelegramException('Unsupported paid media type: ' . $type);
34
                // Return a base PaidMedia object or handle as an error
35
                 return new class($data) extends PaidMedia { protected function subEntities(): array { return [];}};
36
        }
37
    }
38
}
39