Find this useful? Enter your email to receive occasional updates for securing PHP code.

Signing you up...

Thank you for signing up!

PHP Decode

<?php /** * This file is part of the reliforp/reli-prof package. * * (c) sji <sji@sj-i..

Decoded Output download

<?php

/**
 * This file is part of the reliforp/reli-prof package.
 *
 * (c) sji <[email protected]>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

declare(strict_types=1);

namespace Reli\Converter\Speedscope;

use Reli\Converter\ParsedCallTrace;
use Reli\Converter\Speedscope\Settings\SpeedscopeConverterSettings;

class SpeedscopeConverter
{
    /** @param iterable<ParsedCallTrace> $call_frames */
    public function collectFrames(
        iterable $call_frames,
        SpeedscopeConverterSettings $settings,
    ): array {
        $mapper = fn(array $value): string | false => \json_encode(
            $value,
            $settings->utf8_error_handling_type->toFlag()
        );
        $trace_map = [];
        $result_frames = [];
        $sampled_stacks = [];
        $counter = 0;
        foreach ($call_frames as $frames) {
            $sampled_stack = [];
            foreach ($frames->call_frames as $call_frame) {
                $frame = [
                    'name' => $call_frame->function_name,
                    'file' => $call_frame->file_name,
                    'line' => $call_frame->lineno,
                ];
                $mapper_key = $mapper($frame);
                if ($mapper_key === false) {
                    throw new SpeedscopeConverterException(
                        'json_encode failed at '
                        . ($call_frame->original_context?->toString() ?? 'unknown location')
                        . ': '
                        . \json_last_error_msg()
                    );
                }
                if (!isset($trace_map[$mapper_key])) {
                    $result_frames[] = $frame;
                    $trace_map[$mapper_key] = array_key_last($result_frames);
                }
                $sampled_stack[] = $trace_map[$mapper_key];
            }
            $sampled_stacks[] = rray_reverse($sampled_stack);
            $counter++;
        }
        return [
            "\$schema" => "https://www.speedscope.app/file-format-schema.json",
            'shared' => [
                'frames' => $result_frames,
            ],
            'profiles' => [[
                'type' => 'sampled',
                'name' => 'php profile',
                'unit' => 'none',
                'startValue' => 0,
                'endValue' => $counter,
                'samples' => $sampled_stacks,
                'weights' => array_fill(0, count($sampled_stacks), 1),
            ]]
        ];
    }
}
 ?>

Did this file decode correctly?

Original Code

<?php

/**
 * This file is part of the reliforp/reli-prof package.
 *
 * (c) sji <[email protected]>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

declare(strict_types=1);

namespace Reli\Converter\Speedscope;

use Reli\Converter\ParsedCallTrace;
use Reli\Converter\Speedscope\Settings\SpeedscopeConverterSettings;

class SpeedscopeConverter
{
    /** @param iterable<ParsedCallTrace> $call_frames */
    public function collectFrames(
        iterable $call_frames,
        SpeedscopeConverterSettings $settings,
    ): array {
        $mapper = fn(array $value): string | false => \json_encode(
            $value,
            $settings->utf8_error_handling_type->toFlag()
        );
        $trace_map = [];
        $result_frames = [];
        $sampled_stacks = [];
        $counter = 0;
        foreach ($call_frames as $frames) {
            $sampled_stack = [];
            foreach ($frames->call_frames as $call_frame) {
                $frame = [
                    'name' => $call_frame->function_name,
                    'file' => $call_frame->file_name,
                    'line' => $call_frame->lineno,
                ];
                $mapper_key = $mapper($frame);
                if ($mapper_key === false) {
                    throw new SpeedscopeConverterException(
                        'json_encode failed at '
                        . ($call_frame->original_context?->toString() ?? 'unknown location')
                        . ': '
                        . \json_last_error_msg()
                    );
                }
                if (!isset($trace_map[$mapper_key])) {
                    $result_frames[] = $frame;
                    $trace_map[$mapper_key] = array_key_last($result_frames);
                }
                $sampled_stack[] = $trace_map[$mapper_key];
            }
            $sampled_stacks[] = \array_reverse($sampled_stack);
            $counter++;
        }
        return [
            "\$schema" => "https://www.speedscope.app/file-format-schema.json",
            'shared' => [
                'frames' => $result_frames,
            ],
            'profiles' => [[
                'type' => 'sampled',
                'name' => 'php profile',
                'unit' => 'none',
                'startValue' => 0,
                'endValue' => $counter,
                'samples' => $sampled_stacks,
                'weights' => array_fill(0, count($sampled_stacks), 1),
            ]]
        ];
    }
}

Function Calls

None

Variables

None

Stats

MD5 398b5364391217ccb7bba76293df60da
Eval Count 0
Decode Time 97 ms