Factory::resolveEntityClass()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 3
c 1
b 0
f 0
nc 2
nop 2
dl 0
loc 7
rs 10
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