<?php

namespace Longman\TelegramBot\Entities;

abstract class Factory
{
    abstract public static function make(array $data, string $bot_username): Entity;

    public static function resolveEntityClass(string $class, mixed $property, string $bot_username = ''): Entity
    {
        if (is_a($property, $class)) {
            return $property;
        } elseif (is_subclass_of($class, Factory::class)) {
            return $class::make($property, $bot_username);
        }

        return new $class($property, $bot_username);
    }
}

<?php

namespace Longman\TelegramBot\Entities;

abstract class Factory
{
    abstract public static function make(array $data, string $bot_username): Entity;

    public static function resolveEntityClass(string $class, mixed $property, string $bot_username = ''): Entity
    {
        if (is_a($property, $class)) {
            return $property;
        }
        
        if (is_subclass_of($class, Factory::class)) {
            return $class::make($property, $bot_username);
        }

        return new $class($property, $bot_username);
    }
}

Make use of early returns
Make use of early returns

Co-authored-by: Armando Lüscher <26943035120015382c5c160fee1d053cebeae5a6@noplanman.ch>