src/Exporter/InlineExporter.php
public function exportCallable($callback): string
    {
        $wrappedCallback = null;

        while ($callback instanceof WrappedInvocable) {
            $wrappedCallback = $callback;
            $callback = $callback->callback();
        }

        $label = '';

        if ($wrappedCallback) {
            if ($wrappedCallback->isAnonymous()) {
                return $this->export($wrappedCallback);
            }

            $label = $wrappedCallback->label();

            if ('' !== $label) {
                $label = '[' . $label . ']';
            }
        }

        if ($callback instanceof Closure) {
            return $this->export($callback) . $label;
        }

        $reflector = $this->invocableInspector->callbackReflector($callback);

        if (!$reflector instanceof ReflectionMethod) {
            return $reflector->getName() . $label;
        }

        $class = $reflector->getDeclaringClass();
        $name = $reflector->getName();

        if ($class->implementsInterface(Mock::class)) {
            if (
                ($parentClass = $class->getParentClass()) &&
                $parentClass->hasMethod($name)
            ) {
                $class = $parentClass;
            } else {
                try {
                    $prototype = $reflector->getPrototype();
                    $class = $prototype->getDeclaringClass();
                } catch (ReflectionException $e) {
                    // ignore
                }
            }
        }

        $atoms = explode('\\', $class->getName());
        $rendered = array_pop($atoms);

        if ($wrappedCallback instanceof WrappedMethod) {
            $name = $wrappedCallback->name();
            $handle = $wrappedCallback->handle();

            if ($handle instanceof InstanceHandle) {
                $label = $handle->label();

                if ('' !== $label) {
                    $rendered .= '[' . $label . ']';
                }
            }
        }

        if ($reflector->isStatic()) {
            $callOperator = '::';
        } else {
            $callOperator = '->';
        }

        return $rendered . $callOperator . $name;
    }
public function exportCallable($callback): string
    {
        $wrappedCallback = null;

        while ($callback instanceof WrappedInvocable) {
            $wrappedCallback = $callback;
            $callback = $callback->callback();
        }

        $label = '';

        if ($wrappedCallback) {
            if ($wrappedCallback->isAnonymous()) {
                return $this->export($wrappedCallback);
            }

            $label = $wrappedCallback->label();

            if ('' !== $label) {
                $label = '[' . $label . ']';
            }
        }

        if ($callback instanceof Closure) {
            return $this->export($callback) . $label;
        }

        $reflector = $this->invocableInspector->callbackReflector($callback);

        if (!$reflector instanceof ReflectionMethod) {
            return $reflector->getName() . $label;
        }

        $class = $reflector->getDeclaringClass();
        $name = $reflector->getName();

        if ($class->implementsInterface(Mock::class)) {
            if (
                ($parentClass = $class->getParentClass()) &&
                $parentClass->hasMethod($name)
            ) {
                $class = $parentClass;
            } else {
                try {
                    $prototype = $reflector->getPrototype();
                    $class = $prototype->getDeclaringClass();
                } catch (ReflectionException $e) {
                    // ignore
                }
            }
        }

        $atoms = explode('\\', $class->getName());
        $rendered = array_pop($atoms);

        if ($wrappedCallback instanceof WrappedMethod) {
            $name = $wrappedCallback->name();
            $handle = $wrappedCallback->handle();

            if ($handle instanceof InstanceHandle) {
                $label = $handle->label();

                if ('' !== $label) {
                    $rendered .= '[' . $label . ']';
                }
            }
        }

        if ($reflector->isStatic()) {
            $callOperator = '::';
        } else {
            $callOperator = '->';
        }

        return $rendered . $callOperator . $name;
    }
public function exportCallable ( $ callback ) : string { $ wrappedCallback = null ; while ( $ callback instanceof WrappedInvocable ) { $ wrappedCallback = $ callback ; $ callback = $ callback -> callback ( ) ; } $ label = '' ; if ( $ wrappedCallback ) { if ( $ wrappedCallback -> isAnonymous ( ) ) { return $ this -> export ( $ wrappedCallback ) ; } $ label = $ wrappedCallback -> label ( ) ; if ( '' !== $ label ) { $ label = '[' . $ label . ']' ; } } if ( $ callback instanceof Closure ) { return $ this -> export ( $ callback ) . $ label ; } $ reflector = $ this -> invocableInspector -> callbackReflector ( $ callback ) ; if ( ! $ reflector instanceof ReflectionMethod ) { return $ reflector -> getName ( ) . $ label ; } $ class = $ reflector -> getDeclaringClass ( ) ; $ name = $ reflector -> getName ( ) ; if ( $ class -> implementsInterface ( Mock :: class ) ) { if ( ( $ parentClass = $ class -> getParentClass ( ) ) && $ parentClass -> hasMethod ( $ name ) ) { $ class = $ parentClass ; } else { try { $ prototype = $ reflector -> getPrototype ( ) ; $ class = $ prototype -> getDeclaringClass ( ) ; } catch ( ReflectionException $ e ) { // ignore } } } $ atoms = explode ( '\\' , $ class -> getName ( ) ) ; $ rendered = array_pop ( $ atoms ) ; if ( $ wrappedCallback instanceof WrappedMethod ) { $ name = $ wrappedCallback -> name ( ) ; $ handle = $ wrappedCallback -> handle ( ) ; if ( $ handle instanceof InstanceHandle ) { $ label = $ handle -> label ( ) ; if ( '' !== $ label ) { $ rendered .= '[' . $ label . ']' ; } } } if ( $ reflector -> isStatic ( ) ) { $ callOperator = '::' ; } else { $ callOperator = '->' ; } return $ rendered . $ callOperator . $ name ; }
Export a string representation of a callable value.

@param callable $callback The callable.

@return string The exported callable.
Export a string representation of a callable value .