Skip to content

Commit

Permalink
Merge pull request #103: add trap()->code() sugar
Browse files Browse the repository at this point in the history
  • Loading branch information
roxblnfk authored May 29, 2024
2 parents 7e646e0 + 4852dfd commit 043e632
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/Client/TrapHandle.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,28 @@ public function context(mixed ...$values): self
return $this;
}

/**
* Code syntax highlighting.
*
* Adds `language` data context to denote the passed data as source code.
* In this case, Buggregator will perform code highlighting.
*
* Note: it equals to `trap()->context(language: $syntax);`
*
* ```php
* trap(
* index: $indexCode,
* controller: $controllerCode,
* )->code('php');
* ```
*
* @param non-empty-string $syntax The name of the programming language
*/
public function code(string $syntax): self
{
return $this->context(language: $syntax);
}

public function __destruct()
{
$this->haveToSend() and $this->sendDump();
Expand Down
7 changes: 7 additions & 0 deletions tests/Unit/Client/TrapTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ public function testContextMultiple(): void
self::assertSame(['foo' => 'new', 'bar' => 'bar-context'], self::$lastData->getContext());
}

public function testCodeHighlight(): void
{
trap('test-value')->code('php');

self::assertSame(['language' => 'php'], self::$lastData->getContext());
}

/**
* Check the first line of dumped stacktrace string contains right file and line.
*/
Expand Down

0 comments on commit 043e632

Please sign in to comment.