Factory   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A resolveEntityClass() 0 7 2
1
<?php
2
3
namespace TelegramBot;
4
5
/**
6
 * Factory class
7
 *
8
 * @link    https://github.com/telegram-bot-php/core
9
 * @author  Shahrad Elahi (https://github.com/shahradelahi)
10
 * @license https://github.com/telegram-bot-php/core/blob/master/LICENSE (MIT License)
11
 */
12
abstract class Factory
13
{
14
15
    /**
16
     * This method is used to create a new instance of the entity.
17
     *
18
     * @param string $class
19
     * @param mixed $property
20
     * @return Entity
21
     */
22
    public static function resolveEntityClass(string $class, mixed $property): Entity
23
    {
24
        if (is_subclass_of($class, Factory::class)) {
25
            return $class::make($property);
26
        }
27
28
        return new $class($property);
29
    }
30
31
    /**
32
     * @param array $data
33
     * @return Entity
34
     */
35
    abstract public static function make(array $data): Entity;
36
37
}
38