# betterdocs/3.4.2/includes/Dependencies/Invoker/Reflection/CallableReflection.php

BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ &amp; Chatbot, version 3.4.2. 57 lines.

- Page: https://pluginprobe.com/plugins/betterdocs/3.4.2/code/includes/Dependencies/Invoker/Reflection/CallableReflection.php
- Raw: https://pluginprobe.com/plugins/betterdocs/3.4.2/raw/includes/Dependencies/Invoker/Reflection/CallableReflection.php
- Modified: 2023-08-14T08:41:14+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/betterdocs/3.4.2/code/includes/Dependencies/Invoker/Reflection/CallableReflection.php#L10-L20`.

```php
<?php declare(strict_types=1);

namespace WPDeveloper\BetterDocs\Dependencies\Invoker\Reflection;

use Closure;
use WPDeveloper\BetterDocs\Dependencies\Invoker\Exception\NotCallableException;
use ReflectionException;
use ReflectionFunction;
use ReflectionFunctionAbstract;
use ReflectionMethod;

/**
 * Create a reflection object from a callable or a callable-like.
 *
 * @internal
 */
class CallableReflection
{
    /**
     * @param callable|array|string $callable Can be a callable or a callable-like.
     * @throws NotCallableException|ReflectionException
     */
    public static function create($callable): ReflectionFunctionAbstract
    {
        // Closure
        if ($callable instanceof Closure) {
            return new ReflectionFunction($callable);
        }

        // Array callable
        if (is_array($callable)) {
            [$class, $method] = $callable;

            if (! method_exists($class, $method)) {
                throw NotCallableException::fromInvalidCallable($callable);
            }

            return new ReflectionMethod($class, $method);
        }

        // Callable object (i.e. implementing __invoke())
        if (is_object($callable) && method_exists($callable, '__invoke')) {
            return new ReflectionMethod($callable, '__invoke');
        }

        // Standard function
        if (is_string($callable) && function_exists($callable)) {
            return new ReflectionFunction($callable);
        }

        throw new NotCallableException(sprintf(
            '%s is not a callable',
            is_string($callable) ? $callable : 'Instance of ' . get_class($callable)
        ));
    }
}

```
