Spamworldpro Mini Shell
Spamworldpro


Server : Apache
System : Linux server2.thebrownbagmedia.com 4.18.0-553.34.1.el8_10.x86_64 #1 SMP Wed Jan 8 09:40:06 EST 2025 x86_64
User : topnotchcv ( 1029)
PHP Version : 8.1.32
Disable Function : NONE
Directory :  /home/topnotchcv/public_html/vendor/spatie/backtrace/src/Arguments/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/topnotchcv/public_html/vendor/spatie/backtrace/src/Arguments/ReduceArgumentsAction.php
<?php

namespace Spatie\Backtrace\Arguments;

use ReflectionException;
use ReflectionFunction;
use ReflectionMethod;
use ReflectionParameter;
use Spatie\Backtrace\Arguments\ReducedArgument\VariadicReducedArgument;
use Throwable;

class ReduceArgumentsAction
{
    /** @var ArgumentReducers */
    protected $argumentReducers;

    /** @var ReduceArgumentPayloadAction */
    protected $reduceArgumentPayloadAction;

    public function __construct(
        ArgumentReducers $argumentReducers
    ) {
        $this->argumentReducers = $argumentReducers;
        $this->reduceArgumentPayloadAction = new ReduceArgumentPayloadAction($argumentReducers);
    }

    public function execute(
        ?string $class,
        ?string $method,
        ?array $frameArguments
    ): ?array {
        try {
            if ($frameArguments === null) {
                return null;
            }

            $parameters = $this->getParameters($class, $method);

            if ($parameters === null) {
                $arguments = [];

                foreach ($frameArguments as $index => $argument) {
                    $arguments[$index] = ProvidedArgument::fromNonReflectableParameter($index)
                        ->setReducedArgument($this->reduceArgumentPayloadAction->reduce($argument))
                        ->toArray();
                }

                return $arguments;
            }

            $arguments = array_map(
                function ($argument) {
                    return $this->reduceArgumentPayloadAction->reduce($argument);
                },
                $frameArguments,
            );

            $argumentsCount = count($arguments);
            $hasVariadicParameter = false;

            foreach ($parameters as $index => $parameter) {
                if ($index + 1 > $argumentsCount) {
                    $parameter->defaultValueUsed();
                } elseif ($parameter->isVariadic) {
                    $parameter->setReducedArgument(new VariadicReducedArgument(array_slice($arguments, $index)));

                    $hasVariadicParameter = true;
                } else {
                    $parameter->setReducedArgument($arguments[$index]);
                }

                $parameters[$index] = $parameter->toArray();
            }

            if ($this->moreArgumentsProvidedThanParameters($arguments, $parameters, $hasVariadicParameter)) {
                for ($i = count($parameters); $i < count($arguments); $i++) {
                    $parameters[$i] = ProvidedArgument::fromNonReflectableParameter(count($parameters))
                        ->setReducedArgument($arguments[$i])
                        ->toArray();
                }
            }

            return $parameters;
        } catch (Throwable $e) {
            return null;
        }
    }

    /** @return null|Array<\Spatie\Backtrace\Arguments\ProvidedArgument> */
    protected function getParameters(
        ?string $class,
        ?string $method
    ): ?array {
        try {
            $reflection = $class !== null
                ? new ReflectionMethod($class, $method)
                : new ReflectionFunction($method);
        } catch (ReflectionException $e) {
            return null;
        }

        return array_map(
            function (ReflectionParameter $reflectionParameter) {
                return ProvidedArgument::fromReflectionParameter($reflectionParameter);
            },
            $reflection->getParameters(),
        );
    }

    protected function moreArgumentsProvidedThanParameters(
        array $arguments,
        array $parameters,
        bool $hasVariadicParameter
    ): bool {
        return count($arguments) > count($parameters) && ! $hasVariadicParameter;
    }
}

Spamworldpro Mini