Skip to content

Commit

Permalink
rename dumb formatter to compat and add a template for it
Browse files Browse the repository at this point in the history
  • Loading branch information
sj-i committed Aug 1, 2021
1 parent 18c5df4 commit 555d41d
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 9 deletions.
1 change: 1 addition & 0 deletions config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
'output' => [
'template' => [
'default' => 'phpspy'
// 'default' => 'compat'
// 'default' => 'json_lines'
],
],
Expand Down
19 changes: 19 additions & 0 deletions resources/templates/compat.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

/**
* This file is part of the sj-i/php-profiler package.
*
* (c) sji <sji@sj-i.dev>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

use PhpProfiler\Inspector\Output\TraceFormatter\Compat\CompatCallTraceFormatter;
use PhpProfiler\Lib\PhpProcessReader\CallTrace;

/** @var CallTrace $call_trace */

echo CompatCallTraceFormatter::getInstance()->format($call_trace) , PHP_EOL;
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@

declare(strict_types=1);

namespace PhpProfiler\Inspector\Output\TraceFormatter\Dumb;
namespace PhpProfiler\Inspector\Output\TraceFormatter\Compat;

use PhpProfiler\Lib\PhpProcessReader\CallFrame;

final class DumbCallFrameFormatter
final class CompatCallFrameFormatter
{
public function format(CallFrame $call_frame): string
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,32 @@

declare(strict_types=1);

namespace PhpProfiler\Inspector\Output\TraceFormatter\Dumb;
namespace PhpProfiler\Inspector\Output\TraceFormatter\Compat;

use PhpProfiler\Inspector\Output\TraceFormatter\CallTraceFormatter;
use PhpProfiler\Lib\PhpProcessReader\CallTrace;

final class DumbCallTraceFormatter implements CallTraceFormatter
final class CompatCallTraceFormatter implements CallTraceFormatter
{
private DumbCallFrameFormatter $call_frame_formatter;
private CompatCallFrameFormatter $call_frame_formatter;
private static ?self $cache;

public static function getInstance(): self
{
if (!isset(self::$cache)) {
self::$cache = new self(new CompatCallFrameFormatter());
}
return self::$cache;
}

public function __construct(
DumbCallFrameFormatter $call_frame_formatter
CompatCallFrameFormatter $call_frame_formatter
) {
$this->call_frame_formatter = $call_frame_formatter;
}



public function format(CallTrace $call_trace): string
{
$frames = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,19 @@

declare(strict_types=1);

namespace PhpProfiler\Inspector\Output\TraceFormatter\Dumb;
namespace PhpProfiler\Inspector\Output\TraceFormatter\Compat;

use PhpProfiler\Lib\PhpInternals\Types\Zend\Opline;
use PhpProfiler\Lib\PhpProcessReader\CallFrame;
use PhpProfiler\Lib\PhpProcessReader\CallTrace;
use PHPUnit\Framework\TestCase;

class DumbCallTraceFormatterTest extends TestCase
class CompatCallTraceFormatterTest extends TestCase
{
/** @dataProvider dataProvider */
public function testFormat(string $expects, CallTrace $call_trace): void
{
$formatter = new DumbCallTraceFormatter(new DumbCallFrameFormatter());
$formatter = CompatCallTraceFormatter::getInstance();
$this->assertSame($expects, $formatter->format($call_trace));
}

Expand Down

0 comments on commit 555d41d

Please sign in to comment.