Passed
Push — master ( 627c19...f3fe5e )
by Armando
03:09
created

Factory::resolveEntityClass()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3.0416

Importance

Changes 3
Bugs 0 Features 0
Metric Value
cc 3
eloc 5
c 3
b 0
f 0
nc 3
nop 3
dl 0
loc 11
ccs 5
cts 6
cp 0.8333
crap 3.0416
rs 10
1
<?php
2
3
namespace Longman\TelegramBot\Entities;
4
5
abstract class Factory
6
{
7
    abstract public static function make(array $data, string $bot_username): Entity;
8
9 18
    public static function resolveEntityClass(string $class, $property, string $bot_username = ''): Entity
10
    {
11 18
        if (is_a($property, $class)) {
12 2
            return $property;
13
        }
14
15 16
        if (is_subclass_of($class, Factory::class)) {
16
            return $class::make($property, $bot_username);
17
        }
18
19 16
        return new $class($property, $bot_username);
20
    }
21
}
22